MessageHandler.c 992 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static ParsingRatedCur modelnameInfo = {0};
  28. static int gunTotalNumber = 0;
  29. static uint8_t gunType[4] = {0};
  30. //===============================
  31. // Local List Version
  32. //===============================
  33. static int locallistVersion=0;
  34. static char idTagAuthorization[32] = {0};
  35. //===============================
  36. // OCPP sign variable
  37. //===============================
  38. static int server_sign = FALSE;
  39. int server_pending = FALSE;
  40. static int BootNotificationInterval = 0;
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = FALSE;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  54. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  55. //========================================
  56. // OCPP status/previous related variables
  57. //========================================
  58. static int GunStatusInterval = 10;
  59. static uint8_t Connector0PreviousSystemStatus;
  60. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  61. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  62. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  63. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  64. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  65. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  66. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  67. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  68. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  69. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  70. static int TransactionMessageAttemptsValue = 0;
  71. static int TransactionMessageRetryIntervalValue = 0;
  72. static int TempMeterValueInterval = 0;
  73. static struct OCPPAuthLocalElemet
  74. {
  75. int listVersionInt;
  76. char idTagstr[21];
  77. char parentIdTag[21];
  78. char expiryDate[36];
  79. char idTagstatus[16];
  80. }idTagQuery;
  81. //============================================
  82. // OCPP MeterValue request flag
  83. //============================================
  84. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  85. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  86. //============================================
  87. // OCPP HeartBeat Response Not Receive Counts
  88. //============================================
  89. static int HeartBeatWithNOResponse = 0;
  90. //============================================
  91. // OCPP California Pricing Requirements
  92. //============================================
  93. static char dmsVersion[21] = {0};
  94. extern sqlite3 *db;
  95. int TransactionMessageAttemptsGet(void);
  96. int TransactionMessageRetryIntervalGet(void);
  97. int GetOcppConnStatus(void);
  98. void SetOcppConnStatus(uint8_t status);
  99. int setKeyValue(char *key, char *value);
  100. void OCPP_get_TableAuthlocalAllData(void);
  101. void processUnkownKey(void);
  102. struct InterLock
  103. {
  104. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  105. unsigned char isGetDiagnosticGoing:1;
  106. unsigned char isUpdateFirmwareGoing:1;
  107. }interLock;
  108. struct ClientTime
  109. {
  110. struct timespec Heartbeat;
  111. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  112. struct timespec StartTransaction;
  113. struct timespec StopTransaction;
  114. struct timespec MeterValues[CONNECTOR_QUANTITY];
  115. struct timespec RemoteStartWait;
  116. struct timespec TcciQueryDeduct;
  117. struct timespec TcciQueryOccupancyDeduct;
  118. struct timespec CharingProfileRefresh[CONNECTOR_QUANTITY];
  119. }clientTime;
  120. typedef union
  121. {
  122. //Operations Initiated by Central System
  123. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  124. struct
  125. {
  126. //CsMsgValue[0]
  127. unsigned char StatusNotificationReq:1; //bit 0,
  128. unsigned char StatusNotificationConf:1; //bit 1,
  129. unsigned char TriggerMeterValue:1; //bit 2,
  130. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  131. unsigned char isOnCharging:1; //bit 4,
  132. unsigned char :3; //bit5~7
  133. }bits[CONNECTOR_QUANTITY];
  134. }CpinitiateMsg;
  135. CpinitiateMsg cpinitateMsg;
  136. //GetConfiguration Array
  137. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  138. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  139. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  140. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  141. static char *ChargePointErrorCodeStr[] = {
  142. MACROSTR(ConnectorLockFailure),
  143. MACROSTR(EVCommunicationError),
  144. MACROSTR(GroundFailure),
  145. MACROSTR(HighTemperature),
  146. MACROSTR(InternalError),
  147. MACROSTR(LocalListConflict),
  148. MACROSTR(NoError),
  149. MACROSTR(OtherError),
  150. MACROSTR(OverCurrentFailure),
  151. MACROSTR(OverVoltage),
  152. MACROSTR(PowerMeterFailure),
  153. MACROSTR(PowerSwitchFailure),
  154. MACROSTR(ReaderFailure),
  155. MACROSTR(ResetFailure),
  156. MACROSTR(UnderVoltage),
  157. MACROSTR(WeakSignal)
  158. };
  159. static char * ChargePointStatusStr[] = {
  160. MACROSTR(Available),
  161. MACROSTR(Preparing),
  162. MACROSTR(Charging),
  163. MACROSTR(SuspendedEVSE),
  164. MACROSTR(SuspendedEV),
  165. MACROSTR(Finishing),
  166. MACROSTR(Reserved),
  167. MACROSTR(Unavailable),
  168. MACROSTR(Faulted)
  169. };
  170. static char *RegistrationStatusStr[] = {
  171. MACROSTR(Accepted),
  172. MACROSTR(Pending),
  173. MACROSTR(Rejected)
  174. };
  175. static char *AvailabilityTypeStr[] = {
  176. MACROSTR(Inoperative),
  177. MACROSTR(Operative)
  178. };
  179. static char *AvailabilityStatusStr[] = {
  180. MACROSTR(Accepted),
  181. MACROSTR(Rejected),
  182. MACROSTR(Scheduled)
  183. };
  184. static char *ConfigurationStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected),
  187. MACROSTR(RebootRequired),
  188. MACROSTR(NotSupported)
  189. };
  190. static char *ClearCacheStatusStr[] = {
  191. MACROSTR(Accepted),
  192. MACROSTR(Rejected)
  193. };
  194. static char *ChargingProfilePurposeTypeStr[] = {
  195. MACROSTR(ChargePointMaxProfile),
  196. MACROSTR(TxDefaultProfile),
  197. MACROSTR(TxProfile)
  198. };
  199. static char *ChargingProfileStatusStr[] = {
  200. MACROSTR(Accepted),
  201. MACROSTR(Rejected),
  202. MACROSTR(NotSupported)
  203. };
  204. static char *ClearChargingProfileStatusStr[] = {
  205. MACROSTR(Accepted),
  206. MACROSTR(Unknown)
  207. };
  208. static char *GetCompositeScheduleStatusStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Rejected)
  211. };
  212. static char *UpdateTypeStr[] = {
  213. MACROSTR(Differential),
  214. MACROSTR(Full)
  215. };
  216. static char *UpdateStatusStr[] = {
  217. MACROSTR(Accepted),
  218. MACROSTR(Failed),
  219. MACROSTR(NotSupported),
  220. MACROSTR(VersionMismatch)
  221. };
  222. static char *RemoteStartStopStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Rejected)
  225. };
  226. static char *ReservationStatusStr[] = {
  227. MACROSTR(Accepted),
  228. MACROSTR(Faulted),
  229. MACROSTR(Occupied),
  230. MACROSTR(Rejected),
  231. MACROSTR(Unavailable)
  232. };
  233. static char *ResetTypeStr[] = {
  234. MACROSTR(Hard),
  235. MACROSTR(Soft)
  236. };
  237. static char *ResetStatusStr[] = {
  238. MACROSTR(Accepted),
  239. MACROSTR(Rejected)
  240. };
  241. static char * DiagnosticsStatusStr[] = {
  242. MACROSTR(Idle),
  243. MACROSTR(Uploaded),
  244. MACROSTR(UploadFailed),
  245. MACROSTR(Uploading)
  246. };
  247. static char * FirmwareStatusStr[] = {
  248. MACROSTR(Downloaded),
  249. MACROSTR(DownloadFailed),
  250. MACROSTR(Downloading),
  251. MACROSTR(Idle),
  252. MACROSTR(InstallationFailed),
  253. MACROSTR(Installing),
  254. MACROSTR(Installed)
  255. };
  256. static char * MessageTriggerStr[] = {
  257. MACROSTR(BootNotification),
  258. MACROSTR(DiagnosticsStatusNotification),
  259. MACROSTR(FirmwareStatusNotification),
  260. MACROSTR(Heartbeat),
  261. MACROSTR(MeterValues),
  262. MACROSTR(StatusNotification)
  263. };
  264. static char * TriggerMessageStatusStr[] = {
  265. MACROSTR(Accepted),
  266. MACROSTR(Rejected),
  267. MACROSTR(NotImplemented)
  268. };
  269. static char * UnlockStatusStr[] = {
  270. MACROSTR(Unlocked),
  271. MACROSTR(UnlockFailed),
  272. MACROSTR(NotSupported)
  273. };
  274. #if 0
  275. static char * StopTransactionReasonStr[] = {
  276. MACROSTR(EmergencyStop),
  277. MACROSTR(EVDisconnected),
  278. MACROSTR(HardReset),
  279. MACROSTR(Local),
  280. MACROSTR(Other),
  281. MACROSTR(PowerLoss),
  282. MACROSTR(Reboot),
  283. MACROSTR(Remote),
  284. MACROSTR(SoftReset),
  285. MACROSTR(UnlockCommand),
  286. MACROSTR(DeAuthorized)
  287. };
  288. #endif
  289. static char * CancelReservationStatusStr[] = {
  290. MACROSTR(Accepted),
  291. MACROSTR(Rejected)
  292. };
  293. static char * ReadingContextStr[] = {
  294. MACROSTR(Interruption.Begin),
  295. MACROSTR(Interruption.End),
  296. MACROSTR(Other),
  297. MACROSTR(Sample.Clock),
  298. MACROSTR(Sample.Periodic),
  299. MACROSTR(Transaction.Begin),
  300. MACROSTR(Transaction.End),
  301. MACROSTR(Trigger)
  302. };
  303. static char * ValueFormatStr[] = {
  304. MACROSTR(Raw),
  305. MACROSTR(SignedData)
  306. };
  307. static char * MeasurandStr[] = {
  308. MACROSTR(Current.Export),
  309. MACROSTR(Current.Import),
  310. MACROSTR(Current.Offered),
  311. MACROSTR(Energy.Active.Export.Register),
  312. MACROSTR(Energy.Active.Import.Register),
  313. MACROSTR(Energy.Reactive.Export.Register),
  314. MACROSTR(Energy.Reactive.Import.Register),
  315. MACROSTR(Energy.Active.Export.Interval),
  316. MACROSTR(Energy.Active.Import.Interval),
  317. MACROSTR(Energy.Reactive.Export.Interval),
  318. MACROSTR(Energy.Reactive.Import.Interval),
  319. MACROSTR(Frequency),
  320. MACROSTR(Power.Active.Export),
  321. MACROSTR(Power.Active.Import),
  322. MACROSTR(Power.Factor),
  323. MACROSTR(Power.Offered),
  324. MACROSTR(Power.Reactive.ExportMACROSTR),
  325. MACROSTR(Power.Reactive.Import),
  326. MACROSTR(RPM),
  327. MACROSTR(SoC),
  328. MACROSTR(Temperature),
  329. MACROSTR(Voltage)
  330. };
  331. static char * LocationStr[] = {
  332. MACROSTR(Body),
  333. MACROSTR(Cable),
  334. MACROSTR(EV),
  335. MACROSTR(Inlet),
  336. MACROSTR(Outlet)
  337. };
  338. static char * PhaseStr[] = {
  339. MACROSTR(L1),
  340. MACROSTR(L2),
  341. MACROSTR(L3),
  342. MACROSTR(N),
  343. MACROSTR(L1-N),
  344. MACROSTR(L2-N),
  345. MACROSTR(L3-N),
  346. MACROSTR(L1-L2),
  347. MACROSTR(L2-L3),
  348. MACROSTR(L3-L1)
  349. };
  350. static char * UnitOfMeasureStr[] = {
  351. MACROSTR(Wh),
  352. MACROSTR(kWh),
  353. MACROSTR(varh),
  354. MACROSTR(kvarh),
  355. MACROSTR(W),
  356. MACROSTR(kW),
  357. MACROSTR(VA),
  358. MACROSTR(kVA),
  359. MACROSTR(var),
  360. MACROSTR(kvar),
  361. MACROSTR(A),
  362. MACROSTR(V),
  363. MACROSTR(Celsius),
  364. MACROSTR(Fahrenheit),
  365. MACROSTR(K),
  366. MACROSTR(Percent)
  367. };
  368. //=========================================
  369. // Meter buffer process
  370. //=========================================
  371. int meterValueBufferDataQuantity(uint8_t gun_index, ReadingContext dataType)
  372. {
  373. uint32_t result = 0;
  374. char sqlCmd[8192];
  375. char zErrMsg[200];
  376. int rows, cols;
  377. char **resultData;
  378. sprintf(sqlCmd, "select count(idx) as dataQuantity from meterValuesBuffer where gun_index='%d' and ReadingContext='%d' order by ReadingContext, idx", gun_index, (dataType==ReadingContext_Sample_Periodic?0:1));
  379. if( sqlite3_get_table(db, sqlCmd, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  380. {
  381. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  382. }
  383. else
  384. {
  385. if(rows >= 1)
  386. {
  387. result = atoi(resultData[1]);
  388. }
  389. }
  390. return result;
  391. }
  392. int meterValueBufferClear(uint8_t gun_index)
  393. {
  394. int result = PASS;
  395. char sqlCmd[512];
  396. char *errMsg = 0;
  397. sprintf(sqlCmd, "delete from meterValuesBuffer where gun_index=%d", gun_index);
  398. if (sqlite3_exec(db, sqlCmd, 0, 0, &errMsg) != SQLITE_OK)
  399. {
  400. DEBUG_INFO("SQL error: %s\n",errMsg);
  401. result = FAIL;
  402. }
  403. return result;
  404. }
  405. int meterValueBufferInsert(uint8_t gun_index, ReadingContext dataType, uint32_t transactionId, char *meterValue)
  406. {
  407. int result = PASS;
  408. char sqlCmd[8192];
  409. char *errMsg = 0;
  410. sprintf(sqlCmd, "insert into meterValuesBuffer(occurDatetime, gun_index, transactionId, ReadingContext, meterValue) values(CURRENT_TIMESTAMP, '%d', '%d','%d','%s')", gun_index
  411. , transactionId
  412. , (dataType==ReadingContext_Sample_Periodic?0:1)
  413. , meterValue);
  414. if (sqlite3_exec(db, sqlCmd, 0, 0, &errMsg) != SQLITE_OK)
  415. {
  416. result = FAIL;
  417. DEBUG_WARN( "Insert meter value record error message: %s\n", errMsg);
  418. }
  419. return result;
  420. }
  421. int meterValueBufferQuery(uint8_t gun_index, json_object *MeterValues)
  422. {
  423. int result = PASS;
  424. char sqlCmd[8192];
  425. char zErrMsg[200];
  426. int rows, cols;
  427. char **resultData;
  428. sprintf(sqlCmd, "select * from meterValuesBuffer where gun_index='%d' order by ReadingContext, idx", gun_index);
  429. if( sqlite3_get_table(db, sqlCmd, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  430. {
  431. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  432. result = FAIL;
  433. }
  434. else
  435. {
  436. for(uint32_t idxRow=1;idxRow<=rows;idxRow++)
  437. {
  438. json_object *MeterValue = json_tokener_parse(resultData[(idxRow*cols)+5]);
  439. json_object_array_add(MeterValues, MeterValue);
  440. }
  441. }
  442. return result;
  443. }
  444. //=========================================
  445. // Certificate related routine
  446. //=========================================
  447. int certVerify(char *privateKey, char *cert)
  448. {
  449. int result = PASS;
  450. SSL_CTX *ctx = SSL_CTX_new(TLS_method());
  451. // Load certificate file
  452. if(SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM) <= 0)
  453. {
  454. DEBUG_ERROR("Load certificate error!\n");
  455. result = FAIL;
  456. }
  457. // Load private key file
  458. if(SSL_CTX_use_PrivateKey_file(ctx, privateKey, SSL_FILETYPE_PEM) <= 0)
  459. {
  460. DEBUG_ERROR("Load private key error!\n");
  461. result = FAIL;
  462. }
  463. if(!SSL_CTX_check_private_key(ctx))
  464. {
  465. result = FAIL;
  466. }
  467. SSL_CTX_free(ctx);
  468. return result;
  469. }
  470. //=========================================
  471. // TTIA routine
  472. //=========================================
  473. int sendTTIAInfo(uint8_t gun_index)
  474. {
  475. static int sn = 0;
  476. int result = FAIL;
  477. struct hostent *server;
  478. int udp_socket_fd;
  479. struct sockaddr_in dest_addr = {0};
  480. uint8_t tx_buf[80] = {0};
  481. uint8_t logBuf[256]= {0};
  482. uint8_t tx_len, tempIndex, socStart, socEnd;
  483. uint16_t PresentChargedEnergy;
  484. struct tm tmStart, tmEnd;
  485. DEBUG_INFO("sendTTIAInfo...\n");
  486. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  487. {
  488. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  489. {
  490. tempIndex = ((gun_index==2) ? 1: 0);
  491. }
  492. else
  493. {
  494. tempIndex = gun_index;
  495. }
  496. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  497. {
  498. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  499. {
  500. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  501. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  502. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  503. }
  504. }
  505. }
  506. else if(gunType[gun_index] == GUN_TYPE_CCS)
  507. {
  508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  509. {
  510. tempIndex = ((gun_index==2) ? 1: 0);
  511. }
  512. else
  513. {
  514. tempIndex = gun_index;
  515. }
  516. for (int index = 0; index < CCS_QUANTITY; index++)
  517. {
  518. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  519. {
  520. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  521. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  522. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  523. }
  524. }
  525. }
  526. else if(gunType[gun_index] == GUN_TYPE_GBT)
  527. {
  528. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  529. {
  530. tempIndex = ((gun_index==2) ? 1: 0);
  531. }
  532. else
  533. {
  534. tempIndex = gun_index;
  535. }
  536. for (int index = 0; index < GB_QUANTITY; index++)
  537. {
  538. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  539. {
  540. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  541. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  542. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  543. }
  544. }
  545. }
  546. else if(gunType[gun_index] == GUN_TYPE_DO)
  547. {
  548. tempIndex = gun_index;
  549. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  550. {
  551. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  552. {
  553. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  554. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  555. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  556. }
  557. }
  558. }
  559. else
  560. {
  561. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  562. {
  563. tempIndex = 2;
  564. }
  565. else
  566. {
  567. tempIndex = gun_index;
  568. }
  569. for (int index = 0; index < AC_QUANTITY; index++)
  570. {
  571. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  572. {
  573. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  574. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  575. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  576. }
  577. }// END
  578. }
  579. // Message assembly
  580. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  581. tx_buf[4] = 0x02; // Protocol Version
  582. tx_buf[5] = 0xb0; // Message ID
  583. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  584. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  585. tx_buf[8] = 0x00; // CarID low byte
  586. tx_buf[9] = 0x00; // CarID high byte
  587. tx_buf[10] = 0x00; // ID Storage
  588. tx_buf[11] = 0x00; // Driver lowest byte
  589. tx_buf[12] = 0x00; // Driver 2nd byte
  590. tx_buf[13] = 0x00; // Driver 3rd byte
  591. tx_buf[14] = 0x00; // Driver highest byte
  592. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  593. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  594. tx_buf[17] = 0x00; // Reserve
  595. tx_buf[18] = 60 & 0xff; // Payload length low byte
  596. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  597. // EVSE provider
  598. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  599. // EVSE provider
  600. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  601. // EVSE id
  602. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  603. // Connector id
  604. tx_buf[37] = gun_index;
  605. // EVSE station
  606. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  607. // Vehicle SN
  608. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  609. // Mileage
  610. tx_buf[61] = 0x00; // lowest byte
  611. tx_buf[62] = 0x00; // 2nd byte
  612. tx_buf[63] = 0x00; // highest byte
  613. // Start date time 6 bytes
  614. if((sscanf((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  615. {
  616. struct tm *tmTarget;
  617. struct timeb tbTarget;
  618. tmStart.tm_year -= 1900;
  619. tmStart.tm_mon -= 1;
  620. tmStart.tm_gmtoff = 0;
  621. tbTarget.time = mktime(&tmStart);
  622. tbTarget.timezone = 0;
  623. tbTarget.time += (8*3600);
  624. tmTarget = gmtime(&tbTarget.time);
  625. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  626. tx_buf[65] = (tmTarget->tm_mon+1);
  627. tx_buf[66] = tmTarget->tm_mday;
  628. tx_buf[67] = tmTarget->tm_hour;
  629. tx_buf[68] = tmTarget->tm_min;
  630. tx_buf[69] = tmTarget->tm_sec;
  631. }
  632. // Stop date time 6 bytes
  633. if((sscanf((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmEnd.tm_year, &tmEnd.tm_mon, &tmEnd.tm_mday, &tmEnd.tm_hour, &tmEnd.tm_min, &tmEnd.tm_sec) == 6))
  634. {
  635. struct tm *tmTarget;
  636. struct timeb tbTarget;
  637. tmEnd.tm_year -= 1900;
  638. tmEnd.tm_mon -= 1;
  639. tmEnd.tm_gmtoff = 0;
  640. tbTarget.time = mktime(&tmEnd);
  641. tbTarget.timezone = 0;
  642. tbTarget.time += (8*3600);
  643. tmTarget = gmtime(&tbTarget.time);
  644. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  645. tx_buf[71] = (tmTarget->tm_mon+1);
  646. tx_buf[72] = tmTarget->tm_mday;
  647. tx_buf[73] = tmTarget->tm_hour;
  648. tx_buf[74] = tmTarget->tm_min;
  649. tx_buf[75] = tmTarget->tm_sec;
  650. }
  651. // Session energy 2 bytes
  652. tx_buf[76] = PresentChargedEnergy & 0xff;
  653. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  654. // Start SOC 1 byte
  655. tx_buf[78] = socStart;
  656. // Stop SOC 1 byte
  657. tx_buf[79] = socEnd;
  658. // Open socket
  659. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  660. if(udp_socket_fd == -1)
  661. {
  662. DEBUG_ERROR("UDP socket create failed!\n");
  663. }
  664. else
  665. {
  666. // Get server DNS entry
  667. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  668. if (server == NULL)
  669. {
  670. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  671. }
  672. else
  673. {
  674. // Build the server's Internet address
  675. bzero((char *) &dest_addr, sizeof(dest_addr));
  676. dest_addr.sin_family = AF_INET;
  677. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  678. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  679. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  680. {
  681. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  682. {
  683. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  684. }
  685. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  686. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  687. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  688. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  689. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  690. DEBUG_TTIA_INFO("---------- Header ----------\n");
  691. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  692. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  693. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  694. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  695. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  696. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  697. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  698. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  699. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  700. DEBUG_TTIA_INFO("Len: 0x3C\n");
  701. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  702. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  703. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  704. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  705. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  706. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  707. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  708. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  709. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  710. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  711. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  712. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  713. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  714. DEBUG_TTIA_INFO("=========================================\n");
  715. sn++;
  716. result = PASS;
  717. }
  718. else
  719. {
  720. DEBUG_ERROR("UDP sent out fail.\n");
  721. }
  722. }
  723. }
  724. return result;
  725. }
  726. //=========================================
  727. // Save configuration
  728. //=========================================
  729. int runShellCmd(const char*cmd)
  730. {
  731. int result = FAIL;
  732. char buf[256];
  733. FILE *fp;
  734. fp = popen(cmd, "r");
  735. if(fp != NULL)
  736. {
  737. while(fgets(buf, sizeof(buf), fp) != NULL)
  738. {
  739. DEBUG_INFO("%s\n", buf);
  740. }
  741. result = PASS;
  742. }
  743. pclose(fp);
  744. return result;
  745. }
  746. int StoreUsrConfigData(struct SysConfigData *UsrData)
  747. {
  748. int result = PASS;
  749. int fd,wrd;
  750. unsigned int i,Chk;
  751. unsigned char *ptr, *BufTmp;
  752. int MtdBlockSize = 0x300000;
  753. Chk=0;
  754. ptr=(unsigned char *)UsrData;
  755. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  756. {
  757. memset(BufTmp,0,MtdBlockSize);
  758. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  759. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  760. Chk+=*(BufTmp+i);
  761. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  762. // Output configuration to file.
  763. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  764. if (fd < 0)
  765. {
  766. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  767. free(BufTmp);
  768. return 0;
  769. }
  770. wrd=write(fd, BufTmp, MtdBlockSize);
  771. close(fd);
  772. if(wrd<MtdBlockSize)
  773. {
  774. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  775. free(BufTmp);
  776. return 0;
  777. }
  778. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  779. DEBUG_INFO("Erase /dev/mtd10.\n");
  780. runShellCmd("flash_erase /dev/mtd10 0 0");
  781. DEBUG_INFO("Write /dev/mtd10.\n");
  782. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  783. DEBUG_INFO("Erase /dev/mtd11.\n");
  784. runShellCmd("flash_erase /dev/mtd11 0 0");
  785. DEBUG_INFO("Write /dev/mtd11.\n");
  786. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  787. system("rm -f /mnt/EvseConfig.bin");
  788. DEBUG_INFO("EvseConfig write to flash OK\n");
  789. }
  790. else
  791. {
  792. DEBUG_ERROR("alloc BlockSize NG\r\n");
  793. result = FAIL;
  794. }
  795. if(BufTmp!=NULL)
  796. free(BufTmp);
  797. return result;
  798. }
  799. //=========================================
  800. // Sqlite3 related function
  801. //=========================================
  802. static int selectSqlCount = 0;
  803. static int callback(void *data, int argc, char **argv, char **azColName){
  804. int i;
  805. //printf("%s: ", (const char*)data);
  806. selectSqlCount = argc;
  807. for(i = 0; i<argc; i++){
  808. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  809. }
  810. //printf("\n");
  811. return 0;
  812. }
  813. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  814. //int i;
  815. //printf("%s:\n", (const char*)data);
  816. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  817. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  818. return 0;
  819. }
  820. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  821. //printf("%s:\n", (const char*)data);
  822. //idTag
  823. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  824. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  825. //parentIdTag
  826. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  827. //expir_date
  828. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  829. //status
  830. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  831. //version
  832. if(columenCount > 5)
  833. idTagQuery.listVersionInt = atoi(columnValue[5]);
  834. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  835. return 0;
  836. }
  837. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  838. {
  839. // localversion = argv[5] ? atoi(argv[5]) : 0;
  840. // printf("localversion=%d\n", localversion);
  841. return 0;
  842. }
  843. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  844. {
  845. for (int i = 0; i < n_columns; i++)
  846. {
  847. DEBUG_INFO("%s\t", col_values[i]);
  848. }
  849. DEBUG_INFO("\n");
  850. return 0;
  851. }
  852. int OCPP_cleanLocalCache()
  853. {
  854. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  855. char *errMsg = 0;
  856. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  857. if (SQLITE_OK != rc)
  858. {
  859. DEBUG_INFO("SQL error: %s\n",errMsg);
  860. return FALSE;
  861. }
  862. return TRUE;
  863. }
  864. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  865. {
  866. int isSuccess = TRUE;
  867. int ret = 0;
  868. //const char* data = "Callback function called";
  869. char sql[300];
  870. char zErrMsg[200];
  871. memset(sql, 0, 300);
  872. memset(zErrMsg, 0, 200);
  873. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  874. //* Execute SQL statement */
  875. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  876. if( ret != SQLITE_OK )
  877. {
  878. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  879. isSuccess = FALSE;
  880. }
  881. return isSuccess;
  882. }
  883. void OCPP_getIdTagFromLocalCache(char idTag[])
  884. {
  885. int rc = 0;
  886. char sql[100];
  887. char zErrMsg[100];
  888. memset(sql, 0, 100);
  889. memset(zErrMsg, 0, 100);
  890. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  891. memset(&idTagQuery, 0, sizeof(idTagQuery));
  892. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  893. /* Execute SQL statement */
  894. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  895. if( rc != SQLITE_OK )
  896. {
  897. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  898. }
  899. }
  900. void OCPP_getListVerion()
  901. {
  902. int rc = 0;
  903. // const char* data = "Callback function called";
  904. char sql[100];
  905. char zErrMsg[100];
  906. memset(sql, 0, 100);
  907. memset(zErrMsg, 0, 100);
  908. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  909. /* Execute SQL statement */
  910. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  911. if( rc != SQLITE_OK )
  912. {
  913. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  914. }
  915. }
  916. void OCPP_get_TableAuthlocalAllData(void)
  917. {
  918. int rc = 0;
  919. char sql[100];
  920. char zErrMsg[100];
  921. memset(sql, 0, 100);
  922. memset(zErrMsg, 0, 100);
  923. sprintf(sql,"select * from ocpp_auth_local ");
  924. /* Execute SQL statement */
  925. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  926. if( rc != SQLITE_OK )
  927. {
  928. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  929. }
  930. //return ver;
  931. }
  932. int OCPP_cleanLocalList()
  933. {
  934. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  935. char *errMsg = 0;
  936. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  937. if (SQLITE_OK != rc)
  938. {
  939. DEBUG_INFO("%s\n",errMsg);
  940. return FALSE;
  941. }
  942. return TRUE;
  943. }
  944. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  945. {
  946. int isSuccess = FALSE;
  947. int ret = 0;
  948. //const char* data = "Callback function called";
  949. char sql[300];
  950. char zErrMsg[200];
  951. memset(sql, 0, 300);
  952. memset(zErrMsg, 0, 200);
  953. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  954. //* Execute SQL statement */
  955. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  956. if( ret != SQLITE_OK )
  957. {
  958. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  959. return isSuccess;
  960. }
  961. memset(sql, 0, 300);
  962. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  963. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  964. if( ret != SQLITE_OK )
  965. {
  966. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  967. return isSuccess;
  968. }
  969. isSuccess = TRUE;
  970. return isSuccess;
  971. }
  972. void OCPP_getIdTagFromLocalList(char idTag[])
  973. {
  974. int rc = 0;
  975. // const char* data = "Callback function called";
  976. char sql[100];
  977. char zErrMsg[100];
  978. memset(sql, 0, 100);
  979. memset(zErrMsg, 0, 100);
  980. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  981. memset(&idTagQuery, 0, sizeof(idTagQuery));
  982. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  983. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  984. /* Execute SQL statement */
  985. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  986. if( rc != SQLITE_OK )
  987. {
  988. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  989. }
  990. //return ver;
  991. }
  992. void OCPP_deleteIdTagFromLocalList(char idTag[])
  993. {
  994. //int ver = 0;
  995. //int isSuccess = FALSE;
  996. int rc = 0;
  997. char sql[100];
  998. char zErrMsg[100];
  999. memset(sql, 0, 100);
  1000. memset(zErrMsg, 0, 100);
  1001. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  1002. //* Execute SQL statement */
  1003. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  1004. if( rc != SQLITE_OK )
  1005. {
  1006. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1007. }
  1008. }
  1009. int getCurrentYear()
  1010. {
  1011. int result = 0;
  1012. time_t CurrentTime;
  1013. struct tm *tm;
  1014. CurrentTime = time(NULL);
  1015. tm=localtime(&CurrentTime);
  1016. result = (tm->tm_year + 1900);
  1017. return result;
  1018. }
  1019. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  1020. {
  1021. int result = PASS;
  1022. char* errMsg = NULL;
  1023. char sqlStr[WEBSOCKET_BUFFER_SIZE];
  1024. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  1025. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1026. {
  1027. result = FAIL;
  1028. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  1029. }
  1030. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-100) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1031. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1032. {
  1033. result = FAIL;
  1034. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  1035. }
  1036. return result;
  1037. }
  1038. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  1039. {
  1040. int isSuccess = TRUE;
  1041. int tempIndex;
  1042. json_object *EnergyDataTransfer = json_object_new_object();
  1043. json_object *periodEnergys = json_object_new_object();
  1044. char sql[1024];
  1045. char zErrMsg[200];
  1046. memset(sql, 0, ARRAY_SIZE(sql));
  1047. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  1048. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  1049. {
  1050. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1051. {
  1052. tempIndex = ((gun_index==2) ? 1: 0);
  1053. }
  1054. else
  1055. {
  1056. tempIndex = gun_index;
  1057. }
  1058. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1059. {
  1060. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  1061. {
  1062. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1063. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1064. {
  1065. uint8_t period[3];
  1066. sprintf((char*)period, "%d", idxPeriod);
  1067. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1068. }
  1069. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1070. } //end of the same index
  1071. }//end of for CHAdeMO_QUANTITY
  1072. }
  1073. else if(gunType[gun_index] == GUN_TYPE_CCS)
  1074. {
  1075. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1076. {
  1077. tempIndex = ((gun_index==2) ? 1: 0);
  1078. }
  1079. else
  1080. {
  1081. tempIndex = gun_index;
  1082. }
  1083. for (int index = 0; index < CCS_QUANTITY; index++)
  1084. {
  1085. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1086. {
  1087. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1088. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1089. {
  1090. uint8_t period[3];
  1091. sprintf((char*)period, "%d", idxPeriod);
  1092. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1093. }
  1094. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1095. } //end of the same index
  1096. } // end of for CCS_QUANTITY
  1097. }
  1098. else if(gunType[gun_index] == GUN_TYPE_GBT)
  1099. {
  1100. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1101. {
  1102. tempIndex = ((gun_index==2) ? 1: 0);
  1103. }
  1104. else
  1105. {
  1106. tempIndex = gun_index;
  1107. }
  1108. for (int index = 0; index < GB_QUANTITY; index++)
  1109. {
  1110. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1111. {
  1112. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1113. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1114. {
  1115. uint8_t period[3];
  1116. sprintf((char*)period, "%d", idxPeriod);
  1117. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1118. }
  1119. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1120. } //end of the same index
  1121. } // end of for GB_QUANTITY
  1122. }
  1123. else if(gunType[gun_index] == GUN_TYPE_DO)
  1124. {
  1125. tempIndex = gun_index;
  1126. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1127. {
  1128. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1129. {
  1130. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1131. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1132. {
  1133. uint8_t period[3];
  1134. sprintf((char*)period, "%d", idxPeriod);
  1135. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1136. }
  1137. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1138. } //end of the same index
  1139. }
  1140. }
  1141. else
  1142. {
  1143. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1144. {
  1145. tempIndex = 2;
  1146. }
  1147. else
  1148. {
  1149. tempIndex = gun_index;
  1150. }
  1151. for (int index = 0; index < AC_QUANTITY; index++)
  1152. {
  1153. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1154. {
  1155. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1156. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1157. {
  1158. uint8_t period[3];
  1159. sprintf((char*)period, "%d", idxPeriod);
  1160. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1161. }
  1162. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1163. }//end of the same index
  1164. }//end of for AC_QUANTITY
  1165. }
  1166. sprintf(sql, "insert or replace into ocpp_period_energy (transactionId, connectorId, occurDatetime, periodEnergy) VALUES ('%d', '%d', CURRENT_TIMESTAMP, '%s');", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, (gun_index+1), json_object_to_json_string_ext(EnergyDataTransfer, JSON_C_TO_STRING_PLAIN));
  1167. json_object_put(EnergyDataTransfer);
  1168. //* Execute SQL statement */
  1169. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1170. {
  1171. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1172. isSuccess = FALSE;
  1173. }
  1174. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1175. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1176. {
  1177. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1178. isSuccess = FALSE;
  1179. }
  1180. return isSuccess;
  1181. }
  1182. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1183. {
  1184. int isSuccess = TRUE;
  1185. char sql[512];
  1186. char zErrMsg[200];
  1187. int rows, cols;
  1188. char **resultData;
  1189. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1190. /* Execute SQL statement */
  1191. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1192. {
  1193. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1194. isSuccess = FALSE;
  1195. }
  1196. else
  1197. {
  1198. if((rows > 0) && (atoi(resultData[4]) > 0))
  1199. {
  1200. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1201. }
  1202. else
  1203. {
  1204. DEBUG_WARN("There is not match transaction data.\n");
  1205. isSuccess = FALSE;
  1206. }
  1207. }
  1208. return isSuccess;
  1209. }
  1210. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  1211. {
  1212. int result = PASS;
  1213. char* errMsg = NULL;
  1214. char sqlStr[8192];
  1215. sprintf(sqlStr, "insert or replace into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  1216. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1217. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1218. {
  1219. result = FAIL;
  1220. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1221. }
  1222. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1223. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1224. {
  1225. result = FAIL;
  1226. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1227. }
  1228. return result;
  1229. }
  1230. int OCPP_update_deduct_info(int txId, char *creditNo)
  1231. {
  1232. int result = PASS;
  1233. char* errMsg = NULL;
  1234. char sqlStr[8192];
  1235. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1236. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1237. {
  1238. result = FAIL;
  1239. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1240. }
  1241. return result;
  1242. }
  1243. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1244. {
  1245. json_object *dataBuf = json_object_new_object();
  1246. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1247. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1248. json_object_object_add(dataBuf, "txId", json_object_new_int(atoi(columnValue[1])));
  1249. json_object_object_add(dataBuf, "creditNo", json_object_new_string(columnValue[2]));
  1250. json_object_object_add(dataBuf, "deductResult", json_object_new_boolean(atoi(columnValue[3])));
  1251. json_object_object_add(dataBuf, "isDonateInvoice", json_object_new_boolean(atoi(columnValue[4])));
  1252. json_object_object_add(dataBuf, "amount", json_object_new_double(atof(columnValue[5])));
  1253. json_object_object_add(dataBuf, "approvalNo", json_object_new_string(columnValue[9]));
  1254. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1255. json_object_put(dataBuf);
  1256. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1257. return 0;
  1258. }
  1259. void OCPP_query_deduct_info()
  1260. {
  1261. int rc = 0;
  1262. char sql[100];
  1263. char zErrMsg[100];
  1264. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1265. /* Execute SQL statement */
  1266. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1267. if( rc != SQLITE_OK )
  1268. {
  1269. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1270. }
  1271. }
  1272. // Occupancy fee deduct queue process
  1273. int OCPP_insert_occupancyDeduct_info(char *occupancySN, char *creditNo, uint8_t deductResult, double amount, char *approvalNo)
  1274. {
  1275. int result = PASS;
  1276. char* errMsg = NULL;
  1277. char sqlStr[8192];
  1278. sprintf(sqlStr, "insert or replace into report_occupancyDeduct_info(occupancySN, creditNo, deductResult, amount, approvalNo, isUploaded) values('%s', '%s', '%d', '%.2f', '%s', '0');",
  1279. occupancySN, creditNo, deductResult, amount, approvalNo);
  1280. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1281. {
  1282. result = FAIL;
  1283. DEBUG_WARN( "Insert local report_occupancyDeduct_info error message: %s\n", errMsg);
  1284. }
  1285. sprintf(sqlStr, "delete from report_occupancyDeduct_info where (idx < (select idx from report_occupancyDeduct_info order by idx desc limit 1)-5000);");
  1286. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1287. {
  1288. result = FAIL;
  1289. DEBUG_WARN( "delete local report_occupancyDeduct_info error message: %s\n", errMsg);
  1290. }
  1291. return result;
  1292. }
  1293. int OCPP_update_occupancyDeduct_info(char *occupancySN)
  1294. {
  1295. int result = PASS;
  1296. char* errMsg = NULL;
  1297. char sqlStr[8192];
  1298. sprintf(sqlStr, "update report_occupancyDeduct_info set isUploaded='1' where occupancySN='%s';", occupancySN);
  1299. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1300. {
  1301. result = FAIL;
  1302. DEBUG_WARN( "Update local report_occupancyDeduct_info error message: %s\n", errMsg);
  1303. }
  1304. return result;
  1305. }
  1306. int queryOccupancyDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1307. {
  1308. json_object *dataBuf = json_object_new_object();
  1309. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1310. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_OccupancyDeductResult");
  1311. json_object_object_add(dataBuf, "occupancySN", json_object_new_string(columnValue[1]));
  1312. json_object_object_add(dataBuf, "creditNo", json_object_new_string(columnValue[2]));
  1313. json_object_object_add(dataBuf, "deductResult", json_object_new_boolean(atoi(columnValue[3])));
  1314. json_object_object_add(dataBuf, "amount", json_object_new_double(atof(columnValue[4])));
  1315. json_object_object_add(dataBuf, "approvalNo", json_object_new_string(columnValue[5]));
  1316. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1317. json_object_put(dataBuf);
  1318. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1319. return 0;
  1320. }
  1321. void OCPP_query_occupancyDeduct_info()
  1322. {
  1323. int rc = 0;
  1324. char sql[100];
  1325. char zErrMsg[100];
  1326. sprintf(sql,"select * from report_occupancyDeduct_info where isUploaded='0' order by idx limit 1");
  1327. /* Execute SQL statement */
  1328. rc = sqlite3_exec(db, sql, queryOccupancyDeductCallBack, 0, (char **)&zErrMsg);
  1329. if( rc != SQLITE_OK )
  1330. {
  1331. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1332. }
  1333. }
  1334. void reportReaderStatus(int gun_index)
  1335. {
  1336. struct timeval tmnow;
  1337. struct tm *tm;
  1338. char buf[28];//, usec_buf[6];
  1339. gettimeofday(&tmnow, NULL);
  1340. time_t t;
  1341. t = time(NULL);
  1342. /*UTC time and date*/
  1343. tm = gmtime(&t);
  1344. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1345. #if 0 // remove temporally
  1346. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1347. strcat(buf,".");
  1348. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1349. strcat(buf,usec_buf);
  1350. #endif
  1351. json_object *dataBuf = json_object_new_object();
  1352. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1353. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_ReaderStatus");
  1354. json_object_object_add(dataBuf, "ConnectorId", json_object_new_int((gun_index+1)));
  1355. json_object_object_add(dataBuf, "readerStatus", json_object_new_int(ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus));
  1356. json_object_object_add(dataBuf, "timestamp", json_object_new_string(buf));
  1357. json_object_object_add(dataBuf, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  1358. json_object_object_add(dataBuf, "creditNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo));
  1359. json_object_object_add(dataBuf, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  1360. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1361. json_object_put(dataBuf);
  1362. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1363. }
  1364. void occupancyFeeAct(int gun_index)
  1365. {
  1366. struct timeval tmnow;
  1367. struct tm *tm;
  1368. char buf[28];//, usec_buf[6];
  1369. gettimeofday(&tmnow, NULL);
  1370. time_t t;
  1371. t = time(NULL);
  1372. /*UTC time and date*/
  1373. tm = gmtime(&t);
  1374. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1375. #if 0 // remove temporally
  1376. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1377. strcat(buf,".");
  1378. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1379. strcat(buf,usec_buf);
  1380. #endif
  1381. json_object *dataBuf = json_object_new_object();
  1382. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1383. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_OccupancyFeeAct");
  1384. json_object_object_add(dataBuf, "ConnectorId", json_object_new_int((gun_index+1)));
  1385. json_object_object_add(dataBuf, "occupancySN", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].occupancySN));
  1386. json_object_object_add(dataBuf, "action", json_object_new_int(ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].action));
  1387. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1388. json_object_put(dataBuf);
  1389. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1390. }
  1391. //==========================================
  1392. // Check time passed since today
  1393. //==========================================
  1394. long long DiffTimebWithNow(struct timeb ST)
  1395. {
  1396. //return milli-second
  1397. struct timeb ET;
  1398. long long StartTime,StopTime;
  1399. ftime(&ET);
  1400. StartTime=(long long)ST.time;
  1401. StopTime=(long long)ET.time;
  1402. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1403. }
  1404. int getTimePassSinceToday(uint8_t gun_index)
  1405. {
  1406. int result = -1;
  1407. static time_t lastTime[4];
  1408. time_t t;
  1409. struct tm *tmStartToday;
  1410. struct timeb tbStartToday;
  1411. t=time(NULL);
  1412. if(difftime(t, lastTime[gun_index])>0)
  1413. {
  1414. tmStartToday=localtime(&t);
  1415. tmStartToday->tm_hour = 0;
  1416. tmStartToday->tm_min = 0;
  1417. tmStartToday->tm_sec = 0;
  1418. tbStartToday.time = mktime(tmStartToday);
  1419. tbStartToday.millitm = 0;
  1420. result = DiffTimebWithNow(tbStartToday)/1000;
  1421. lastTime[gun_index] = t;
  1422. }
  1423. return result;
  1424. }
  1425. void getNowDatetime(uint8_t *data)
  1426. {
  1427. time_t t = time(NULL);
  1428. struct tm tm = *localtime(&t);
  1429. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  1430. }
  1431. int syncDateTimeRTC(uint8_t *data)
  1432. {
  1433. struct ParsingResult
  1434. {
  1435. int result;
  1436. int scanedElement;
  1437. int year;
  1438. int month;
  1439. int mday;
  1440. int hour;
  1441. int min;
  1442. int sec;
  1443. int tz_hour;
  1444. int tz_min;
  1445. float minSec;
  1446. }result;
  1447. struct tm tmOrg;
  1448. struct tm *tmTarget;
  1449. struct timeb tbTarget;
  1450. char buf[128];
  1451. memset(&result, 0x00, sizeof(struct ParsingResult));
  1452. result.result = PASS;
  1453. if(strstr((char*)data, ".") != NULL)
  1454. {
  1455. // Original data with mini second
  1456. if(strstr((char*)data, "Z") != NULL)
  1457. {
  1458. // Original data with Z
  1459. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1460. &result.year,
  1461. &result.month,
  1462. &result.mday,
  1463. &result.hour,
  1464. &result.min,
  1465. &result.sec,
  1466. &result.minSec);
  1467. }
  1468. else
  1469. {
  1470. // Original data without Z
  1471. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1472. &result.year,
  1473. &result.month,
  1474. &result.mday,
  1475. &result.hour,
  1476. &result.min,
  1477. &result.sec,
  1478. &result.minSec,
  1479. &result.tz_hour,
  1480. &result.tz_min);
  1481. }
  1482. }
  1483. else
  1484. {
  1485. // Original data without mini second
  1486. if(strstr((char*)data, "Z") != NULL)
  1487. {
  1488. // Original data with Z
  1489. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1490. &result.year,
  1491. &result.month,
  1492. &result.mday,
  1493. &result.hour,
  1494. &result.min,
  1495. &result.sec);
  1496. }
  1497. else
  1498. {
  1499. // Original data without Z
  1500. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1501. &result.year,
  1502. &result.month,
  1503. &result.mday,
  1504. &result.hour,
  1505. &result.min,
  1506. &result.sec,
  1507. &result.tz_hour,
  1508. &result.tz_min);
  1509. }
  1510. }
  1511. tmOrg.tm_year = result.year - 1900;
  1512. tmOrg.tm_mon = result.month - 1;
  1513. tmOrg.tm_mday = result.mday;
  1514. tmOrg.tm_hour = result.hour;
  1515. tmOrg.tm_min = result.min;
  1516. tmOrg.tm_sec = result.sec;
  1517. tmOrg.tm_gmtoff = 0;
  1518. tbTarget.time = mktime(&tmOrg);
  1519. tbTarget.timezone = 0;
  1520. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1521. tmTarget = gmtime(&tbTarget.time);
  1522. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  1523. //DEBUG_INFO(" org date time: %s\n", data);
  1524. //DEBUG_INFO("parse date time: %s\n", buf);
  1525. system(buf);
  1526. system("/sbin/hwclock -w --systohc");
  1527. if(result.scanedElement < 6)
  1528. result.result = FAIL;
  1529. return result.result;
  1530. }
  1531. //==========================================
  1532. // Parse certificate content
  1533. //==========================================
  1534. int parseCertInfo(char *certPath, int parseType, char *data)
  1535. {
  1536. int result = FAIL;
  1537. int count = 0;
  1538. int showupLine = 0;
  1539. memset(data, 0, ARRAY_SIZE(data));
  1540. if(access(certPath,F_OK) != -1)
  1541. {
  1542. char temp[512] = {0};
  1543. char capturedData[256] = {0};
  1544. char hashType[10] = "SHA256";
  1545. FILE *fp;
  1546. // Need to get hash type first
  1547. sprintf(temp ,"openssl x509 -noout -text -in %s", certPath);
  1548. fp = popen(temp, "r");
  1549. if(fp)
  1550. {
  1551. while(fgets(temp, sizeof(temp), fp) != NULL)
  1552. {
  1553. if(strstr(temp, "Signature Algorithm:") != NULL)
  1554. {
  1555. result = PASS;
  1556. if(strstr(temp, "sha256") != NULL || strstr(temp, "SHA256") != NULL)
  1557. sprintf((char*)hashType, "SHA256");
  1558. else if(strstr(temp, "sha384") != NULL || strstr(temp, "SHA384") != NULL)
  1559. sprintf((char*)hashType, "SHA384");
  1560. else if(strstr(temp, "sha512") != NULL || strstr(temp, "SHA512") != NULL)
  1561. sprintf((char*)hashType, "SHA512");
  1562. else
  1563. {
  1564. DEBUG_INFO("Error: hashAlgorithm is illegal or missing.\n");
  1565. result = FAIL;
  1566. }
  1567. break;
  1568. }
  1569. }
  1570. }
  1571. switch(parseType)
  1572. {
  1573. case CERT_PARSE_HashAlgorithm:
  1574. sprintf((char*)data, hashType);
  1575. DEBUG_INFO("hashAlgorithm: %s\n", hashType);
  1576. break;
  1577. case CERT_PARSE_SerialNumber:
  1578. sprintf(temp ,"openssl x509 -noout -serial -in %s", certPath);
  1579. fp = popen(temp, "r");
  1580. if(fp)
  1581. {
  1582. while(fgets(temp, sizeof(temp), fp) != NULL)
  1583. {
  1584. if(strstr(temp, "serial=") != NULL)
  1585. {
  1586. sscanf(temp, "%*[^=]=%s", capturedData);
  1587. result = PASS;
  1588. break;
  1589. }
  1590. }
  1591. DEBUG_INFO("serialNumber: %s\n", capturedData);
  1592. sprintf((char*)data, capturedData);
  1593. }
  1594. break;
  1595. case CERT_PARSE_IssuerNameHash:
  1596. sprintf(temp ,"openssl asn1parse -i < %s", certPath);
  1597. fp = popen(temp, "r");
  1598. if(fp)
  1599. {
  1600. while(fgets(temp, sizeof(temp), fp) != NULL)
  1601. {
  1602. if(strstr(temp, "SEQUENCE") != NULL)
  1603. {
  1604. count++;
  1605. if(count==4)
  1606. {
  1607. sscanf(temp, "%[^:]", capturedData);
  1608. showupLine = atoi(capturedData);
  1609. break;
  1610. }
  1611. }
  1612. }
  1613. }
  1614. if(showupLine > 0)
  1615. {
  1616. sprintf(temp ,"openssl asn1parse -i < %s -strparse %d -out /Storage/OCPP/IssuerNameHash", certPath, showupLine);
  1617. system(temp);
  1618. }
  1619. else
  1620. {
  1621. break;
  1622. }
  1623. if(access("/Storage/OCPP/IssuerNameHash",F_OK) != -1)
  1624. {
  1625. sprintf(temp ,"openssl %s < /Storage/OCPP/IssuerNameHash", (char*)hashType);
  1626. fp = popen(temp, "r");
  1627. if(fp)
  1628. {
  1629. while(fgets(temp, sizeof(temp), fp) != NULL)
  1630. {
  1631. if(strstr(temp, "(stdin)=") != NULL)
  1632. {
  1633. sscanf(temp, "%*[^=]=%s", capturedData);
  1634. result = PASS;
  1635. break;
  1636. }
  1637. }
  1638. stringtrimspace(capturedData);
  1639. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1640. sprintf((char*)data, capturedData);
  1641. }
  1642. }
  1643. break;
  1644. case CERT_PARSE_IssuerKeyHash:
  1645. sprintf(temp ,"openssl asn1parse -i < %s", certPath);
  1646. fp = popen(temp, "r");
  1647. if(fp)
  1648. {
  1649. while(fgets(temp, sizeof(temp), fp) != NULL)
  1650. {
  1651. if(strstr(temp, "BIT STRING") != NULL)
  1652. {
  1653. sscanf(temp, "%[^:]", capturedData);
  1654. showupLine = atoi(capturedData);
  1655. break;
  1656. }
  1657. }
  1658. }
  1659. if(showupLine > 0)
  1660. {
  1661. sprintf(temp ,"openssl asn1parse -i < %s -strparse %d -out /Storage/OCPP/IssuerKeyHash", certPath, showupLine);
  1662. system(temp);
  1663. }
  1664. else
  1665. {
  1666. break;
  1667. }
  1668. if(access("/Storage/OCPP/IssuerKeyHash",F_OK) != -1)
  1669. {
  1670. sprintf(temp ,"openssl %s < /Storage/OCPP/IssuerKeyHash", (char*)hashType);
  1671. fp = popen(temp, "r");
  1672. if(fp)
  1673. {
  1674. while(fgets(temp, sizeof(temp), fp) != NULL)
  1675. {
  1676. if(strstr(temp, "(stdin)=") != NULL)
  1677. {
  1678. sscanf(temp, "%*[^=]=%s", capturedData);
  1679. result = PASS;
  1680. break;
  1681. }
  1682. }
  1683. stringtrimspace(capturedData);
  1684. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1685. sprintf((char*)data, capturedData);
  1686. }
  1687. }
  1688. break;
  1689. case CERT_PARSE_OcspUrl:
  1690. //sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", certPath);
  1691. sprintf(temp ,"openssl crl2pkcs7 -nocrl -certfile %s | openssl pkcs7 -print_certs -text -noout", certPath);
  1692. fp = popen(temp, "r");
  1693. if(fp)
  1694. {
  1695. while(fgets(temp, sizeof(temp), fp) != NULL)
  1696. {
  1697. if(strstr(temp, "OCSP - URI:") != NULL)
  1698. {
  1699. //strcpy((char*)data, temp);
  1700. sscanf(temp, "%*[^:]:%s", capturedData);
  1701. sprintf((char*)data, capturedData);
  1702. DEBUG_INFO("OCSP_URI: %s\n", data);
  1703. result = PASS;
  1704. break;
  1705. }
  1706. }
  1707. }
  1708. break;
  1709. default:
  1710. DEBUG_INFO("Parse type is invalid.\n");
  1711. break;
  1712. }
  1713. pclose(fp);
  1714. }
  1715. return result;
  1716. }
  1717. //==========================================
  1718. // GetCompositeSchedule logic related function
  1719. //==========================================
  1720. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1721. {
  1722. //return milli-second
  1723. unsigned int StartTime,StopTime;
  1724. StartTime=(unsigned int)ST.time;
  1725. StopTime=(unsigned int)ET.time;
  1726. return (StopTime-StartTime);
  1727. }
  1728. int DiffTimebWithNowSec(struct timeb ST)
  1729. {
  1730. //return milli-second
  1731. struct timeb ET;
  1732. unsigned int StartTime,StopTime;
  1733. ftime(&ET);
  1734. StartTime=(unsigned int)ST.time;
  1735. StopTime=(unsigned int)ET.time;
  1736. return (StopTime-StartTime);
  1737. }
  1738. int getStartStop(uint8_t *start, uint8_t *stop)
  1739. {
  1740. struct ParsingResult
  1741. {
  1742. int result;
  1743. int scanedElement;
  1744. int year;
  1745. int month;
  1746. int mday;
  1747. int hour;
  1748. int min;
  1749. int sec;
  1750. int tz_hour;
  1751. int tz_min;
  1752. float minSec;
  1753. };
  1754. struct ParsingResult parseStart;
  1755. struct ParsingResult parseStop;
  1756. int result = -1;
  1757. struct tm tmStart;
  1758. struct timeb tbStart;
  1759. struct tm tmStop;
  1760. struct timeb tbStop;
  1761. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1762. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1763. // Scan start & stop date time
  1764. if(strstr((char*)start, ".") != NULL)
  1765. {
  1766. // Original data with mini second
  1767. if(strstr((char*)start, "Z") != NULL)
  1768. {
  1769. // Original data with Z
  1770. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1771. &parseStart.year,
  1772. &parseStart.month,
  1773. &parseStart.mday,
  1774. &parseStart.hour,
  1775. &parseStart.min,
  1776. &parseStart.sec,
  1777. &parseStart.minSec);
  1778. }
  1779. else
  1780. {
  1781. // Original data without Z
  1782. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1783. &parseStart.year,
  1784. &parseStart.month,
  1785. &parseStart.mday,
  1786. &parseStart.hour,
  1787. &parseStart.min,
  1788. &parseStart.sec,
  1789. &parseStart.minSec,
  1790. &parseStart.tz_hour,
  1791. &parseStart.tz_min);
  1792. }
  1793. }
  1794. else
  1795. {
  1796. // Original data without mini second
  1797. if(strstr((char*)start, "Z") != NULL)
  1798. {
  1799. // Original data with Z
  1800. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1801. &parseStart.year,
  1802. &parseStart.month,
  1803. &parseStart.mday,
  1804. &parseStart.hour,
  1805. &parseStart.min,
  1806. &parseStart.sec);
  1807. }
  1808. else
  1809. {
  1810. // Original data without Z
  1811. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1812. &parseStart.year,
  1813. &parseStart.month,
  1814. &parseStart.mday,
  1815. &parseStart.hour,
  1816. &parseStart.min,
  1817. &parseStart.sec,
  1818. &parseStart.tz_hour,
  1819. &parseStart.tz_min);
  1820. }
  1821. }
  1822. if(strstr((char*)stop, ".") != NULL)
  1823. {
  1824. // Original data with mini second
  1825. if(strstr((char*)stop, "Z") != NULL)
  1826. {
  1827. // Original data with Z
  1828. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1829. &parseStop.year,
  1830. &parseStop.month,
  1831. &parseStop.mday,
  1832. &parseStop.hour,
  1833. &parseStop.min,
  1834. &parseStop.sec,
  1835. &parseStop.minSec);
  1836. }
  1837. else
  1838. {
  1839. // Original data without Z
  1840. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1841. &parseStop.year,
  1842. &parseStop.month,
  1843. &parseStop.mday,
  1844. &parseStop.hour,
  1845. &parseStop.min,
  1846. &parseStop.sec,
  1847. &parseStop.minSec,
  1848. &parseStop.tz_hour,
  1849. &parseStop.tz_min);
  1850. }
  1851. }
  1852. else
  1853. {
  1854. // Original data without mini second
  1855. if(strstr((char*)stop, "Z") != NULL)
  1856. {
  1857. // Original data with Z
  1858. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1859. &parseStop.year,
  1860. &parseStop.month,
  1861. &parseStop.mday,
  1862. &parseStop.hour,
  1863. &parseStop.min,
  1864. &parseStop.sec);
  1865. }
  1866. else
  1867. {
  1868. // Original data without Z
  1869. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1870. &parseStop.year,
  1871. &parseStop.month,
  1872. &parseStop.mday,
  1873. &parseStop.hour,
  1874. &parseStop.min,
  1875. &parseStop.sec,
  1876. &parseStop.tz_hour,
  1877. &parseStop.tz_min);
  1878. }
  1879. }
  1880. // Calculate date time difference
  1881. if((parseStart.scanedElement >=6) &&
  1882. (parseStop.scanedElement >=6))
  1883. {
  1884. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1885. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1886. tmStart.tm_year = parseStart.year - 1900;
  1887. tmStart.tm_mon = parseStart.month - 1;
  1888. tmStart.tm_mday = parseStart.mday;
  1889. tmStart.tm_hour = parseStart.hour;
  1890. tmStart.tm_min = parseStart.min;
  1891. tmStart.tm_sec = parseStart.sec;
  1892. tmStart.tm_gmtoff = 0;
  1893. tbStart.time = mktime(&tmStart);
  1894. tbStart.timezone = 0;
  1895. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1896. tmStop.tm_year = parseStop.year - 1900;
  1897. tmStop.tm_mon = parseStop.month - 1;
  1898. tmStop.tm_mday = parseStop.mday;
  1899. tmStop.tm_hour = parseStop.hour;
  1900. tmStop.tm_min = parseStop.min;
  1901. tmStop.tm_sec = parseStop.sec;
  1902. tmStop.tm_gmtoff = 0;
  1903. tbStop.time = mktime(&tmStop);
  1904. tbStop.timezone = 0;
  1905. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1906. result = DiffTimebSec(tbStart, tbStop);
  1907. //DEBUG_INFO("getStartStop(): %d\n", result);
  1908. }
  1909. else
  1910. {
  1911. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1912. }
  1913. return result;
  1914. }
  1915. int isOvertNow(uint8_t *start)
  1916. {
  1917. int result = NO;
  1918. struct ParsingResult
  1919. {
  1920. int result;
  1921. int scanedElement;
  1922. int year;
  1923. int month;
  1924. int mday;
  1925. int hour;
  1926. int min;
  1927. int sec;
  1928. int tz_hour;
  1929. int tz_min;
  1930. float minSec;
  1931. }parsingResult;
  1932. struct tm tmStart;
  1933. struct timeb tbStart;
  1934. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1935. if(strstr((char*)start, ".") != NULL)
  1936. {
  1937. // Original data with mini second
  1938. if(strstr((char*)start, "Z") != NULL)
  1939. {
  1940. // Original data with Z
  1941. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1942. &parsingResult.year,
  1943. &parsingResult.month,
  1944. &parsingResult.mday,
  1945. &parsingResult.hour,
  1946. &parsingResult.min,
  1947. &parsingResult.sec,
  1948. &parsingResult.minSec);
  1949. }
  1950. else
  1951. {
  1952. // Original data without Z
  1953. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1954. &parsingResult.year,
  1955. &parsingResult.month,
  1956. &parsingResult.mday,
  1957. &parsingResult.hour,
  1958. &parsingResult.min,
  1959. &parsingResult.sec,
  1960. &parsingResult.minSec,
  1961. &parsingResult.tz_hour,
  1962. &parsingResult.tz_min);
  1963. }
  1964. }
  1965. else
  1966. {
  1967. // Original data without mini second
  1968. if(strstr((char*)start, "Z") != NULL)
  1969. {
  1970. // Original data with Z
  1971. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1972. &parsingResult.year,
  1973. &parsingResult.month,
  1974. &parsingResult.mday,
  1975. &parsingResult.hour,
  1976. &parsingResult.min,
  1977. &parsingResult.sec);
  1978. }
  1979. else
  1980. {
  1981. // Original data without Z
  1982. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1983. &parsingResult.year,
  1984. &parsingResult.month,
  1985. &parsingResult.mday,
  1986. &parsingResult.hour,
  1987. &parsingResult.min,
  1988. &parsingResult.sec,
  1989. &parsingResult.tz_hour,
  1990. &parsingResult.tz_min);
  1991. }
  1992. }
  1993. if(parsingResult.scanedElement >= 6)
  1994. {
  1995. tmStart.tm_year = parsingResult.year - 1900;
  1996. tmStart.tm_mon = parsingResult.month - 1;
  1997. tmStart.tm_mday = parsingResult.mday;
  1998. tmStart.tm_hour = parsingResult.hour;
  1999. tmStart.tm_min = parsingResult.min;
  2000. tmStart.tm_sec = parsingResult.sec;
  2001. tmStart.tm_gmtoff = 0;
  2002. tbStart.time = mktime(&tmStart);
  2003. tbStart.timezone = 0;
  2004. tbStart.millitm = 0;
  2005. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  2006. if(DiffTimebWithNowSec(tbStart) <= 0)
  2007. result = NO;
  2008. else
  2009. result = YES;
  2010. }
  2011. else
  2012. {
  2013. DEBUG_WARN("Start date parsing error.\n");
  2014. }
  2015. return result;
  2016. }
  2017. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  2018. {
  2019. struct ParsingResult
  2020. {
  2021. int result;
  2022. int scanedElement;
  2023. int year;
  2024. int month;
  2025. int mday;
  2026. int hour;
  2027. int min;
  2028. int sec;
  2029. int tz_hour;
  2030. int tz_min;
  2031. float minSec;
  2032. };
  2033. struct ParsingResult parseStart;
  2034. struct ParsingResult parseStop;
  2035. int result = -1;
  2036. struct tm tmStart;
  2037. struct timeb tbStart;
  2038. struct tm tmStop;
  2039. struct timeb tbStop;
  2040. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  2041. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  2042. // Scan start & stop date time
  2043. if(strstr((char*)start, ".") != NULL)
  2044. {
  2045. // Original data with mini second
  2046. if(strstr((char*)start, "Z") != NULL)
  2047. {
  2048. // Original data with Z
  2049. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  2050. &parseStart.year,
  2051. &parseStart.month,
  2052. &parseStart.mday,
  2053. &parseStart.hour,
  2054. &parseStart.min,
  2055. &parseStart.sec,
  2056. &parseStart.minSec);
  2057. }
  2058. else
  2059. {
  2060. // Original data without Z
  2061. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2062. &parseStart.year,
  2063. &parseStart.month,
  2064. &parseStart.mday,
  2065. &parseStart.hour,
  2066. &parseStart.min,
  2067. &parseStart.sec,
  2068. &parseStart.minSec,
  2069. &parseStart.tz_hour,
  2070. &parseStart.tz_min);
  2071. }
  2072. }
  2073. else
  2074. {
  2075. // Original data without mini second
  2076. if(strstr((char*)start, "Z") != NULL)
  2077. {
  2078. // Original data with Z
  2079. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  2080. &parseStart.year,
  2081. &parseStart.month,
  2082. &parseStart.mday,
  2083. &parseStart.hour,
  2084. &parseStart.min,
  2085. &parseStart.sec);
  2086. }
  2087. else
  2088. {
  2089. // Original data without Z
  2090. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  2091. &parseStart.year,
  2092. &parseStart.month,
  2093. &parseStart.mday,
  2094. &parseStart.hour,
  2095. &parseStart.min,
  2096. &parseStart.sec,
  2097. &parseStart.tz_hour,
  2098. &parseStart.tz_min);
  2099. }
  2100. }
  2101. if(strstr((char*)stop, ".") != NULL)
  2102. {
  2103. // Original data with mini second
  2104. if(strstr((char*)stop, "Z") != NULL)
  2105. {
  2106. // Original data with Z
  2107. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  2108. &parseStop.year,
  2109. &parseStop.month,
  2110. &parseStop.mday,
  2111. &parseStop.hour,
  2112. &parseStop.min,
  2113. &parseStop.sec,
  2114. &parseStop.minSec);
  2115. }
  2116. else
  2117. {
  2118. // Original data without Z
  2119. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2120. &parseStop.year,
  2121. &parseStop.month,
  2122. &parseStop.mday,
  2123. &parseStop.hour,
  2124. &parseStop.min,
  2125. &parseStop.sec,
  2126. &parseStop.minSec,
  2127. &parseStop.tz_hour,
  2128. &parseStop.tz_min);
  2129. }
  2130. }
  2131. else
  2132. {
  2133. // Original data without mini second
  2134. if(strstr((char*)stop, "Z") != NULL)
  2135. {
  2136. // Original data with Z
  2137. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  2138. &parseStop.year,
  2139. &parseStop.month,
  2140. &parseStop.mday,
  2141. &parseStop.hour,
  2142. &parseStop.min,
  2143. &parseStop.sec);
  2144. }
  2145. else
  2146. {
  2147. // Original data without Z
  2148. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  2149. &parseStop.year,
  2150. &parseStop.month,
  2151. &parseStop.mday,
  2152. &parseStop.hour,
  2153. &parseStop.min,
  2154. &parseStop.sec,
  2155. &parseStop.tz_hour,
  2156. &parseStop.tz_min);
  2157. }
  2158. }
  2159. // Calculate date time difference
  2160. if((parseStart.scanedElement >=6) &&
  2161. (parseStop.scanedElement >=6))
  2162. {
  2163. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  2164. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  2165. tmStart.tm_year = parseStart.year - 1900;
  2166. tmStart.tm_mon = parseStart.month - 1;
  2167. tmStart.tm_mday = parseStart.mday;
  2168. tmStart.tm_hour = parseStart.hour;
  2169. tmStart.tm_min = parseStart.min;
  2170. tmStart.tm_sec = parseStart.sec;
  2171. tmStart.tm_gmtoff = 0;
  2172. tbStart.time = mktime(&tmStart);
  2173. tbStart.timezone = 0;
  2174. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  2175. tmStop.tm_year = parseStop.year - 1900;
  2176. tmStop.tm_mon = parseStop.month - 1;
  2177. tmStop.tm_mday = parseStop.mday;
  2178. tmStop.tm_hour = parseStop.hour;
  2179. tmStop.tm_min = parseStop.min;
  2180. tmStop.tm_sec = parseStop.sec;
  2181. tmStop.tm_gmtoff = 0;
  2182. tbStop.time = mktime(&tmStop);
  2183. tbStop.timezone = 0;
  2184. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  2185. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  2186. //DEBUG_INFO("getStartStop(): %d\n", result);
  2187. }
  2188. else
  2189. {
  2190. DEBUG_WARN("Start or stop date parsing error.\r\n");
  2191. }
  2192. return result;
  2193. }
  2194. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2195. {
  2196. FILE *fp;
  2197. char profileFileName[128];
  2198. char *line = NULL;
  2199. size_t len = 0;
  2200. time_t CurrentTime;
  2201. struct tm *tmComposite;
  2202. struct StructChargingProfile maxProfile;
  2203. struct StructChargingProfile compositeProfile;
  2204. uint8_t limitMax=0;
  2205. int compositePeriodIdx = 0;
  2206. //uint8_t isDurationNull = FALSE;
  2207. CurrentTime = time(NULL);
  2208. tmComposite=localtime(&CurrentTime);
  2209. sprintf((char*)compositeProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  2210. if(isUnitA)
  2211. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2212. else
  2213. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2214. compositeProfile.ChargingSchedule.Duration = durationReq;
  2215. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2216. {
  2217. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2218. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2219. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2220. }
  2221. compositeProfile.ChargingProfileId = 0;
  2222. compositeProfile.StackLevel = 99 ;
  2223. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2224. maxProfile.ChargingProfileId = -1;
  2225. maxProfile.ChargingSchedule.Duration = -1;
  2226. system("rm -f /tmp/*.json");
  2227. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2228. // Search max profile
  2229. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2230. if((access(profileFileName, F_OK))!=-1)
  2231. {
  2232. fp = fopen(profileFileName, "r");
  2233. while(getline(&line, &len, fp) != -1)
  2234. {
  2235. json_object *obj = NULL;
  2236. obj = json_tokener_parse(line);
  2237. if(is_error(obj))
  2238. {
  2239. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2240. }
  2241. else
  2242. {
  2243. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2244. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2245. )
  2246. {
  2247. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2248. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2249. )
  2250. {
  2251. struct tm tmFrom, tmTo;
  2252. struct timeb tbFrom, tbTo;
  2253. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2254. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2255. {
  2256. tmFrom.tm_year -= 1900;
  2257. tmFrom.tm_mon -= 1;
  2258. tbFrom.time = mktime(&tmFrom);
  2259. tmTo.tm_year -= 1900;
  2260. tmTo.tm_mon -= 1;
  2261. tbTo.time = mktime(&tmTo);
  2262. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2263. {
  2264. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2265. {
  2266. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2267. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2268. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2269. }
  2270. if(maxProfile.ChargingProfileId == -1)
  2271. DEBUG_INFO("MaxProfile found.\n");
  2272. else
  2273. DEBUG_INFO("MaxProfile updated.\n");
  2274. // Required item
  2275. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2276. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2277. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2278. if(isUnitA)
  2279. {
  2280. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2281. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2282. {
  2283. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2284. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2285. 3:
  2286. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2287. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2288. }
  2289. }
  2290. else
  2291. {
  2292. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2293. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2294. {
  2295. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2296. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2297. 3:
  2298. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2299. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2300. }
  2301. }
  2302. // Optional item
  2303. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2304. {
  2305. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2306. }
  2307. else
  2308. {
  2309. sprintf((char*)maxProfile.ValidFrom, " ");
  2310. }
  2311. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2312. {
  2313. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2314. }
  2315. else
  2316. {
  2317. sprintf((char*)maxProfile.ValidTo, " ");
  2318. }
  2319. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2320. {
  2321. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2322. }
  2323. else
  2324. {
  2325. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2326. }
  2327. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2328. {
  2329. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2330. }
  2331. else
  2332. {
  2333. maxProfile.TransactionId = -1;
  2334. }
  2335. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2336. {
  2337. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2338. }
  2339. else
  2340. {
  2341. maxProfile.ChargingSchedule.Duration = 86400;
  2342. //isDurationNull = TRUE;
  2343. }
  2344. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2345. {
  2346. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2347. }
  2348. else
  2349. {
  2350. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2351. }
  2352. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2353. {
  2354. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2355. }
  2356. else
  2357. {
  2358. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2359. }
  2360. }
  2361. }
  2362. }
  2363. else
  2364. {
  2365. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2366. {
  2367. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2368. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2369. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2370. }
  2371. if(maxProfile.ChargingProfileId == -1)
  2372. DEBUG_INFO("MaxProfile found.\n");
  2373. else
  2374. DEBUG_INFO("MaxProfile updated.\n");
  2375. // Required item
  2376. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2377. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2378. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2379. if(isUnitA)
  2380. {
  2381. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2382. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2383. {
  2384. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2385. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2386. 3:
  2387. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2388. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2389. }
  2390. }
  2391. else
  2392. {
  2393. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2394. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2395. {
  2396. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2397. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2398. 3:
  2399. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2400. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2401. }
  2402. }
  2403. // Optional item
  2404. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2405. {
  2406. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2407. }
  2408. else
  2409. {
  2410. sprintf((char*)maxProfile.ValidFrom, " ");
  2411. }
  2412. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2413. {
  2414. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2415. }
  2416. else
  2417. {
  2418. sprintf((char*)maxProfile.ValidTo, " ");
  2419. }
  2420. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2421. {
  2422. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2423. }
  2424. else
  2425. {
  2426. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2427. }
  2428. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2429. {
  2430. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2431. }
  2432. else
  2433. {
  2434. maxProfile.TransactionId = -1;
  2435. }
  2436. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2437. {
  2438. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2439. }
  2440. else
  2441. {
  2442. maxProfile.ChargingSchedule.Duration = 86400;
  2443. //isDurationNull = TRUE;
  2444. }
  2445. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2446. {
  2447. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2448. }
  2449. else
  2450. {
  2451. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2452. }
  2453. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2454. {
  2455. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2456. }
  2457. else
  2458. {
  2459. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2460. }
  2461. }
  2462. }
  2463. }
  2464. json_object_put(obj);
  2465. }
  2466. fclose(fp);
  2467. /*
  2468. if(maxProfile.ChargingProfileId !=-1)
  2469. {
  2470. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2471. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2472. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2473. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2474. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2475. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2476. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2477. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2478. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2479. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2480. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2481. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2482. {
  2483. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2484. {
  2485. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2486. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2487. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2488. }
  2489. }
  2490. }
  2491. else
  2492. DEBUG_INFO("MaxProfile not found.\n");
  2493. DEBUG_INFO("------------------------------------\n");*/
  2494. }
  2495. if(maxProfile.ChargingProfileId != -1)
  2496. {
  2497. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2498. {
  2499. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  2500. {
  2501. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2502. 0:
  2503. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2504. }
  2505. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2506. {
  2507. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2508. {
  2509. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2510. 0:
  2511. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2512. if(idxPeriod > 0)
  2513. {
  2514. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2515. {
  2516. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2517. }
  2518. }
  2519. }
  2520. }
  2521. }
  2522. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2523. {
  2524. if(maxProfile.ChargingSchedule.Duration != -1)
  2525. {
  2526. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2527. }
  2528. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2529. {
  2530. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2531. {
  2532. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2533. if(idxPeriod > 0)
  2534. {
  2535. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2536. {
  2537. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2538. }
  2539. }
  2540. }
  2541. }
  2542. }
  2543. else
  2544. {
  2545. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2546. {
  2547. if(maxProfile.ChargingSchedule.Duration != -1)
  2548. {
  2549. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2550. 0:
  2551. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2552. }
  2553. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2554. {
  2555. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2556. {
  2557. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2558. 0:
  2559. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2560. if(idxPeriod > 0)
  2561. {
  2562. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2563. {
  2564. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2565. }
  2566. }
  2567. }
  2568. }
  2569. }
  2570. else
  2571. {
  2572. if(maxProfile.ChargingSchedule.Duration != -1)
  2573. {
  2574. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2575. 0:
  2576. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2577. }
  2578. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2579. {
  2580. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2581. {
  2582. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2583. 0:
  2584. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2585. if(idxPeriod > 0)
  2586. {
  2587. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2588. {
  2589. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2590. }
  2591. }
  2592. }
  2593. }
  2594. }
  2595. }
  2596. /*
  2597. DEBUG_INFO("MaxProfile after align.\n");
  2598. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2599. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2600. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2601. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2602. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2603. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2604. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2605. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2606. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2607. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2608. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2609. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2610. {
  2611. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2612. {
  2613. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2614. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2615. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2616. }
  2617. }
  2618. DEBUG_INFO("------------------------------------\n");*/
  2619. }
  2620. // Find each profile period quantity
  2621. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2622. {
  2623. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2624. limitMax = idx+1;
  2625. }
  2626. if(maxProfile.ChargingProfileId != -1)
  2627. {
  2628. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2629. {
  2630. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2631. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2632. (maxProfile.ChargingSchedule.Duration > 0))
  2633. {
  2634. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2635. {
  2636. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2637. compositePeriodIdx++;
  2638. }
  2639. else
  2640. {
  2641. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2642. }
  2643. }
  2644. }
  2645. }
  2646. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2647. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2648. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2649. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2650. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2651. {
  2652. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2653. {
  2654. compositeProfile.ChargingProfileId = 1;
  2655. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2656. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2657. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2658. }
  2659. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2660. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2661. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2662. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2663. }
  2664. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2665. if(line)
  2666. free(line);
  2667. }
  2668. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2669. {
  2670. FILE *fp;
  2671. char profileFileName[128];
  2672. char *line = NULL;
  2673. size_t len = 0;
  2674. time_t CurrentTime;
  2675. struct tm *tmComposite;
  2676. struct StructChargingProfile maxProfile;
  2677. struct StructChargingProfile defaultTxProfile;
  2678. struct StructChargingProfile txProfile;
  2679. struct StructChargingProfile compositeProfile;
  2680. struct StructChargingSchedulePeriod tmpPeriod;
  2681. uint8_t limitMax=0;
  2682. uint8_t limitDef=0;
  2683. uint8_t limitTx=0;
  2684. int compositePeriodIdx = 0;
  2685. CurrentTime = time(NULL);
  2686. tmComposite=localtime(&CurrentTime);
  2687. sprintf((char*)compositeProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  2688. if(isUnitA)
  2689. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2690. else
  2691. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2692. compositeProfile.ChargingSchedule.Duration = durationReq;
  2693. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2694. {
  2695. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2696. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2697. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2698. }
  2699. compositeProfile.ChargingProfileId = 0;
  2700. compositeProfile.StackLevel = 99 ;
  2701. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2702. maxProfile.ChargingProfileId = -1;
  2703. defaultTxProfile.ChargingProfileId = -1;
  2704. txProfile.ChargingProfileId = -1;
  2705. maxProfile.ChargingSchedule.Duration = -1;
  2706. defaultTxProfile.ChargingSchedule.Duration = -1;
  2707. txProfile.ChargingSchedule.Duration = -1;
  2708. system("rm -f /tmp/*.json");
  2709. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2710. /*
  2711. * Search valid charging profile
  2712. */
  2713. //DEBUG_INFO("====================================\n");
  2714. // Search tx profile
  2715. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2716. if((access(profileFileName, F_OK))!=-1)
  2717. {
  2718. fp = fopen(profileFileName, "r");
  2719. while(getline(&line, &len, fp) != -1)
  2720. {
  2721. json_object *obj = NULL;
  2722. obj = json_tokener_parse(line);
  2723. if(is_error(obj))
  2724. {
  2725. DEBUG_ERROR("Parse txProfile from file error.\n");
  2726. }
  2727. else
  2728. {
  2729. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2730. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2731. )
  2732. {
  2733. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2734. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2735. )
  2736. {
  2737. struct tm tmFrom, tmTo;
  2738. struct timeb tbFrom, tbTo;
  2739. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2740. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2741. {
  2742. tmFrom.tm_year -= 1900;
  2743. tmFrom.tm_mon -= 1;
  2744. tbFrom.time = mktime(&tmFrom);
  2745. tmTo.tm_year -= 1900;
  2746. tmTo.tm_mon -= 1;
  2747. tbTo.time = mktime(&tmTo);
  2748. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2749. {
  2750. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2751. {
  2752. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2753. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2754. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2755. }
  2756. if(txProfile.ChargingProfileId == -1)
  2757. DEBUG_INFO("TxProfile found.\n");
  2758. else
  2759. DEBUG_INFO("TxProfile updated.\n");
  2760. // Required item
  2761. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2762. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2763. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2764. if(isUnitA)
  2765. {
  2766. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2767. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2768. {
  2769. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2770. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2771. 3:
  2772. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2773. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2774. }
  2775. }
  2776. else
  2777. {
  2778. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2779. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2780. {
  2781. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2782. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2783. 3:
  2784. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2785. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2786. }
  2787. }
  2788. // Optional item
  2789. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2790. {
  2791. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2792. }
  2793. else
  2794. {
  2795. sprintf((char*)txProfile.ValidFrom, " ");
  2796. }
  2797. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2798. {
  2799. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2800. }
  2801. else
  2802. {
  2803. sprintf((char*)txProfile.ValidTo, " ");
  2804. }
  2805. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2806. {
  2807. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2808. }
  2809. else
  2810. {
  2811. sprintf((char*)txProfile.RecurrencyKind, " ");
  2812. }
  2813. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2814. {
  2815. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2816. }
  2817. else
  2818. {
  2819. txProfile.TransactionId = -1;
  2820. }
  2821. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2822. {
  2823. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2824. }
  2825. else
  2826. {
  2827. txProfile.ChargingSchedule.Duration = 86400;
  2828. }
  2829. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2830. {
  2831. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2832. }
  2833. else
  2834. {
  2835. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2836. }
  2837. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2838. {
  2839. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2840. }
  2841. else
  2842. {
  2843. txProfile.ChargingSchedule.MinChargingRate = -1;
  2844. }
  2845. }
  2846. }
  2847. }
  2848. else
  2849. {
  2850. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2851. {
  2852. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2853. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2854. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2855. }
  2856. if(txProfile.ChargingProfileId == -1)
  2857. DEBUG_INFO("TxProfile found.\n");
  2858. else
  2859. DEBUG_INFO("TxProfile updated.\n");
  2860. // Required item
  2861. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2862. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2863. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2864. if(isUnitA)
  2865. {
  2866. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2867. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2868. {
  2869. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2870. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2871. 3:
  2872. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2873. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2874. }
  2875. }
  2876. else
  2877. {
  2878. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2879. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2880. {
  2881. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2882. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2883. 3:
  2884. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2885. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2886. }
  2887. }
  2888. // Optional item
  2889. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2890. {
  2891. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2892. }
  2893. else
  2894. {
  2895. sprintf((char*)txProfile.ValidFrom, " ");
  2896. }
  2897. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2898. {
  2899. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2900. }
  2901. else
  2902. {
  2903. sprintf((char*)txProfile.ValidTo, " ");
  2904. }
  2905. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2906. {
  2907. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2908. }
  2909. else
  2910. {
  2911. sprintf((char*)txProfile.RecurrencyKind, " ");
  2912. }
  2913. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2914. {
  2915. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2916. }
  2917. else
  2918. {
  2919. txProfile.TransactionId = -1;
  2920. }
  2921. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2922. {
  2923. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2924. }
  2925. else
  2926. {
  2927. txProfile.ChargingSchedule.Duration = 86400;
  2928. }
  2929. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2930. {
  2931. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2932. }
  2933. else
  2934. {
  2935. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2936. }
  2937. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2938. {
  2939. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2940. }
  2941. else
  2942. {
  2943. txProfile.ChargingSchedule.MinChargingRate = -1;
  2944. }
  2945. }
  2946. }
  2947. }
  2948. json_object_put(obj);
  2949. }
  2950. fclose(fp);
  2951. /*
  2952. if(txProfile.ChargingProfileId != -1)
  2953. {
  2954. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2955. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2956. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2957. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2958. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2959. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2960. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2961. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2962. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2963. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2964. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2965. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2966. {
  2967. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2968. {
  2969. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2970. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2971. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2972. }
  2973. }
  2974. }
  2975. else
  2976. DEBUG_INFO("TxProfile not found.\n");*/
  2977. }
  2978. // Search default tx profile
  2979. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2980. if((access(profileFileName, F_OK))==-1)
  2981. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2982. if((access(profileFileName, F_OK))!=-1)
  2983. {
  2984. fp = fopen(profileFileName, "r");
  2985. while(getline(&line, &len, fp) != -1)
  2986. {
  2987. json_object *obj = NULL;
  2988. obj = json_tokener_parse(line);
  2989. if(is_error(obj))
  2990. {
  2991. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2992. }
  2993. else
  2994. {
  2995. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2996. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2997. )
  2998. {
  2999. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3000. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3001. )
  3002. {
  3003. struct tm tmFrom, tmTo;
  3004. struct timeb tbFrom, tbTo;
  3005. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  3006. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  3007. {
  3008. tmFrom.tm_year -= 1900;
  3009. tmFrom.tm_mon -= 1;
  3010. tbFrom.time = mktime(&tmFrom);
  3011. tmTo.tm_year -= 1900;
  3012. tmTo.tm_mon -= 1;
  3013. tbTo.time = mktime(&tmTo);
  3014. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3015. {
  3016. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3017. {
  3018. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3019. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3020. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3021. }
  3022. if(defaultTxProfile.ChargingProfileId == -1)
  3023. DEBUG_INFO("TxDefaultProfile found.\n");
  3024. else
  3025. DEBUG_INFO("TxDefaultProfile updated.\n");
  3026. // Required item
  3027. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3028. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3029. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3030. if(isUnitA)
  3031. {
  3032. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3033. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3034. {
  3035. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3036. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3037. 3:
  3038. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3039. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3040. }
  3041. }
  3042. else
  3043. {
  3044. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3045. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3046. {
  3047. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3048. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3049. 3:
  3050. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3051. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  3052. }
  3053. }
  3054. // Optional item
  3055. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3056. {
  3057. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3058. }
  3059. else
  3060. {
  3061. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  3062. }
  3063. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3064. {
  3065. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3066. }
  3067. else
  3068. {
  3069. sprintf((char*)defaultTxProfile.ValidTo, " ");
  3070. }
  3071. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3072. {
  3073. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3074. }
  3075. else
  3076. {
  3077. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  3078. }
  3079. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3080. {
  3081. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3082. }
  3083. else
  3084. {
  3085. defaultTxProfile.TransactionId = -1;
  3086. }
  3087. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3088. {
  3089. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3090. }
  3091. else
  3092. {
  3093. defaultTxProfile.ChargingSchedule.Duration = 86400;
  3094. }
  3095. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3096. {
  3097. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3098. }
  3099. else
  3100. {
  3101. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  3102. }
  3103. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3104. {
  3105. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3106. }
  3107. else
  3108. {
  3109. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  3110. }
  3111. }
  3112. }
  3113. }
  3114. else
  3115. {
  3116. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3117. {
  3118. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3119. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3120. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3121. }
  3122. if(defaultTxProfile.ChargingProfileId == -1)
  3123. DEBUG_INFO("TxDefaultProfile found.\n");
  3124. else
  3125. DEBUG_INFO("TxDefaultProfile updated.\n");
  3126. // Required item
  3127. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3128. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3129. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3130. if(isUnitA)
  3131. {
  3132. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3133. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3134. {
  3135. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3136. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3137. 3:
  3138. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3139. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3140. }
  3141. }
  3142. else
  3143. {
  3144. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3145. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3146. {
  3147. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3148. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3149. 3:
  3150. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3151. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  3152. }
  3153. }
  3154. // Optional item
  3155. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3156. {
  3157. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3158. }
  3159. else
  3160. {
  3161. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  3162. }
  3163. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3164. {
  3165. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3166. }
  3167. else
  3168. {
  3169. sprintf((char*)defaultTxProfile.ValidTo, " ");
  3170. }
  3171. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3172. {
  3173. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3174. }
  3175. else
  3176. {
  3177. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  3178. }
  3179. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3180. {
  3181. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3182. }
  3183. else
  3184. {
  3185. defaultTxProfile.TransactionId = -1;
  3186. }
  3187. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3188. {
  3189. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3190. }
  3191. else
  3192. {
  3193. defaultTxProfile.ChargingSchedule.Duration = 86400;
  3194. }
  3195. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3196. {
  3197. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3198. }
  3199. else
  3200. {
  3201. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  3202. }
  3203. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3204. {
  3205. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3206. }
  3207. else
  3208. {
  3209. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  3210. }
  3211. }
  3212. }
  3213. }
  3214. json_object_put(obj);
  3215. }
  3216. fclose(fp);
  3217. /*
  3218. if(defaultTxProfile.ChargingProfileId != -1)
  3219. {
  3220. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3221. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3222. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3223. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3224. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3225. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3226. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3227. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  3228. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3229. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3230. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3231. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3232. {
  3233. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3234. {
  3235. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3236. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3237. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3238. }
  3239. }
  3240. }
  3241. else
  3242. DEBUG_INFO("TxDefaultProfile not found.\n");
  3243. DEBUG_INFO("------------------------------------\n");*/
  3244. }
  3245. // Search max profile
  3246. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  3247. if((access(profileFileName, F_OK))!=-1)
  3248. {
  3249. fp = fopen(profileFileName, "r");
  3250. while(getline(&line, &len, fp) != -1)
  3251. {
  3252. json_object *obj = NULL;
  3253. obj = json_tokener_parse(line);
  3254. if(is_error(obj))
  3255. {
  3256. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  3257. }
  3258. else
  3259. {
  3260. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  3261. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  3262. )
  3263. {
  3264. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3265. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3266. )
  3267. {
  3268. struct tm tmFrom, tmTo;
  3269. struct timeb tbFrom, tbTo;
  3270. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  3271. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  3272. {
  3273. tmFrom.tm_year -= 1900;
  3274. tmFrom.tm_mon -= 1;
  3275. tbFrom.time = mktime(&tmFrom);
  3276. tmTo.tm_year -= 1900;
  3277. tmTo.tm_mon -= 1;
  3278. tbTo.time = mktime(&tmTo);
  3279. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3280. {
  3281. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3282. {
  3283. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3284. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3285. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3286. }
  3287. if(maxProfile.ChargingProfileId == -1)
  3288. DEBUG_INFO("MaxProfile found.\n");
  3289. else
  3290. DEBUG_INFO("MaxProfile updated.\n");
  3291. // Required item
  3292. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3293. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3294. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3295. if(isUnitA)
  3296. {
  3297. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3298. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3299. {
  3300. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3301. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3302. 3:
  3303. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3304. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3305. }
  3306. }
  3307. else
  3308. {
  3309. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3310. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3311. {
  3312. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3313. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3314. 3:
  3315. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3316. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  3317. }
  3318. }
  3319. // Optional item
  3320. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3321. {
  3322. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3323. }
  3324. else
  3325. {
  3326. sprintf((char*)maxProfile.ValidFrom, " ");
  3327. }
  3328. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3329. {
  3330. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3331. }
  3332. else
  3333. {
  3334. sprintf((char*)maxProfile.ValidTo, " ");
  3335. }
  3336. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3337. {
  3338. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3339. }
  3340. else
  3341. {
  3342. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3343. }
  3344. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3345. {
  3346. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3347. }
  3348. else
  3349. {
  3350. maxProfile.TransactionId = -1;
  3351. }
  3352. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3353. {
  3354. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3355. }
  3356. else
  3357. {
  3358. maxProfile.ChargingSchedule.Duration = 86400;
  3359. }
  3360. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3361. {
  3362. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3363. }
  3364. else
  3365. {
  3366. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  3367. }
  3368. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3369. {
  3370. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3371. }
  3372. else
  3373. {
  3374. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3375. }
  3376. }
  3377. }
  3378. }
  3379. else
  3380. {
  3381. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3382. {
  3383. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3384. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3385. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3386. }
  3387. if(maxProfile.ChargingProfileId == -1)
  3388. DEBUG_INFO("MaxProfile found.\n");
  3389. else
  3390. DEBUG_INFO("MaxProfile updated.\n");
  3391. // Required item
  3392. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3393. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3394. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3395. if(isUnitA)
  3396. {
  3397. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3398. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3399. {
  3400. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3401. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3402. 3:
  3403. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3404. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3405. }
  3406. }
  3407. else
  3408. {
  3409. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3410. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3411. {
  3412. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3413. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3414. 3:
  3415. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3416. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  3417. }
  3418. }
  3419. // Optional item
  3420. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3421. {
  3422. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3423. }
  3424. else
  3425. {
  3426. sprintf((char*)maxProfile.ValidFrom, " ");
  3427. }
  3428. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3429. {
  3430. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3431. }
  3432. else
  3433. {
  3434. sprintf((char*)maxProfile.ValidTo, " ");
  3435. }
  3436. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3437. {
  3438. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3439. }
  3440. else
  3441. {
  3442. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3443. }
  3444. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3445. {
  3446. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3447. }
  3448. else
  3449. {
  3450. maxProfile.TransactionId = -1;
  3451. }
  3452. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3453. {
  3454. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3455. }
  3456. else
  3457. {
  3458. maxProfile.ChargingSchedule.Duration = 86400;
  3459. }
  3460. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3461. {
  3462. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3463. }
  3464. else
  3465. {
  3466. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  3467. }
  3468. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3469. {
  3470. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3471. }
  3472. else
  3473. {
  3474. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3475. }
  3476. }
  3477. }
  3478. }
  3479. json_object_put(obj);
  3480. }
  3481. fclose(fp);
  3482. /*
  3483. if(maxProfile.ChargingProfileId !=-1)
  3484. {
  3485. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3486. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3487. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3488. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3489. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3490. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3491. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3492. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3493. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3494. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3495. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3496. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3497. {
  3498. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3499. {
  3500. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3501. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3502. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3503. }
  3504. }
  3505. }
  3506. else
  3507. DEBUG_INFO("MaxProfile not found.\n");
  3508. DEBUG_INFO("------------------------------------\n");*/
  3509. }
  3510. /*
  3511. * Align found profile start schedule & periods
  3512. */
  3513. //DEBUG_INFO("====================================\n");
  3514. /*
  3515. // For local test usage, force modify found profile start schedule info
  3516. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  3517. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  3518. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  3519. */
  3520. if(txProfile.ChargingProfileId != -1)
  3521. {
  3522. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3523. {
  3524. if(txProfile.ChargingSchedule.Duration != -1)
  3525. {
  3526. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3527. 0:
  3528. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3529. }
  3530. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3531. {
  3532. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3533. {
  3534. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3535. 0:
  3536. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3537. if(idxPeriod > 0)
  3538. {
  3539. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3540. {
  3541. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3542. }
  3543. }
  3544. }
  3545. }
  3546. }
  3547. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3548. {
  3549. if(txProfile.ChargingSchedule.Duration != -1)
  3550. {
  3551. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3552. 0:
  3553. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3554. }
  3555. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3556. {
  3557. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3558. {
  3559. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3560. 0:
  3561. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3562. if(idxPeriod > 0)
  3563. {
  3564. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3565. {
  3566. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3567. }
  3568. }
  3569. }
  3570. }
  3571. }
  3572. else
  3573. {
  3574. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3575. {
  3576. if(txProfile.ChargingSchedule.Duration != -1)
  3577. {
  3578. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3579. 0:
  3580. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3581. }
  3582. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3583. {
  3584. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3585. {
  3586. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3587. 0:
  3588. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3589. if(idxPeriod > 0)
  3590. {
  3591. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3592. {
  3593. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3594. }
  3595. }
  3596. }
  3597. }
  3598. }
  3599. else
  3600. {
  3601. if(txProfile.ChargingSchedule.Duration != -1)
  3602. {
  3603. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3604. 0:
  3605. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3606. }
  3607. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3608. {
  3609. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3610. {
  3611. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3612. 0:
  3613. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3614. if(idxPeriod > 0)
  3615. {
  3616. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3617. {
  3618. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3619. }
  3620. }
  3621. }
  3622. }
  3623. }
  3624. }
  3625. /*
  3626. DEBUG_INFO("txProfile after align.\n");
  3627. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3628. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3629. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3630. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3631. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3632. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3633. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3634. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3635. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3636. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3637. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3638. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3639. {
  3640. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3641. {
  3642. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3643. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3644. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3645. }
  3646. }*/
  3647. }
  3648. if(defaultTxProfile.ChargingProfileId != -1)
  3649. {
  3650. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3651. {
  3652. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3653. {
  3654. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3655. 0:
  3656. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3657. }
  3658. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3659. {
  3660. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3661. {
  3662. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3663. 0:
  3664. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3665. if(idxPeriod > 0)
  3666. {
  3667. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3668. {
  3669. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3670. }
  3671. }
  3672. }
  3673. }
  3674. }
  3675. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3676. {
  3677. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3678. {
  3679. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3680. 0:
  3681. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3682. }
  3683. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3684. {
  3685. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3686. {
  3687. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3688. 0:
  3689. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3690. if(idxPeriod > 0)
  3691. {
  3692. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3693. {
  3694. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3695. }
  3696. }
  3697. }
  3698. }
  3699. }
  3700. else
  3701. {
  3702. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3703. {
  3704. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3705. {
  3706. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3707. 0:
  3708. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3709. }
  3710. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3711. {
  3712. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3713. {
  3714. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3715. 0:
  3716. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3717. if(idxPeriod > 0)
  3718. {
  3719. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3720. {
  3721. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3722. }
  3723. }
  3724. }
  3725. }
  3726. }
  3727. else
  3728. {
  3729. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3730. {
  3731. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3732. 0:
  3733. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3734. }
  3735. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3736. {
  3737. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3738. {
  3739. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3740. 0:
  3741. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3742. if(idxPeriod > 0)
  3743. {
  3744. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3745. {
  3746. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3747. }
  3748. }
  3749. }
  3750. }
  3751. }
  3752. }
  3753. /*
  3754. DEBUG_INFO("defaultTxProfile after align.\n");
  3755. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3756. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3757. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3758. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3759. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3760. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3761. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3762. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3763. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3764. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3765. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3766. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3767. {
  3768. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3769. {
  3770. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3771. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3772. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3773. }
  3774. }
  3775. DEBUG_INFO("------------------------------------\n");*/
  3776. }
  3777. if(maxProfile.ChargingProfileId != -1)
  3778. {
  3779. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3780. {
  3781. if(maxProfile.ChargingSchedule.Duration != -1)
  3782. {
  3783. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3784. 0:
  3785. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3786. }
  3787. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3788. {
  3789. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3790. {
  3791. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3792. 0:
  3793. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3794. if(idxPeriod > 0)
  3795. {
  3796. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3797. {
  3798. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3799. }
  3800. }
  3801. }
  3802. }
  3803. }
  3804. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3805. {
  3806. if(maxProfile.ChargingSchedule.Duration != -1)
  3807. {
  3808. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3809. 0:
  3810. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3811. }
  3812. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3813. {
  3814. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3815. {
  3816. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3817. 0:
  3818. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3819. if(idxPeriod > 0)
  3820. {
  3821. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3822. {
  3823. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3824. }
  3825. }
  3826. }
  3827. }
  3828. }
  3829. else
  3830. {
  3831. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3832. {
  3833. if(maxProfile.ChargingSchedule.Duration != -1)
  3834. {
  3835. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3836. 0:
  3837. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3838. }
  3839. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3840. {
  3841. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3842. {
  3843. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3844. 0:
  3845. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3846. if(idxPeriod > 0)
  3847. {
  3848. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3849. {
  3850. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3851. }
  3852. }
  3853. }
  3854. }
  3855. }
  3856. else
  3857. {
  3858. if(maxProfile.ChargingSchedule.Duration != -1)
  3859. {
  3860. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3861. 0:
  3862. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3863. }
  3864. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3865. {
  3866. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3867. {
  3868. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3869. 0:
  3870. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3871. if(idxPeriod > 0)
  3872. {
  3873. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3874. {
  3875. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3876. }
  3877. }
  3878. }
  3879. }
  3880. }
  3881. }
  3882. /*
  3883. DEBUG_INFO("MaxProfile after align.\n");
  3884. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3885. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3886. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3887. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3888. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3889. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3890. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3891. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3892. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3893. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3894. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3895. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3896. {
  3897. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3898. {
  3899. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3900. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3901. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3902. }
  3903. }
  3904. DEBUG_INFO("------------------------------------\n");*/
  3905. }
  3906. /*
  3907. * Merge to composite schedule
  3908. */
  3909. //DEBUG_INFO("====================================\n");
  3910. // Find each profile period quantity
  3911. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3912. {
  3913. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3914. limitMax = idx+1;
  3915. }
  3916. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3917. {
  3918. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3919. limitDef = idx+1;
  3920. }
  3921. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3922. {
  3923. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3924. limitTx = idx+1;
  3925. }
  3926. // TxProfile found, composite schedule based on it
  3927. if(txProfile.ChargingProfileId != -1)
  3928. {
  3929. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3930. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3931. {
  3932. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3933. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3934. (txProfile.ChargingSchedule.Duration > 0))
  3935. {
  3936. if(maxProfile.ChargingProfileId != -1)
  3937. {
  3938. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3939. {
  3940. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3941. {
  3942. if((maxProfile.ChargingSchedule.Duration > 0))
  3943. {
  3944. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3945. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3946. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3947. }
  3948. else
  3949. {
  3950. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3951. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3952. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3953. }
  3954. }
  3955. if(idxMaxPeriod == (limitMax-1))
  3956. {
  3957. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3958. {
  3959. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3960. {
  3961. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3962. compositePeriodIdx++;
  3963. }
  3964. else
  3965. {
  3966. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3967. }
  3968. }
  3969. }
  3970. }
  3971. }
  3972. else
  3973. {
  3974. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3975. {
  3976. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3977. compositePeriodIdx++;
  3978. }
  3979. else
  3980. {
  3981. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3982. }
  3983. }
  3984. }
  3985. if(idxTxPeriod == (limitTx-1))
  3986. {
  3987. if(defaultTxProfile.ChargingProfileId != -1)
  3988. {
  3989. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3990. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3991. {
  3992. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3993. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3994. (defaultTxProfile.ChargingSchedule.Duration>0))
  3995. {
  3996. if(maxProfile.ChargingProfileId != -1)
  3997. {
  3998. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3999. {
  4000. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  4001. {
  4002. if((maxProfile.ChargingSchedule.Duration > 0))
  4003. {
  4004. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  4005. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  4006. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  4007. }
  4008. else
  4009. {
  4010. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  4011. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  4012. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  4013. }
  4014. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  4015. {
  4016. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4017. {
  4018. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4019. compositePeriodIdx++;
  4020. }
  4021. else
  4022. {
  4023. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4024. }
  4025. }
  4026. // Delete duplicate period
  4027. if(compositePeriodIdx > 1)
  4028. {
  4029. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4030. {
  4031. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4032. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4033. compositePeriodIdx -= 1;
  4034. }
  4035. }
  4036. }
  4037. else
  4038. {
  4039. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4040. {
  4041. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4042. compositePeriodIdx++;
  4043. }
  4044. else
  4045. {
  4046. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4047. }
  4048. break;
  4049. }
  4050. }
  4051. }
  4052. else
  4053. {
  4054. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4055. {
  4056. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4057. compositePeriodIdx++;
  4058. }
  4059. else
  4060. {
  4061. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4062. }
  4063. }
  4064. }
  4065. }
  4066. }
  4067. }
  4068. }
  4069. }
  4070. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  4071. else if(defaultTxProfile.ChargingProfileId != -1)
  4072. {
  4073. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  4074. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  4075. {
  4076. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  4077. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  4078. (defaultTxProfile.ChargingSchedule.Duration > 0))
  4079. {
  4080. if(maxProfile.ChargingProfileId != -1)
  4081. {
  4082. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4083. {
  4084. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  4085. {
  4086. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  4087. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  4088. if((maxProfile.ChargingSchedule.Duration > 0))
  4089. {
  4090. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  4091. }
  4092. else
  4093. {
  4094. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  4095. }
  4096. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  4097. {
  4098. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4099. {
  4100. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4101. compositePeriodIdx++;
  4102. }
  4103. else
  4104. {
  4105. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4106. }
  4107. }
  4108. // Delete duplicate period
  4109. if(compositePeriodIdx > 1)
  4110. {
  4111. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4112. {
  4113. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4114. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4115. compositePeriodIdx -= 1;
  4116. }
  4117. }
  4118. }
  4119. else
  4120. {
  4121. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4122. {
  4123. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4124. compositePeriodIdx++;
  4125. }
  4126. else
  4127. {
  4128. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4129. }
  4130. break;
  4131. }
  4132. }
  4133. }
  4134. else
  4135. {
  4136. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4137. {
  4138. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4139. compositePeriodIdx++;
  4140. }
  4141. else
  4142. {
  4143. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4144. }
  4145. }
  4146. }
  4147. }
  4148. }
  4149. // Fill other period by MaxProfile
  4150. if(maxProfile.ChargingProfileId != -1)
  4151. {
  4152. if(compositePeriodIdx==0)
  4153. {
  4154. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  4155. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  4156. {
  4157. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  4158. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  4159. (maxProfile.ChargingSchedule.Duration > 0))
  4160. {
  4161. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4162. {
  4163. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  4164. compositePeriodIdx++;
  4165. }
  4166. else
  4167. {
  4168. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  4169. }
  4170. }
  4171. }
  4172. }
  4173. else
  4174. {
  4175. int lastCompositePeriodIdx = compositePeriodIdx;
  4176. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4177. {
  4178. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  4179. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  4180. (maxProfile.ChargingSchedule.Duration > 0))
  4181. {
  4182. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  4183. {
  4184. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  4185. {
  4186. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  4187. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  4188. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  4189. }
  4190. else
  4191. {
  4192. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  4193. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  4194. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  4195. }
  4196. }
  4197. if(tmpPeriod.Limit != -1)
  4198. {
  4199. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  4200. {
  4201. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  4202. {
  4203. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4204. compositePeriodIdx++;
  4205. }
  4206. else
  4207. {
  4208. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4209. }
  4210. }
  4211. // Delete duplicate period
  4212. if(compositePeriodIdx > 1)
  4213. {
  4214. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4215. {
  4216. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4217. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4218. compositePeriodIdx -= 1;
  4219. }
  4220. }
  4221. }
  4222. }
  4223. }
  4224. }
  4225. }
  4226. if(compositeProfile.ChargingSchedule.Duration < durationReq)
  4227. {
  4228. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  4229. {
  4230. if((idxPeriod > 0) && (compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == 0 || compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1))
  4231. {
  4232. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = compositeProfile.ChargingSchedule.Duration;
  4233. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (isUnitA==TRUE)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:modelnameInfo.ratedPower;
  4234. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].NumberPhases;
  4235. DEBUG_INFO(">>> Adding startPeriod because the duration of the final schedule is shorter than requested duration.\n");
  4236. DEBUG_INFO("Add Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4237. DEBUG_INFO("Add Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  4238. DEBUG_INFO("Add Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4239. DEBUG_INFO("------------------------------------------------\n");
  4240. break;
  4241. }
  4242. }
  4243. }
  4244. compositeProfile.ChargingSchedule.Duration = durationReq;
  4245. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  4246. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  4247. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  4248. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  4249. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  4250. {
  4251. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4252. {
  4253. compositeProfile.ChargingProfileId = 1;
  4254. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4255. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  4256. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4257. }
  4258. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  4259. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  4260. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  4261. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  4262. }
  4263. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  4264. if(line)
  4265. free(line);
  4266. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  4267. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  4268. }
  4269. //==========================================
  4270. // Init all share memory
  4271. //==========================================
  4272. int InitShareMemory()
  4273. {
  4274. int result = PASS;
  4275. int MeterSMId;
  4276. //creat ShmSysConfigAndInfo
  4277. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  4278. {
  4279. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  4280. result = FAIL;
  4281. }
  4282. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4283. {
  4284. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  4285. result = FAIL;
  4286. }
  4287. else
  4288. {}
  4289. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  4290. {
  4291. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  4292. result = FAIL;
  4293. }
  4294. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4295. {
  4296. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  4297. result = FAIL;
  4298. }
  4299. else
  4300. {}
  4301. //creat ShmPsuData
  4302. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  4303. {
  4304. DEBUG_ERROR("shmget ShmPsuData NG\n");
  4305. result = FAIL;
  4306. }
  4307. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4308. {
  4309. DEBUG_ERROR("shmat ShmPsuData NG\n");
  4310. result = FAIL;
  4311. }
  4312. else
  4313. {}
  4314. //creat ShmOCPP16Data
  4315. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  4316. {
  4317. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  4318. result = FAIL;
  4319. }
  4320. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4321. {
  4322. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  4323. result = FAIL;
  4324. }
  4325. else
  4326. {}
  4327. /****************************** For Initial Settings************************************************/
  4328. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  4329. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  4330. // allocate Configuration memory address
  4331. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  4332. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  4333. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  4334. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  4335. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  4336. //offline MeterValue Interval
  4337. TempMeterValueInterval = 0;
  4338. return result;
  4339. }
  4340. int ProcessShareMemory()
  4341. {
  4342. int result = PASS;
  4343. if(InitShareMemory() == FAIL)
  4344. {
  4345. DEBUG_ERROR("InitShareMemory NG\n");
  4346. if(ShmStatusCodeData!=NULL)
  4347. {
  4348. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  4349. }
  4350. result = FAIL;
  4351. }
  4352. // Model name parsing
  4353. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  4354. {
  4355. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  4356. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  4357. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  4358. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  4359. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  4360. ) // 'D' means DC
  4361. {
  4362. // DO series
  4363. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  4364. {
  4365. gunTotalNumber += 1;
  4366. gunType[gun_index] = GUN_TYPE_DO;
  4367. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4368. {
  4369. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  4370. {
  4371. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4372. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4373. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  4374. }
  4375. }
  4376. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4377. {
  4378. case Gun_Type_Chademo:
  4379. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  4380. break;
  4381. case Gun_Type_CCS_2:
  4382. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  4383. break;
  4384. case Gun_Type_GB:
  4385. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  4386. break;
  4387. case Gun_Type_AC:
  4388. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  4389. break;
  4390. default:
  4391. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  4392. break;
  4393. }
  4394. }
  4395. }
  4396. else
  4397. {
  4398. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  4399. {
  4400. gunTotalNumber += 1;
  4401. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4402. {
  4403. case Gun_Type_Chademo:
  4404. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  4405. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  4406. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  4407. {
  4408. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4409. {
  4410. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4411. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4412. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4413. }
  4414. }
  4415. break;
  4416. case Gun_Type_CCS_2:
  4417. gunType[gun_index] = GUN_TYPE_CCS;
  4418. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4419. for (int index = 0; index < CCS_QUANTITY; index++)
  4420. {
  4421. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4422. {
  4423. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4424. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4425. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4426. }
  4427. }
  4428. break;
  4429. case Gun_Type_GB:
  4430. gunType[gun_index] = GUN_TYPE_GBT;
  4431. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4432. for (int index = 0; index < GB_QUANTITY; index++)
  4433. {
  4434. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4435. {
  4436. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4437. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4438. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4439. }
  4440. }
  4441. break;
  4442. case Gun_Type_AC:
  4443. gunType[gun_index] = GUN_TYPE_AC;
  4444. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4445. for (int index = 0; index < AC_QUANTITY; index++)
  4446. {
  4447. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4448. {
  4449. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4450. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4451. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4452. }
  4453. }
  4454. break;
  4455. default:
  4456. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4457. break;
  4458. }
  4459. }
  4460. }
  4461. }
  4462. else
  4463. {
  4464. DEBUG_ERROR("Model name parsing fail.\n");
  4465. result = FAIL;
  4466. }
  4467. if(result != PASS)sleep(5);
  4468. return result;
  4469. }
  4470. void checkRemoteStart(uint8_t connectorIdInt)
  4471. {
  4472. uint8_t tempIndex;
  4473. int result = PASS;
  4474. char cmdBuf[512];
  4475. //check Transaction active
  4476. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4477. {
  4478. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4479. {
  4480. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4481. }
  4482. else
  4483. {
  4484. tempIndex = connectorIdInt -1;
  4485. }
  4486. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4487. {
  4488. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4489. {
  4490. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4491. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4492. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4493. {
  4494. //Reserved
  4495. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4496. }
  4497. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4498. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4499. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4500. {
  4501. //Reserved
  4502. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4503. result = FAIL;
  4504. goto end;
  4505. }
  4506. else
  4507. {
  4508. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4509. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4510. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4511. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4512. {
  4513. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4514. result = FAIL;
  4515. goto end;
  4516. }
  4517. }//END FOR ELSE
  4518. }
  4519. }// END FOR CHAdeMO_QUANTITY
  4520. }
  4521. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4522. {
  4523. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4524. {
  4525. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4526. }
  4527. else
  4528. {
  4529. tempIndex = connectorIdInt -1;
  4530. }
  4531. for (int index = 0; index < CCS_QUANTITY; index++)
  4532. {
  4533. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4534. {
  4535. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4536. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4537. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4538. {
  4539. //Reserved
  4540. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4541. }
  4542. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4543. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4544. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4545. {
  4546. //Reserved
  4547. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4548. result = FAIL;
  4549. goto end;
  4550. }
  4551. else
  4552. {
  4553. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4554. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4555. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4556. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4557. {
  4558. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4559. result = FAIL;
  4560. goto end;
  4561. }
  4562. }// END FOR ELSE
  4563. }
  4564. }// END FOR CCS_QUANTITY
  4565. }
  4566. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4567. {
  4568. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4569. {
  4570. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4571. }
  4572. else
  4573. {
  4574. tempIndex = connectorIdInt -1;
  4575. }
  4576. for (int index = 0; index < GB_QUANTITY; index++)
  4577. {
  4578. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4579. {
  4580. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4581. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4582. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4583. {
  4584. //Reserved
  4585. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4586. }
  4587. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4588. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4589. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4590. {
  4591. //Reserved
  4592. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4593. result = FAIL;
  4594. goto end;
  4595. }
  4596. else
  4597. {
  4598. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4599. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4600. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4601. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4602. {
  4603. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4604. result = FAIL;
  4605. goto end;
  4606. }
  4607. }// END FOR ELSE
  4608. }
  4609. } // END FOR GB_QUANTITY
  4610. }
  4611. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4612. {
  4613. tempIndex = connectorIdInt -1;
  4614. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4615. {
  4616. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4617. {
  4618. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4619. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4620. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4621. {
  4622. //Reserved
  4623. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4624. }
  4625. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4626. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4627. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4628. {
  4629. //Reserved
  4630. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4631. result = FAIL;
  4632. goto end;
  4633. }
  4634. else
  4635. {
  4636. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4637. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4638. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4639. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4640. {
  4641. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4642. result = FAIL;
  4643. goto end;
  4644. }
  4645. }// END FOR ELSE
  4646. }
  4647. } // END FOR GB_QUANTITY
  4648. }
  4649. else
  4650. {
  4651. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4652. {
  4653. tempIndex = 2;
  4654. }
  4655. else
  4656. {
  4657. tempIndex = connectorIdInt -1;
  4658. }
  4659. for (int index = 0; index < AC_QUANTITY; index++)
  4660. {
  4661. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4662. {
  4663. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4664. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4665. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4666. {
  4667. //Reserved
  4668. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4669. }
  4670. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4671. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4672. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4673. {
  4674. //Reserved
  4675. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4676. result = FAIL;
  4677. goto end;
  4678. }
  4679. else
  4680. {
  4681. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4682. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4683. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4684. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4685. {
  4686. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4687. result = FAIL;
  4688. goto end;
  4689. }
  4690. }//END FOR ELSE
  4691. }
  4692. }// END FOR AC_QUANTITY
  4693. }
  4694. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4695. {
  4696. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4697. {
  4698. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4699. {
  4700. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4701. system(cmdBuf);
  4702. }
  4703. }
  4704. else
  4705. {
  4706. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4707. result = FAIL;
  4708. }
  4709. }
  4710. end:
  4711. if(result == PASS)
  4712. {
  4713. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4714. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4715. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4716. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4717. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4718. }
  4719. }
  4720. int isConnector0Unavailable()
  4721. {
  4722. uint8_t result = YES;
  4723. uint8_t tempIndex;
  4724. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4725. {
  4726. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4727. {
  4728. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4729. {
  4730. tempIndex = ((gun_index==2) ? 1: 0);
  4731. }
  4732. else
  4733. {
  4734. tempIndex = gun_index;
  4735. }
  4736. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4737. {
  4738. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4739. {
  4740. 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))
  4741. {
  4742. result = NO;
  4743. }
  4744. }
  4745. }
  4746. }
  4747. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4748. {
  4749. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4750. {
  4751. tempIndex = ((gun_index==2) ? 1: 0);
  4752. }
  4753. else
  4754. {
  4755. tempIndex = gun_index;
  4756. }
  4757. for (int index = 0; index < CCS_QUANTITY; index++)
  4758. {
  4759. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4760. {
  4761. 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))
  4762. {
  4763. result = NO;
  4764. }
  4765. }
  4766. }
  4767. }
  4768. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4769. {
  4770. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4771. {
  4772. tempIndex = ((gun_index==2) ? 1: 0);
  4773. }
  4774. else
  4775. {
  4776. tempIndex = gun_index;
  4777. }
  4778. for (int index = 0; index < GB_QUANTITY; index++)
  4779. {
  4780. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4781. {
  4782. 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))
  4783. {
  4784. result = NO;
  4785. }
  4786. }
  4787. }
  4788. }
  4789. else if(gunType[gun_index] == GUN_TYPE_DO)
  4790. {
  4791. tempIndex = gun_index;
  4792. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4793. {
  4794. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4795. {
  4796. 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))
  4797. {
  4798. result = NO;
  4799. }
  4800. }
  4801. }
  4802. }
  4803. else
  4804. {
  4805. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4806. {
  4807. tempIndex = 2;
  4808. }
  4809. else
  4810. {
  4811. tempIndex = gun_index;
  4812. }
  4813. for (int index = 0; index < AC_QUANTITY; index++)
  4814. {
  4815. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4816. {
  4817. 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))
  4818. {
  4819. result = NO;
  4820. }
  4821. }
  4822. }// END
  4823. }
  4824. }
  4825. return result;
  4826. }
  4827. void CheckSystemValue(void)
  4828. {
  4829. char filenmae[100]={0};
  4830. char str[100]={0};
  4831. int tempIndex = 0;
  4832. //===============================
  4833. // send Heartbeat
  4834. //===============================
  4835. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4836. {
  4837. //parameter for test
  4838. sendHeartbeatRequest(0);
  4839. //===========================
  4840. // Reset Waiting Time
  4841. //===========================
  4842. HeartBeatWithNOResponse += 1;
  4843. }
  4844. //===============================
  4845. // Tcci credit deduct report
  4846. //===============================
  4847. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4848. {
  4849. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4850. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4851. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4852. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4853. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4854. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4855. }
  4856. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[0].DataTransferReq != TRUE) && getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4857. {
  4858. OCPP_query_deduct_info();
  4859. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4860. }
  4861. if(ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq)
  4862. {
  4863. OCPP_insert_occupancyDeduct_info((char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.occupancySN, (char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.creditNo,
  4864. ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.deductResult, ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.amount,
  4865. (char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.approvalNo);
  4866. ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq = FALSE;
  4867. }
  4868. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[0].DataTransferReq != TRUE) && getDiffSecNow(clientTime.TcciQueryOccupancyDeduct) > 5)
  4869. {
  4870. OCPP_query_occupancyDeduct_info();
  4871. refreshStartTimer(&clientTime.TcciQueryOccupancyDeduct);
  4872. }
  4873. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4874. {
  4875. // ClockAlign MeterValue
  4876. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4877. {
  4878. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4879. {
  4880. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4881. {
  4882. tempIndex = ((gun_index==2) ? 1: 0);
  4883. }
  4884. else
  4885. {
  4886. tempIndex = gun_index;
  4887. }
  4888. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4889. {
  4890. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4891. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4892. {
  4893. reqClockAlignMeter[gun_index] = 1;
  4894. }
  4895. }// End for CHAdeMO
  4896. }
  4897. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4898. {
  4899. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4900. {
  4901. tempIndex = ((gun_index==2) ? 1: 0);
  4902. }
  4903. else
  4904. {
  4905. tempIndex = gun_index;
  4906. }
  4907. for (int index = 0; index < CCS_QUANTITY; index++)
  4908. {
  4909. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4910. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4911. {
  4912. reqClockAlignMeter[gun_index] = 1;
  4913. }
  4914. } // End for CCS
  4915. }
  4916. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4917. {
  4918. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4919. {
  4920. tempIndex = ((gun_index==2) ? 1: 0);
  4921. }
  4922. else
  4923. {
  4924. tempIndex = gun_index;
  4925. }
  4926. for (int index = 0; index < GB_QUANTITY; index++)
  4927. {
  4928. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4929. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4930. {
  4931. reqClockAlignMeter[gun_index] = 1;
  4932. }
  4933. }// End for GB
  4934. }
  4935. else if(gunType[gun_index] == GUN_TYPE_DO)
  4936. {
  4937. tempIndex = gun_index;
  4938. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4939. {
  4940. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4941. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4942. {
  4943. reqClockAlignMeter[gun_index] = 1;
  4944. }
  4945. }
  4946. }
  4947. else
  4948. {
  4949. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4950. {
  4951. tempIndex = 2;
  4952. }
  4953. else
  4954. {
  4955. tempIndex = gun_index;
  4956. }
  4957. for (int index = 0; index < AC_QUANTITY; index++)
  4958. {
  4959. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4960. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4961. {
  4962. reqClockAlignMeter[gun_index] = 1;
  4963. }
  4964. }//End for AC
  4965. }
  4966. }
  4967. }
  4968. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4969. {
  4970. //==========================================
  4971. // Check remote start without connector id
  4972. //==========================================
  4973. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4974. {
  4975. int connectorIdInt = -1;
  4976. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4977. {
  4978. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4979. {
  4980. connectorIdInt = (gun_index+1);
  4981. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4982. checkRemoteStart(connectorIdInt);
  4983. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4984. break;
  4985. }
  4986. }
  4987. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4988. {
  4989. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4990. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4991. }
  4992. }
  4993. //==========================================
  4994. // csu trigger DataTransferReq
  4995. //==========================================
  4996. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4997. {
  4998. sendDataTransferRequest(gun_index);
  4999. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  5000. }
  5001. //==========================================
  5002. // CSU Trigger Authorize Request
  5003. //==========================================
  5004. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  5005. {
  5006. sendAuthorizeRequest(0);
  5007. authorizeRetryTimes = authorizeRetryTimes + 1;
  5008. if(authorizeRetryTimes < 3)
  5009. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5010. }
  5011. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  5012. {
  5013. authorizeRetryTimes = 0;
  5014. SetOcppConnStatus(FALSE);
  5015. server_sign = FALSE;
  5016. }
  5017. 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))
  5018. {
  5019. sendAuthorizeRequest(0);
  5020. }
  5021. //==========================================
  5022. // Charger start transaction
  5023. //==========================================
  5024. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  5025. {
  5026. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  5027. meterValueBufferClear(gun_index);
  5028. sendStartTransactionRequest(gun_index);
  5029. refreshStartTimer(&clientTime.StartTransaction);
  5030. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5031. storeTempStopTransaction(gun_index);
  5032. }
  5033. //==========================================
  5034. // Charger stop transaction
  5035. //==========================================
  5036. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  5037. {
  5038. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5039. sendStopTransactionRequest(gun_index);
  5040. OCPP_updatePeriodEnergy(gun_index);
  5041. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  5042. refreshStartTimer(&clientTime.StopTransaction);
  5043. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  5044. }
  5045. //==========================================
  5046. // Charger OCMF message
  5047. //==========================================
  5048. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq == 1)))
  5049. {
  5050. sendOcmfByDataTransferRequest(gun_index);
  5051. ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq = 0;
  5052. }
  5053. //==========================================
  5054. // Charger status report
  5055. //==========================================
  5056. //--- Check Mode Change ---//
  5057. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5058. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5059. {
  5060. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5061. {
  5062. tempIndex = ((gun_index==2) ? 1: 0);
  5063. }
  5064. else
  5065. {
  5066. tempIndex = gun_index;
  5067. }
  5068. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5069. {
  5070. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5071. {
  5072. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  5073. {
  5074. // Sent unplug message for California pricing logic
  5075. 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])
  5076. {
  5077. uint8_t ts[36];
  5078. getNowDatetime(ts);
  5079. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5080. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5081. if(strcmp((char*)dmsVersion, "2.0")==0)
  5082. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5083. else
  5084. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5085. sendUnplugByDataTransferRequest(gun_index);
  5086. interLock.isSentUnplug[gun_index] = 1;
  5087. }
  5088. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5089. {
  5090. interLock.isSentUnplug[gun_index] = 0;
  5091. }
  5092. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  5093. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  5094. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5095. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5096. {
  5097. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5098. if((access(filenmae,F_OK))!=-1)
  5099. {
  5100. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5101. sprintf(str,"rm -f %s",filenmae);
  5102. system(str);
  5103. }
  5104. }
  5105. }
  5106. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5107. #if 1 // for TempStopTransaction
  5108. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5109. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5110. {
  5111. checkTempStopTransaction(gun_index);
  5112. }
  5113. #endif
  5114. }
  5115. }
  5116. }
  5117. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5118. {
  5119. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5120. {
  5121. tempIndex = ((gun_index==2) ? 1: 0);
  5122. }
  5123. else
  5124. {
  5125. tempIndex = gun_index;
  5126. }
  5127. for (int index = 0; index < CCS_QUANTITY; index++)
  5128. {
  5129. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5130. {
  5131. 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]*/ )
  5132. {
  5133. // Sent unplug message for California pricing logic
  5134. 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])
  5135. {
  5136. uint8_t ts[36];
  5137. getNowDatetime(ts);
  5138. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5139. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5140. if(strcmp((char*)dmsVersion, "2.0")==0)
  5141. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5142. else
  5143. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5144. sendUnplugByDataTransferRequest(gun_index);
  5145. interLock.isSentUnplug[gun_index] = 1;
  5146. }
  5147. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5148. {
  5149. interLock.isSentUnplug[gun_index] = 0;
  5150. }
  5151. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  5152. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  5153. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5154. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5155. {
  5156. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5157. if((access(filenmae,F_OK))!=-1)
  5158. {
  5159. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5160. sprintf(str,"rm -f %s",filenmae);
  5161. system(str);
  5162. }
  5163. }
  5164. }
  5165. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5166. #if 1 // for TempStopTransaction
  5167. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5168. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5169. {
  5170. checkTempStopTransaction(gun_index);
  5171. }
  5172. #endif
  5173. }
  5174. }
  5175. }
  5176. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5177. {
  5178. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5179. {
  5180. tempIndex = ((gun_index==2) ? 1: 0);
  5181. }
  5182. else
  5183. {
  5184. tempIndex = gun_index;
  5185. }
  5186. for (int index = 0; index < GB_QUANTITY; index++)
  5187. {
  5188. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5189. {
  5190. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  5191. {
  5192. // Sent unplug message for California pricing logic
  5193. 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])
  5194. {
  5195. uint8_t ts[36];
  5196. getNowDatetime(ts);
  5197. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5198. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5199. if(strcmp((char*)dmsVersion, "2.0")==0)
  5200. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5201. else
  5202. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5203. sendUnplugByDataTransferRequest(gun_index);
  5204. interLock.isSentUnplug[gun_index] = 1;
  5205. }
  5206. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5207. {
  5208. interLock.isSentUnplug[gun_index] = 0;
  5209. }
  5210. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  5211. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  5212. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5213. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5214. {
  5215. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5216. if((access(filenmae,F_OK))!=-1)
  5217. {
  5218. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5219. sprintf(str,"rm -f %s",filenmae);
  5220. system(str);
  5221. }
  5222. }
  5223. }
  5224. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5225. #if 1 // for TempStopTransaction
  5226. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5227. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5228. {
  5229. checkTempStopTransaction(gun_index);
  5230. }
  5231. #endif
  5232. }
  5233. }
  5234. }
  5235. else if(gunType[gun_index] == GUN_TYPE_DO)
  5236. {
  5237. tempIndex = gun_index;
  5238. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5239. {
  5240. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5241. {
  5242. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  5243. {
  5244. // Sent unplug message for California pricing logic
  5245. 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])
  5246. {
  5247. uint8_t ts[36];
  5248. getNowDatetime(ts);
  5249. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5250. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5251. if(strcmp((char*)dmsVersion, "2.0")==0)
  5252. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5253. else
  5254. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5255. sendUnplugByDataTransferRequest(gun_index);
  5256. interLock.isSentUnplug[gun_index] = 1;
  5257. }
  5258. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  5259. {
  5260. interLock.isSentUnplug[gun_index] = 0;
  5261. }
  5262. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  5263. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  5264. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5265. 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
  5266. {
  5267. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5268. if((access(filenmae,F_OK))!=-1)
  5269. {
  5270. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5271. sprintf(str,"rm -f %s",filenmae);
  5272. system(str);
  5273. }
  5274. }
  5275. }
  5276. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5277. #if 1 // for TempStopTransaction
  5278. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  5279. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5280. {
  5281. checkTempStopTransaction(gun_index);
  5282. }
  5283. #endif
  5284. }
  5285. }
  5286. }
  5287. else
  5288. {
  5289. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5290. {
  5291. tempIndex = 2;
  5292. }
  5293. else
  5294. {
  5295. tempIndex = gun_index;
  5296. }
  5297. for (int index = 0; index < AC_QUANTITY; index++)
  5298. {
  5299. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5300. {
  5301. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  5302. {
  5303. // Sent unplug message for California pricing logic
  5304. 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])
  5305. {
  5306. uint8_t ts[36];
  5307. getNowDatetime(ts);
  5308. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5309. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5310. if(strcmp((char*)dmsVersion, "2.0")==0)
  5311. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5312. else
  5313. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5314. sendUnplugByDataTransferRequest(gun_index);
  5315. interLock.isSentUnplug[gun_index] = 1;
  5316. }
  5317. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5318. {
  5319. interLock.isSentUnplug[gun_index] = 0;
  5320. }
  5321. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  5322. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  5323. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5324. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5325. {
  5326. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5327. if((access(filenmae,F_OK))!=-1)
  5328. {
  5329. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5330. sprintf(str,"rm -f %s",filenmae);
  5331. system(str);
  5332. }
  5333. }
  5334. }
  5335. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5336. #if 1 // for TempStopTransaction
  5337. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5338. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5339. {
  5340. checkTempStopTransaction(gun_index);
  5341. }
  5342. #endif
  5343. }
  5344. }// END
  5345. }
  5346. if(isWebsocketSendable && (server_sign == TRUE) && (isConnector0Unavailable() != Connector0PreviousSystemStatus))
  5347. {
  5348. sendConnector0StatusNotificationRequest();
  5349. Connector0PreviousSystemStatus = isConnector0Unavailable();
  5350. }
  5351. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf != 1) &&
  5352. (
  5353. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  5354. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  5355. )
  5356. )
  5357. {
  5358. sendStatusNotificationRequest(gun_index);
  5359. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  5360. }
  5361. //==============================================
  5362. // TCCI related DataTransfer messages
  5363. //==============================================
  5364. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  5365. {
  5366. reportReaderStatus(gun_index);
  5367. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  5368. }
  5369. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].OccupancyFeeActReq == 1))
  5370. {
  5371. occupancyFeeAct(gun_index);
  5372. }
  5373. //==============================================
  5374. // CSU Trigger or timer timeout refresh Smart Charging Profile
  5375. //==============================================
  5376. if((ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  5377. ((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))))
  5378. {
  5379. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  5380. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  5381. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  5382. }
  5383. //==============================================
  5384. // Meter report
  5385. //==============================================
  5386. // Trigger MeterValue
  5387. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  5388. {
  5389. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  5390. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  5391. }
  5392. // Clock-aligned Meter value
  5393. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  5394. {
  5395. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  5396. reqClockAlignMeter[gun_index] = 0;
  5397. }
  5398. // Sample period MeterValue
  5399. 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))))
  5400. {
  5401. //check Transaction active
  5402. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5403. {
  5404. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5405. {
  5406. tempIndex = ((gun_index==2) ? 1: 0);
  5407. }
  5408. else
  5409. {
  5410. tempIndex = gun_index;
  5411. }
  5412. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5413. {
  5414. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5415. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5416. {
  5417. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5418. {
  5419. reqSampleMeter[gun_index] = 1;
  5420. }
  5421. }
  5422. }// End for CHAdeMO
  5423. }
  5424. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5425. {
  5426. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5427. {
  5428. tempIndex = ((gun_index==2) ? 1: 0);
  5429. }
  5430. else
  5431. {
  5432. tempIndex = gun_index;
  5433. }
  5434. for (int index = 0; index < CCS_QUANTITY; index++)
  5435. {
  5436. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5437. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5438. {
  5439. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5440. {
  5441. reqSampleMeter[gun_index] = 1;
  5442. }
  5443. }
  5444. } // End for CCS
  5445. }
  5446. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5447. {
  5448. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5449. {
  5450. tempIndex = ((gun_index==2) ? 1: 0);
  5451. }
  5452. else
  5453. {
  5454. tempIndex = gun_index;
  5455. }
  5456. for (int index = 0; index < GB_QUANTITY; index++)
  5457. {
  5458. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5459. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5460. {
  5461. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5462. {
  5463. reqSampleMeter[gun_index] = 1;
  5464. }
  5465. }
  5466. }// End for GB
  5467. }
  5468. else if(gunType[gun_index] == GUN_TYPE_DO)
  5469. {
  5470. tempIndex = gun_index;
  5471. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5472. {
  5473. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5474. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5475. {
  5476. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  5477. {
  5478. reqSampleMeter[gun_index] = 1;
  5479. }
  5480. }
  5481. }
  5482. }
  5483. else
  5484. {
  5485. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5486. {
  5487. tempIndex = 2;
  5488. }
  5489. else
  5490. {
  5491. tempIndex = gun_index;
  5492. }
  5493. for (int index = 0; index < AC_QUANTITY; index++)
  5494. {
  5495. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5496. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5497. {
  5498. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  5499. {
  5500. reqSampleMeter[gun_index] = 1;
  5501. }
  5502. }
  5503. }//End for AC
  5504. }
  5505. if(reqSampleMeter[gun_index] == 1)
  5506. {
  5507. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  5508. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  5509. storeTempStopTransaction(gun_index);
  5510. reqSampleMeter[gun_index] = 0;
  5511. }
  5512. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5513. }
  5514. //==============================================
  5515. // Check Connector reserved
  5516. //==============================================
  5517. //===============================
  5518. // Check if Reserve is expired
  5519. //===============================
  5520. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  5521. {
  5522. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  5523. {
  5524. DEBUG_INFO("reserve expired.\n");
  5525. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  5526. }
  5527. }//END OF Check if Reserve is expired
  5528. //==========================================
  5529. // csu trigger FirmwareStatusNotificationReq
  5530. //==========================================
  5531. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  5532. {
  5533. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  5534. }
  5535. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq == 1))
  5536. {
  5537. sendSignedFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status);
  5538. }
  5539. //==========================================
  5540. // csu trigger DiagnosticsStatusNotificationReq
  5541. //==========================================
  5542. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  5543. {
  5544. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  5545. }
  5546. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq == 1))
  5547. {
  5548. sendLogStatusNotificationRequest((char *)ShmOCPP16Data->LogStatusNotification.status);
  5549. }
  5550. //==========================================
  5551. // csu trigger CancelReservationConf
  5552. //==========================================
  5553. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  5554. {
  5555. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  5556. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  5557. }
  5558. //==========================================
  5559. // csu trigger ChangeAvailabilityConf
  5560. //==========================================
  5561. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  5562. {
  5563. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  5564. }
  5565. //==========================================
  5566. // csu trigger UnlockConnectorConf
  5567. //==========================================
  5568. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  5569. {
  5570. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5571. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5572. }
  5573. //==========================================
  5574. // csu trigger ReserveNowConf
  5575. //==========================================
  5576. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5577. {
  5578. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5579. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5580. }
  5581. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access(CSR_CP,F_OK) != -1))
  5582. {
  5583. sendSignCertificateRequest();
  5584. }
  5585. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq == 1))
  5586. {
  5587. sendSecurityEventNotificationRequest();
  5588. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5589. }
  5590. // Support 15118
  5591. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.SignCertificateReq == 1) && (access(CSR_V2G,F_OK) != -1))
  5592. {
  5593. json_object *data = json_object_new_object();
  5594. // Read csr file content
  5595. memset(ShmOCPP16Data->v2g_extend.SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5596. FILE *fp=fopen(CSR_V2G,"r");
  5597. char *line = NULL;
  5598. size_t len = 0;
  5599. while(getline(&line, &len, fp) != -1)
  5600. {
  5601. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5602. {
  5603. memcpy(&ShmOCPP16Data->v2g_extend.SignCertificate.csr[strlen((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr)], line, (strlen(line)-1));
  5604. }
  5605. }
  5606. fclose(fp);
  5607. json_object_object_add(data, "csr", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5608. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5609. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"SignCertificate");
  5610. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5611. json_object_put(data);
  5612. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5613. ShmOCPP16Data->v2g_extend.SignCertificateReq = 0;
  5614. }
  5615. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.AuthorizeReq == 1))
  5616. {
  5617. memset(&ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo,0,sizeof(struct IdTokenInfoType));
  5618. int parseCertResult = FAIL;
  5619. json_object *data = json_object_new_object();
  5620. json_object *idToken = json_object_new_object();
  5621. json_object *iso15118CertificateHashData = json_object_new_array();
  5622. // Read CERTIFICATE_PnCAuth file content
  5623. if(access(CERTIFICATE_PnCAuth,F_OK) != -1)
  5624. {
  5625. memset(ShmOCPP16Data->v2g_extend.Authorize.certificate, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5626. FILE *fp=fopen(CERTIFICATE_PnCAuth,"r");
  5627. char *line = NULL;
  5628. size_t len = 0;
  5629. while(getline(&line, &len, fp) != -1)
  5630. {
  5631. //memcpy(&ShmOCPP16Data->v2g_extend.Authorize.certificate[strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate)], line, (strlen(line)-1));
  5632. strcat((char *)ShmOCPP16Data->v2g_extend.Authorize.certificate, line);
  5633. }
  5634. fclose(fp);
  5635. }
  5636. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate) > 0)
  5637. json_object_object_add(data, "certificate", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5638. //strcpy((char *)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5639. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken));
  5640. json_object_object_add(data, "idToken", idToken);
  5641. char parseData[512] = {0};
  5642. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  5643. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].hashAlgorithm, parseData);
  5644. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_SerialNumber, parseData) == PASS)
  5645. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].serialNumber, parseData);
  5646. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  5647. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerNameHash, parseData);
  5648. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  5649. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerKeyHash, parseData);
  5650. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_OcspUrl, parseData) == PASS && strlen((char*)parseData) >= 7)
  5651. strcpy((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].responderURL, parseData);
  5652. for(int idx=0; idx < 4; idx++)
  5653. {
  5654. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm) > 0)
  5655. {
  5656. json_object *OCSPRequestDataType = json_object_new_object();
  5657. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm));
  5658. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerNameHash));
  5659. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerKeyHash));
  5660. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].serialNumber));
  5661. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].responderURL));
  5662. json_object_array_add(iso15118CertificateHashData, OCSPRequestDataType);
  5663. parseCertResult = PASS;
  5664. }
  5665. }
  5666. if(parseCertResult == PASS)
  5667. {
  5668. json_object_object_add(data, "iso15118CertificateHashData", iso15118CertificateHashData);
  5669. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5670. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Authorize");
  5671. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5672. json_object_put(data);
  5673. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5674. ShmOCPP16Data->v2g_extend.AuthorizeReq = 0;
  5675. }
  5676. else
  5677. {
  5678. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "NoCertificateAvailable");
  5679. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.status, "Invalid");
  5680. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  5681. }
  5682. }
  5683. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq == 1))
  5684. {
  5685. json_object *data = json_object_new_object();
  5686. json_object_object_add(data, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.iso15118SchemaVersion));
  5687. json_object_object_add(data, "action", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.action));
  5688. json_object_object_add(data, "exiRequest", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.exiRequest));
  5689. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5690. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Get15118EVCertificate");
  5691. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5692. json_object_put(data);
  5693. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5694. ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq = 0;
  5695. }
  5696. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.GetCertificateStatusReq == 1))
  5697. {
  5698. json_object *data = json_object_new_object();
  5699. json_object *OCSPRequestDataType = json_object_new_object();
  5700. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.hashAlgorithm));
  5701. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerNameHash));
  5702. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerKeyHash));
  5703. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.serialNumber));
  5704. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.responderURL));
  5705. json_object_object_add(data, "ocspRequestData", OCSPRequestDataType);
  5706. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5707. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"GetInstalledCertificateIds");
  5708. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5709. json_object_put(data);
  5710. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5711. ShmOCPP16Data->v2g_extend.GetCertificateStatusReq = 0;
  5712. }
  5713. }
  5714. }
  5715. //==========================================
  5716. // send request routine
  5717. //==========================================
  5718. int sendAuthorizeRequest(int gun_index)
  5719. {
  5720. mtrace();
  5721. int result = FAIL;
  5722. char message[100]={0};
  5723. char guid[37];
  5724. char tempdata[65]={0};
  5725. DEBUG_INFO("sendAuthorizeRequest...\n");
  5726. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5727. //Local Authorize
  5728. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5729. {
  5730. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5731. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5732. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5733. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5734. result = PASS;
  5735. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5736. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5737. authorizeRetryTimes = 0;
  5738. return result;
  5739. }
  5740. 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))||
  5741. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5742. {
  5743. // Query from cache
  5744. DEBUG_INFO("Authorize from cache.\n");
  5745. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5746. // Query from list
  5747. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strstr(idTagQuery.idTagstatus,"Accepted") == NULL) )
  5748. {
  5749. DEBUG_INFO("Authorize from list.\n");
  5750. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5751. }
  5752. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strstr(idTagQuery.idTagstatus,"Accepted") == NULL) )
  5753. {
  5754. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5755. {
  5756. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5757. }
  5758. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5759. {
  5760. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5761. }
  5762. if(!GetOcppConnStatus())
  5763. {
  5764. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5765. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5766. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5767. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5768. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5769. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5770. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5771. authorizeRetryTimes = 0;
  5772. return result;
  5773. }
  5774. }
  5775. else
  5776. {
  5777. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5778. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5779. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5780. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5781. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5782. else
  5783. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5784. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5785. result = PASS;
  5786. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5787. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5788. authorizeRetryTimes = 0;
  5789. return result;
  5790. }
  5791. }
  5792. //initialize struct Authorize
  5793. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5794. //get data from shared memory
  5795. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5796. random_uuid(guid);
  5797. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5798. LWS_Send(message);
  5799. sprintf(tempdata, "Authorize,%d", gun_index);
  5800. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5801. {
  5802. result = PASS;
  5803. DEBUG_INFO("Authorize mapItem pass\n");
  5804. }
  5805. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5806. return result;
  5807. }
  5808. int sendBootNotificationRequest(void)
  5809. {
  5810. mtrace();
  5811. int result = FAIL;
  5812. char message[500]={0}, payload[700]={0};
  5813. char guid[37]={0};
  5814. char tempdata[65]={0};
  5815. // Fill BootNotification fields
  5816. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5817. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5818. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5819. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5820. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5821. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5822. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5823. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5824. ShmOCPP16Data->ChargeBoxId
  5825. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5826. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5827. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5828. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5829. ,ShmOCPP16Data->BootNotification.CpIccid
  5830. ,ShmOCPP16Data->BootNotification.CpImsi);
  5831. random_uuid(guid);
  5832. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5833. LWS_Send(message);
  5834. sprintf(tempdata, "BootNotification,0");
  5835. 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*/)
  5836. {
  5837. result = PASS;
  5838. }
  5839. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5840. strcpy(queuedata,message);
  5841. return result;
  5842. }
  5843. int sendDataTransferRequest(int gun_index)
  5844. {
  5845. mtrace();
  5846. char message[10240]={0};
  5847. char guid[37]={0};
  5848. char tempdata[65]={0};
  5849. int result = FAIL;
  5850. json_object *DataTransfer = json_object_new_object();
  5851. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5852. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5853. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].Data));
  5854. random_uuid(guid);
  5855. sprintf(message,"[%d,\"%s\",\"DataTransfer\",%s]", MESSAGE_TYPE_CALL,
  5856. guid,
  5857. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5858. json_object_put(DataTransfer);
  5859. LWS_Send(message);
  5860. sprintf(tempdata, "DataTransfer,%d", gun_index);
  5861. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5862. {
  5863. result = PASS;
  5864. DEBUG_INFO("DataTransfer mapItem pass\n");
  5865. }
  5866. return result;
  5867. }
  5868. int sendUnplugByDataTransferRequest(int gun_index)
  5869. {
  5870. mtrace();
  5871. char message[10752]={0};
  5872. char guid[37]={0};
  5873. char tempdata[65]={0};
  5874. int result = FAIL;
  5875. random_uuid(guid);
  5876. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5877. (gun_index+1),
  5878. MESSAGE_TYPE_CALL,
  5879. guid,
  5880. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5881. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5882. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5883. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5884. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5885. {
  5886. result = PASS;
  5887. DEBUG_INFO("DataTransfer mapItem pass\n");
  5888. }
  5889. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5890. return result;
  5891. }
  5892. int sendOcmfByDataTransferRequest(int gun_index)
  5893. {
  5894. mtrace();
  5895. json_object *DataTransfer = json_object_new_object();
  5896. json_object *data = json_object_new_object();
  5897. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5898. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ID_OCMF");
  5899. json_object_object_add(data, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  5900. json_object_object_add(data, "dataString", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].DataString));
  5901. json_object_object_add(data, "publicKey", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].PublicKey));
  5902. json_object_object_add(DataTransfer, "data", data);
  5903. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5904. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5905. char message[3000]={0};
  5906. char guid[37]={0};
  5907. char tempdata[65]={0};
  5908. int result = FAIL;
  5909. random_uuid(guid);
  5910. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",%s]",
  5911. (gun_index+1),
  5912. MESSAGE_TYPE_CALL,
  5913. guid,
  5914. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5915. json_object_put(DataTransfer);
  5916. sprintf(tempdata, "DataTransfer,%d", gun_index );
  5917. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5918. {
  5919. result = PASS;
  5920. DEBUG_INFO("DataTransfer mapItem pass\n");
  5921. }
  5922. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5923. return result;
  5924. }
  5925. int sendDiagnosticsStatusNotificationRequest(char *status)
  5926. {
  5927. mtrace();
  5928. int result = FAIL;
  5929. char message[110]={0};
  5930. char guid[37]={0};
  5931. char tempdata[65]={0};
  5932. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5933. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5934. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5935. random_uuid(guid);
  5936. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5937. LWS_SendNow(message);
  5938. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5939. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5940. {
  5941. result = PASS;
  5942. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5943. }
  5944. //#ifdef SystemLogMessage
  5945. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5946. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5947. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5948. //#endif
  5949. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5950. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5951. //record status
  5952. if(strcmp(status,"Idle")==0)
  5953. {
  5954. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5955. }
  5956. else if(strcmp(status,"Uploaded")==0)
  5957. {
  5958. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5959. }
  5960. else if(strcmp(status,"UploadFailed")==0)
  5961. {
  5962. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5963. }
  5964. else if(strcmp(status,"Uploading")==0)
  5965. {
  5966. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5967. }
  5968. return result;
  5969. }
  5970. int sendFirmwareStatusNotificationRequest(char *status)
  5971. {
  5972. mtrace();
  5973. int result = FAIL;
  5974. char message[110]={0};
  5975. char guid[37]={0};
  5976. char tempdata[65]={0};
  5977. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5978. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5979. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5980. random_uuid(guid);
  5981. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5982. LWS_SendNow(message);
  5983. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5984. 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*/)
  5985. {
  5986. result = PASS;
  5987. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5988. }
  5989. //#ifdef SystemLogMessage
  5990. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5991. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5992. //#endif
  5993. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5994. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5995. //record status
  5996. if(strcmp(status,"Downloaded")==0)
  5997. {
  5998. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  5999. }
  6000. else if(strcmp(status,"DownloadFailed")==0)
  6001. {
  6002. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  6003. }
  6004. else if(strcmp(status,"Downloading")==0)
  6005. {
  6006. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  6007. }
  6008. else if(strcmp(status,"Idle")==0)
  6009. {
  6010. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  6011. }
  6012. else if(strcmp(status,"InstallationFailed")==0)
  6013. {
  6014. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  6015. }
  6016. else if(strcmp(status,"Installing")==0)
  6017. {
  6018. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  6019. }
  6020. else if(strcmp(status,"Installed")==0)
  6021. {
  6022. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  6023. }
  6024. return result;
  6025. }
  6026. int sendHeartbeatRequest(int gun_index)
  6027. {
  6028. mtrace();
  6029. int result = FAIL;
  6030. char message[80]={0};
  6031. char guid[37]={0};
  6032. char tempdata[65]={0};
  6033. random_uuid(guid);
  6034. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  6035. , MESSAGE_TYPE_CALL
  6036. , guid );
  6037. LWS_Send(message);
  6038. sprintf(tempdata, "Heartbeat,%d", 0);
  6039. 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*/)
  6040. {
  6041. result = PASS;
  6042. }
  6043. return result;
  6044. }
  6045. int sendStartTransactionRequest(int gun_index)
  6046. {
  6047. mtrace();
  6048. int result = FAIL;
  6049. char message[250]={0};
  6050. char guid[37]={0};
  6051. struct timeval tmnow;
  6052. struct tm *tm;
  6053. char buf[28];//, usec_buf[6];
  6054. char tempdata[65]={0};
  6055. int tempIndex = 0;
  6056. DEBUG_INFO("sendStartTransactionRequest...\n");
  6057. gettimeofday(&tmnow, NULL);
  6058. time_t t;
  6059. t = time(NULL);
  6060. /*UTC time and date*/
  6061. tm = gmtime(&t);
  6062. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6063. #if 0 // remove temporally
  6064. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  6065. strcat(buf,".");
  6066. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  6067. strcat(buf,usec_buf);
  6068. #endif
  6069. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  6070. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  6071. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  6072. // clear StartTransaction Response
  6073. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  6074. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  6075. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  6076. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  6077. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  6078. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6079. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6080. {
  6081. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6082. {
  6083. tempIndex = ((gun_index==2) ? 1: 0);
  6084. }
  6085. else
  6086. {
  6087. tempIndex = gun_index;
  6088. }
  6089. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6090. {
  6091. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6092. {
  6093. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6094. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  6095. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6096. }
  6097. }
  6098. }
  6099. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6100. {
  6101. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6102. {
  6103. tempIndex = ((gun_index==2) ? 1: 0);
  6104. }
  6105. else
  6106. {
  6107. tempIndex = gun_index;
  6108. }
  6109. for (int index = 0; index < CCS_QUANTITY; index++)
  6110. {
  6111. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6112. {
  6113. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6114. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  6115. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6116. }
  6117. }
  6118. }
  6119. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6120. {
  6121. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6122. {
  6123. tempIndex = ((gun_index==2) ? 1: 0);
  6124. }
  6125. else
  6126. {
  6127. tempIndex = gun_index;
  6128. }
  6129. for (int index = 0; index < GB_QUANTITY; index++)
  6130. {
  6131. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6132. {
  6133. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6134. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  6135. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6136. }
  6137. }
  6138. }
  6139. else if(gunType[gun_index] == GUN_TYPE_DO)
  6140. {
  6141. tempIndex = gun_index;
  6142. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6143. {
  6144. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6145. {
  6146. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6147. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  6148. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6149. }
  6150. }
  6151. }
  6152. else
  6153. {
  6154. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6155. {
  6156. tempIndex = 2;
  6157. }
  6158. else
  6159. {
  6160. tempIndex = gun_index;
  6161. }
  6162. for (int index = 0; index < AC_QUANTITY; index++)
  6163. {
  6164. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6165. {
  6166. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6167. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  6168. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6169. }
  6170. }
  6171. }
  6172. random_uuid(guid);
  6173. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  6174. {
  6175. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  6176. , gun_index +1
  6177. , MESSAGE_TYPE_CALL
  6178. , guid
  6179. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  6180. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  6181. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  6182. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  6183. }
  6184. else
  6185. {
  6186. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  6187. , gun_index +1
  6188. , MESSAGE_TYPE_CALL
  6189. , guid
  6190. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  6191. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  6192. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  6193. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  6194. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  6195. }
  6196. #if 1
  6197. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  6198. 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*/)
  6199. {
  6200. result = PASS;
  6201. }
  6202. #endif
  6203. strcpy(queuedata, message);
  6204. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6205. OCPP_insert_transaction_msg(YES, queuedata);
  6206. return result;
  6207. }
  6208. int sendConnector0StatusNotificationRequest()
  6209. {
  6210. mtrace();
  6211. int result = FAIL;
  6212. char message[600]={0};
  6213. char guid[37];
  6214. struct timeval tmnow;
  6215. struct tm *tm;
  6216. char buf[28];//, usec_buf[6];
  6217. char tempdata[65]={0};
  6218. DEBUG_INFO("sendConnector0StatusNotificationRequest...\n");
  6219. gettimeofday(&tmnow, NULL);
  6220. time_t t;
  6221. t = time(NULL);
  6222. /*UTC time and date*/
  6223. tm = gmtime(&t);
  6224. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6225. random_uuid(guid);
  6226. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":0,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6227. , MESSAGE_TYPE_CALL
  6228. , guid
  6229. , "NoError"
  6230. , ""
  6231. , (isConnector0Unavailable()==YES?"Unavailable":"Available")
  6232. , buf
  6233. , ShmSysConfigAndInfo->SysConfig.chargePointVendor
  6234. , "");
  6235. LWS_Send(message);
  6236. sprintf(tempdata, "StatusNotification,%d", 99);
  6237. 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*/)
  6238. {
  6239. //DEBUG_ERROR("statusNotification mapitem pass");
  6240. result = PASS;
  6241. }
  6242. return result;
  6243. }
  6244. int sendStatusNotificationRequest(int gun_index)
  6245. {
  6246. mtrace();
  6247. int result = FAIL;
  6248. char message[600]={0};
  6249. char guid[37];
  6250. int currentStatus = 0;
  6251. struct timeval tmnow;
  6252. struct tm *tm;
  6253. char buf[28];//, usec_buf[6];
  6254. char tempdata[65]={0};
  6255. int tempIndex = 0;
  6256. uint8_t isStateChanged = TRUE;
  6257. uint8_t isContentIllegal = TRUE;
  6258. DEBUG_INFO("sendStatusNotificationRequest...\n");
  6259. gettimeofday(&tmnow, NULL);
  6260. time_t t;
  6261. t = time(NULL);
  6262. /*UTC time and date*/
  6263. tm = gmtime(&t);
  6264. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6265. #if 0 // remove temporally
  6266. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  6267. strcat(buf,".");
  6268. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  6269. strcat(buf,usec_buf);
  6270. #endif
  6271. //printf("%s",buf);
  6272. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  6273. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  6274. // it's option
  6275. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  6276. /*
  6277. enum _SYSTEM_STATUS
  6278. {
  6279. S_BOOTING = 0,
  6280. S_IDLE, = 1
  6281. S_AUTHORIZING, =2
  6282. S_REASSIGN_CHECK, =3
  6283. S_REASSIGN, =4
  6284. S_PRECHARGE, =5
  6285. S_PREPARING_FOR_EV, =6
  6286. S_PREPARING_FOR_EVSE, =7
  6287. S_CHARGING, =8
  6288. S_TERMINATING, =9
  6289. S_COMPLETE, =10
  6290. S_ALARM, =11
  6291. S_FAULT =12
  6292. }
  6293. */
  6294. //check Transaction active
  6295. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6296. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6297. {
  6298. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6299. {
  6300. tempIndex = ((gun_index==2) ? 1: 0);
  6301. }
  6302. else
  6303. {
  6304. tempIndex = gun_index;
  6305. }
  6306. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6307. {
  6308. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  6309. {
  6310. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  6311. {
  6312. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6313. {
  6314. currentStatus = Preparing; //OCPP Status: Preparing
  6315. }
  6316. else
  6317. {
  6318. currentStatus = Available; //OCPP Status: Available
  6319. }
  6320. }
  6321. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6322. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6323. ) //S_PRECHARGE
  6324. {
  6325. currentStatus = Preparing; //OCPP Status: Preparing
  6326. }
  6327. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6328. {
  6329. currentStatus = Charging; //OCPP Status: Charging
  6330. }
  6331. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6332. {
  6333. currentStatus = Finishing; //OCPP Status: Finishing
  6334. }
  6335. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6336. {
  6337. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6338. }
  6339. 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
  6340. {
  6341. currentStatus = Unavailable; //OCPP Status: Unavailable
  6342. }
  6343. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6344. {
  6345. currentStatus = Faulted; //OCPP Status: Faulted
  6346. }
  6347. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6348. {
  6349. currentStatus = Reserved; //OCPP Status: Reserved
  6350. }
  6351. } //end of the same index
  6352. }//end of for CHAdeMO_QUANTITY
  6353. }
  6354. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6355. {
  6356. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6357. {
  6358. tempIndex = ((gun_index==2) ? 1: 0);
  6359. }
  6360. else
  6361. {
  6362. tempIndex = gun_index;
  6363. }
  6364. for (int index = 0; index < CCS_QUANTITY; index++)
  6365. {
  6366. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6367. {
  6368. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6369. {
  6370. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  6371. {
  6372. currentStatus = Preparing; //OCPP Status: Preparing
  6373. }
  6374. else
  6375. {
  6376. currentStatus = Available; //OCPP Status: Available
  6377. }
  6378. }
  6379. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6380. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6381. ) //S_PRECHARGE
  6382. {
  6383. currentStatus = Preparing; //OCPP Status: Preparing
  6384. }
  6385. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6386. {
  6387. currentStatus = Charging; //OCPP Status: Charging
  6388. }
  6389. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6390. {
  6391. currentStatus = Finishing; //OCPP Status: Finishing
  6392. }
  6393. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  6394. {
  6395. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6396. }
  6397. 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
  6398. {
  6399. currentStatus = Unavailable; //OCPP Status : Unavailable
  6400. }
  6401. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6402. {
  6403. currentStatus = Faulted; //OCPP Status: Faulted
  6404. }
  6405. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6406. {
  6407. currentStatus = Reserved; //OCPP Status: Reserved
  6408. }
  6409. } //end of the same index
  6410. } // end of for CCS_QUANTITY
  6411. }
  6412. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6413. {
  6414. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6415. {
  6416. tempIndex = ((gun_index==2) ? 1: 0);
  6417. }
  6418. else
  6419. {
  6420. tempIndex = gun_index;
  6421. }
  6422. for (int index = 0; index < GB_QUANTITY; index++)
  6423. {
  6424. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6425. {
  6426. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6427. {
  6428. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6429. {
  6430. currentStatus = Preparing; //OCPP Status: Preparing
  6431. }
  6432. else
  6433. {
  6434. currentStatus = Available; //OCPP Status: Available
  6435. }
  6436. }
  6437. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6438. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6439. ) //S_PRECHARGE
  6440. {
  6441. currentStatus = Preparing; //OCPP Status: Preparing
  6442. }
  6443. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6444. {
  6445. currentStatus = Charging; //OCPP Status: Charging
  6446. }
  6447. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6448. {
  6449. currentStatus = Finishing; //OCPP Status: Finishing
  6450. }
  6451. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6452. {
  6453. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6454. }
  6455. 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
  6456. {
  6457. currentStatus = Unavailable; //OCPP Status: Unavailable
  6458. }
  6459. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6460. {
  6461. currentStatus = Faulted; //OCPP Status: Faulted
  6462. }
  6463. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6464. {
  6465. currentStatus = Reserved; //OCPP Status: Reserved
  6466. }
  6467. } //end of the same index
  6468. } // end of for GB_QUANTITY
  6469. }
  6470. else if(gunType[gun_index] == GUN_TYPE_DO)
  6471. {
  6472. tempIndex = gun_index;
  6473. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6474. {
  6475. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6476. {
  6477. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6478. {
  6479. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6480. {
  6481. currentStatus = Preparing; //OCPP Status: Preparing
  6482. }
  6483. else
  6484. {
  6485. currentStatus = Available; //OCPP Status: Available
  6486. }
  6487. }
  6488. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6489. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6490. ) //S_PRECHARGE
  6491. {
  6492. currentStatus = Preparing; //OCPP Status: Preparing
  6493. }
  6494. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6495. {
  6496. currentStatus = Charging; //OCPP Status: Charging
  6497. }
  6498. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6499. {
  6500. currentStatus = Finishing; //OCPP Status: Finishing
  6501. }
  6502. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6503. {
  6504. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6505. }
  6506. 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
  6507. {
  6508. currentStatus = Unavailable; //OCPP Status: Unavailable
  6509. }
  6510. 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
  6511. {
  6512. currentStatus = Faulted; //OCPP Status: Faulted
  6513. }
  6514. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6515. {
  6516. currentStatus = Reserved; //OCPP Status: Reserved
  6517. }
  6518. } //end of the same index
  6519. }
  6520. }
  6521. else
  6522. {
  6523. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6524. {
  6525. tempIndex = 2;
  6526. }
  6527. else
  6528. {
  6529. tempIndex = gun_index;
  6530. }
  6531. for (int index = 0; index < AC_QUANTITY; index++)
  6532. {
  6533. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6534. {
  6535. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  6536. {
  6537. 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))
  6538. {
  6539. currentStatus = Preparing; //OCPP Status: Preparing
  6540. }
  6541. else
  6542. {
  6543. currentStatus = Available; //OCPP Status: Available
  6544. }
  6545. }
  6546. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  6547. {
  6548. currentStatus = Preparing; //OCPP Status: Preparing
  6549. }
  6550. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  6551. {
  6552. currentStatus = Charging; //OCPP Status: Charging
  6553. }
  6554. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  6555. {
  6556. currentStatus = Finishing; //OCPP Status: Finishing
  6557. }
  6558. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6559. {
  6560. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  6561. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6562. else
  6563. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  6564. }
  6565. 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
  6566. {
  6567. currentStatus = Unavailable; //OCPP Status: Unavailable
  6568. }
  6569. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6570. {
  6571. currentStatus = Faulted; //OCPP Status: Faulted
  6572. }
  6573. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6574. {
  6575. currentStatus = Reserved; //OCPP Status: Reserved
  6576. }
  6577. }//end of the same index
  6578. }//end of for AC_QUANTITY
  6579. }
  6580. //it's option
  6581. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  6582. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  6583. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  6584. {
  6585. isStateChanged = FALSE;
  6586. }
  6587. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6588. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  6589. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6590. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  6591. isContentIllegal = TRUE;
  6592. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  6593. {
  6594. if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  6595. {
  6596. isContentIllegal = FALSE;
  6597. break;
  6598. }
  6599. }
  6600. if(isContentIllegal)
  6601. {
  6602. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  6603. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  6604. }
  6605. random_uuid(guid);
  6606. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6607. , MESSAGE_TYPE_CALL
  6608. , guid
  6609. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  6610. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  6611. , ShmOCPP16Data->StatusNotification[gun_index].Info
  6612. , ShmOCPP16Data->StatusNotification[gun_index].Status
  6613. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  6614. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  6615. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  6616. if((server_sign == TRUE) && isStateChanged)
  6617. {
  6618. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6619. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6620. LWS_Send(message);
  6621. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  6622. 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*/)
  6623. {
  6624. //DEBUG_ERROR("statusNotification mapitem pass");
  6625. result = PASS;
  6626. }
  6627. }
  6628. else
  6629. {
  6630. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6631. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6632. result = PASS;
  6633. }
  6634. return result;
  6635. }
  6636. int sendStopTransactionRequest(int gun_index)
  6637. {
  6638. mtrace();
  6639. int result = FAIL;
  6640. //char message[1500]={0};
  6641. char guid[37]={0};
  6642. char tempdata[65]={0};
  6643. int tempIndex = 0;
  6644. char TempStopTransaction[256];
  6645. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  6646. DEBUG_INFO("sendStopTransactionRequest \n");
  6647. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6648. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  6649. //=========================== Stop Transaction Time ===============================================
  6650. getNowDatetime(ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  6651. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  6652. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  6653. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6654. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6655. {
  6656. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6657. {
  6658. tempIndex = ((gun_index==2) ? 1: 0);
  6659. }
  6660. else
  6661. {
  6662. tempIndex = gun_index;
  6663. }
  6664. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6665. {
  6666. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6667. {
  6668. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6669. }
  6670. }// END OF CHAdeMO_QUANTITY
  6671. }
  6672. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6673. {
  6674. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6675. {
  6676. tempIndex = ((gun_index==2) ? 1: 0);
  6677. }
  6678. else
  6679. {
  6680. tempIndex = gun_index;
  6681. }
  6682. for (int index = 0; index < CCS_QUANTITY; index++)
  6683. {
  6684. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6685. {
  6686. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6687. }
  6688. }// END OF CCS_QUANTITY
  6689. }
  6690. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6691. {
  6692. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6693. {
  6694. tempIndex = ((gun_index==2) ? 1: 0);
  6695. }
  6696. else
  6697. {
  6698. tempIndex = gun_index;
  6699. }
  6700. for (int index = 0; index < GB_QUANTITY; index++)
  6701. {
  6702. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6703. {
  6704. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6705. }
  6706. }// END OF GB_QUANTITY
  6707. }
  6708. else if(gunType[gun_index] == GUN_TYPE_DO)
  6709. {
  6710. tempIndex = gun_index;
  6711. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6712. {
  6713. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6714. {
  6715. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6716. }
  6717. }// END OF GB_QUANTITY
  6718. }
  6719. else
  6720. {
  6721. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6722. {
  6723. tempIndex = 2;
  6724. }
  6725. else
  6726. {
  6727. tempIndex = gun_index;
  6728. }
  6729. for (int index = 0; index < AC_QUANTITY; index++)
  6730. {
  6731. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6732. {
  6733. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6734. }
  6735. }// END OF AC_QUANTITY
  6736. }
  6737. //================================================ Message create ====================================================
  6738. json_object *StopTransaction = json_object_new_object();
  6739. json_object *transactionDatas = json_object_new_array();
  6740. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6741. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6742. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6743. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6744. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6745. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6746. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6747. meterValueBufferQuery(gun_index, transactionDatas);
  6748. if(json_object_array_length(transactionDatas) > 0) json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6749. random_uuid(guid);
  6750. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6751. ,MESSAGE_TYPE_CALL
  6752. ,guid
  6753. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6754. json_object_put(StopTransaction);
  6755. #if 1 // for TempStopTransaction
  6756. //Delete TempStopTransaction
  6757. if((access(TempStopTransaction,F_OK))!=-1)
  6758. {
  6759. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6760. }
  6761. #endif
  6762. #if 1
  6763. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6764. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6765. {
  6766. result = PASS;
  6767. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6768. }
  6769. #endif
  6770. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6771. OCPP_insert_transaction_msg(NO, queuedata);
  6772. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6773. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6774. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6775. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6776. {
  6777. //SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6778. }
  6779. //for test
  6780. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6781. return result;
  6782. }
  6783. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6784. {
  6785. mtrace();
  6786. int result = FAIL;
  6787. char guid[37]={0};
  6788. char tempdata[65]={0};
  6789. int tempIndex = 0;
  6790. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6791. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6792. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6793. //set value
  6794. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6795. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6796. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6797. -1);
  6798. random_uuid(guid);
  6799. //UTC Date time
  6800. struct timeval tmnow;
  6801. struct tm *tm;
  6802. char buf[28];//, usec_buf[6];
  6803. gettimeofday(&tmnow, NULL);
  6804. time_t t;
  6805. t = time(NULL);
  6806. /*UTC time and date*/
  6807. tm = gmtime(&t);
  6808. if(dataType == ReadingContext_Sample_Clock)
  6809. {
  6810. struct tm *tmTarget;
  6811. struct timeb tbTarget;
  6812. tbTarget.time = mktime(tm);
  6813. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6814. tmTarget = gmtime(&tbTarget.time);
  6815. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6816. }
  6817. else
  6818. {
  6819. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6820. }
  6821. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6822. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6823. //********************************(1)Current.Import L1************************************************/
  6824. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6825. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6826. (dataType == ReadingContext_Trigger))
  6827. {
  6828. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6829. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6830. {
  6831. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6832. {
  6833. tempIndex = ((gun_index==2) ? 1: 0);
  6834. }
  6835. else
  6836. {
  6837. tempIndex = gun_index;
  6838. }
  6839. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6840. {
  6841. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6842. {
  6843. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6844. }
  6845. }
  6846. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6847. }
  6848. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6849. {
  6850. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6851. {
  6852. tempIndex = ((gun_index==2) ? 1: 0);
  6853. }
  6854. else
  6855. {
  6856. tempIndex = gun_index;
  6857. }
  6858. for (int index = 0; index < CCS_QUANTITY; index++)
  6859. {
  6860. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6861. {
  6862. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6863. }
  6864. }
  6865. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6866. }
  6867. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6868. {
  6869. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6870. {
  6871. tempIndex = ((gun_index==2) ? 1: 0);
  6872. }
  6873. else
  6874. {
  6875. tempIndex = gun_index;
  6876. }
  6877. for (int index = 0; index < GB_QUANTITY; index++)
  6878. {
  6879. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6880. {
  6881. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6882. }
  6883. }
  6884. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6885. }
  6886. else if(gunType[gun_index] == GUN_TYPE_DO)
  6887. {
  6888. tempIndex = gun_index;
  6889. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6890. {
  6891. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6892. {
  6893. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6894. }
  6895. }
  6896. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6897. }
  6898. else
  6899. {
  6900. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6901. {
  6902. tempIndex = 2;
  6903. }
  6904. else
  6905. {
  6906. tempIndex = gun_index;
  6907. }
  6908. for (int index = 0; index < AC_QUANTITY; index++)
  6909. {
  6910. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6911. {
  6912. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6913. }
  6914. }
  6915. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6916. }
  6917. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6918. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6919. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6920. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6921. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6922. }
  6923. //********************************(2)Energy.Active.Import.Register ************************************************/
  6924. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6925. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6926. (dataType == ReadingContext_Trigger))
  6927. {
  6928. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6929. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6930. {
  6931. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6932. {
  6933. tempIndex = ((gun_index==2) ? 1: 0);
  6934. }
  6935. else
  6936. {
  6937. tempIndex = gun_index;
  6938. }
  6939. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6940. {
  6941. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6942. {
  6943. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6944. }
  6945. }
  6946. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6947. }
  6948. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6949. {
  6950. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6951. {
  6952. tempIndex = ((gun_index==2) ? 1: 0);
  6953. }
  6954. else
  6955. {
  6956. tempIndex = gun_index;
  6957. }
  6958. for (int index = 0; index < CCS_QUANTITY; index++)
  6959. {
  6960. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6961. {
  6962. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6963. }
  6964. }
  6965. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6966. }
  6967. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6968. {
  6969. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6970. {
  6971. tempIndex = ((gun_index==2) ? 1: 0);
  6972. }
  6973. else
  6974. {
  6975. tempIndex = gun_index;
  6976. }
  6977. for (int index = 0; index < GB_QUANTITY; index++)
  6978. {
  6979. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6980. {
  6981. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6982. }
  6983. }
  6984. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6985. }
  6986. else if(gunType[gun_index] == GUN_TYPE_DO)
  6987. {
  6988. tempIndex = gun_index;
  6989. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6990. {
  6991. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6992. {
  6993. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6994. }
  6995. }
  6996. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6997. }
  6998. else
  6999. {
  7000. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7001. {
  7002. tempIndex = 2;
  7003. }
  7004. else
  7005. {
  7006. tempIndex = gun_index;
  7007. }
  7008. for (int index = 0; index < AC_QUANTITY; index++)
  7009. {
  7010. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7011. {
  7012. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  7013. }
  7014. }
  7015. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  7016. }
  7017. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  7018. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  7019. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  7020. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  7021. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7022. }
  7023. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  7024. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7025. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7026. (dataType == ReadingContext_Trigger))
  7027. {
  7028. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7029. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7030. {
  7031. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7032. {
  7033. tempIndex = ((gun_index==2) ? 1: 0);
  7034. }
  7035. else
  7036. {
  7037. tempIndex = gun_index;
  7038. }
  7039. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7040. {
  7041. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7042. {
  7043. if(dataType == ReadingContext_Sample_Clock)
  7044. {
  7045. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7046. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7047. }
  7048. else if(dataType == ReadingContext_Sample_Periodic)
  7049. {
  7050. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7051. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7052. }
  7053. else
  7054. {
  7055. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7056. }
  7057. }
  7058. } // END OF FOR CHAdeMO_QUANTITY
  7059. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7060. }
  7061. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7062. {
  7063. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7064. {
  7065. tempIndex = ((gun_index==2) ? 1: 0);
  7066. }
  7067. else
  7068. {
  7069. tempIndex = gun_index;
  7070. }
  7071. for (int index = 0; index < CCS_QUANTITY; index++)
  7072. {
  7073. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7074. {
  7075. if(dataType == ReadingContext_Sample_Clock)
  7076. {
  7077. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7078. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7079. }
  7080. else if(dataType == ReadingContext_Sample_Periodic)
  7081. {
  7082. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7083. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7084. }
  7085. else
  7086. {
  7087. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7088. }
  7089. }
  7090. } // END OF CCS_QUANTITY
  7091. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7092. }
  7093. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7094. {
  7095. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7096. {
  7097. tempIndex = ((gun_index==2) ? 1: 0);
  7098. }
  7099. else
  7100. {
  7101. tempIndex = gun_index;
  7102. }
  7103. for (int index = 0; index < GB_QUANTITY; index++)
  7104. {
  7105. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7106. {
  7107. if(dataType == ReadingContext_Sample_Clock)
  7108. {
  7109. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7110. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7111. }
  7112. else if(dataType == ReadingContext_Sample_Periodic)
  7113. {
  7114. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7115. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7116. }
  7117. else
  7118. {
  7119. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7120. }
  7121. }
  7122. } // END OF GB_QUANTITY
  7123. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7124. }
  7125. else if(gunType[gun_index] == GUN_TYPE_DO)
  7126. {
  7127. tempIndex = gun_index;
  7128. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7129. {
  7130. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7131. {
  7132. if(dataType == ReadingContext_Sample_Clock)
  7133. {
  7134. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7135. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7136. }
  7137. else if(dataType == ReadingContext_Sample_Periodic)
  7138. {
  7139. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7140. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7141. }
  7142. else
  7143. {
  7144. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7145. }
  7146. }
  7147. }
  7148. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7149. }
  7150. else
  7151. {
  7152. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7153. {
  7154. tempIndex = 2;
  7155. }
  7156. else
  7157. {
  7158. tempIndex = gun_index;
  7159. }
  7160. for (int index = 0; index < AC_QUANTITY; index++)
  7161. {
  7162. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7163. {
  7164. if(dataType == ReadingContext_Sample_Clock)
  7165. {
  7166. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7167. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7168. }
  7169. else if(dataType == ReadingContext_Sample_Periodic)
  7170. {
  7171. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7172. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7173. }
  7174. else
  7175. {
  7176. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7177. }
  7178. }
  7179. }
  7180. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7181. }
  7182. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7183. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7184. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7185. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7186. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7187. }
  7188. //********************************(4)Power.Active.Import************************************************/
  7189. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7190. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7191. (dataType == ReadingContext_Trigger))
  7192. {
  7193. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7194. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7195. {
  7196. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7197. {
  7198. tempIndex = ((gun_index==2) ? 1: 0);
  7199. }
  7200. else
  7201. {
  7202. tempIndex = gun_index;
  7203. }
  7204. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7205. {
  7206. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7207. {
  7208. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7209. }
  7210. } // END OF FOR
  7211. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7212. }
  7213. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7214. {
  7215. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7216. {
  7217. tempIndex = ((gun_index==2) ? 1: 0);
  7218. }
  7219. else
  7220. {
  7221. tempIndex = gun_index;
  7222. }
  7223. for (int index = 0; index < CCS_QUANTITY; index++)
  7224. {
  7225. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7226. {
  7227. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7228. }
  7229. }
  7230. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7231. }
  7232. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7233. {
  7234. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7235. {
  7236. tempIndex = ((gun_index==2) ? 1: 0);
  7237. }
  7238. else
  7239. {
  7240. tempIndex = gun_index;
  7241. }
  7242. for (int index = 0; index < GB_QUANTITY; index++)
  7243. {
  7244. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7245. {
  7246. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7247. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7248. }
  7249. }
  7250. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7251. }
  7252. else if(gunType[gun_index] == GUN_TYPE_DO)
  7253. {
  7254. tempIndex = gun_index;
  7255. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7256. {
  7257. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7258. {
  7259. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7260. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7261. }
  7262. }
  7263. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7264. }
  7265. else
  7266. {
  7267. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7268. {
  7269. tempIndex = 2;
  7270. }
  7271. else
  7272. {
  7273. tempIndex = gun_index;
  7274. }
  7275. for (int index = 0; index < AC_QUANTITY; index++)
  7276. {
  7277. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7278. {
  7279. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7280. }
  7281. }
  7282. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7283. }
  7284. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7285. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7286. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7287. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7288. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7289. }
  7290. //***********************************************(5)VOLTAGE L1******************************************************/
  7291. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7292. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7293. (dataType == ReadingContext_Trigger))
  7294. {
  7295. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7296. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7297. {
  7298. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7299. {
  7300. tempIndex = ((gun_index==2) ? 1: 0);
  7301. }
  7302. else
  7303. {
  7304. tempIndex = gun_index;
  7305. }
  7306. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7307. {
  7308. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7309. {
  7310. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7311. }
  7312. }
  7313. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7314. }
  7315. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7316. {
  7317. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7318. {
  7319. tempIndex = ((gun_index==2) ? 1: 0);
  7320. }
  7321. else
  7322. {
  7323. tempIndex = gun_index;
  7324. }
  7325. for (int index = 0; index < CCS_QUANTITY; index++)
  7326. {
  7327. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7328. {
  7329. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7330. }
  7331. }
  7332. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7333. }
  7334. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7335. {
  7336. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7337. {
  7338. tempIndex = ((gun_index==2) ? 1: 0);
  7339. }
  7340. else
  7341. {
  7342. tempIndex = gun_index;
  7343. }
  7344. for (int index = 0; index < GB_QUANTITY; index++)
  7345. {
  7346. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7347. {
  7348. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7349. }
  7350. }
  7351. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7352. }
  7353. else if(gunType[gun_index] == GUN_TYPE_DO)
  7354. {
  7355. tempIndex = gun_index;
  7356. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7357. {
  7358. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7359. {
  7360. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7361. }
  7362. }
  7363. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7364. }
  7365. else
  7366. {
  7367. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7368. {
  7369. tempIndex = 2;
  7370. }
  7371. else
  7372. {
  7373. tempIndex = gun_index;
  7374. }
  7375. for (int index = 0; index < AC_QUANTITY; index++)
  7376. {
  7377. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7378. {
  7379. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7380. }
  7381. }
  7382. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7383. }
  7384. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7385. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7386. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7387. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7388. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7389. }
  7390. //***********************************************(6)SOC******************************************************/
  7391. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7392. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7393. (dataType == ReadingContext_Trigger))
  7394. {
  7395. 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))
  7396. {
  7397. //idx_sample=5;
  7398. //sampledValue = NULL;
  7399. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7400. {
  7401. tempIndex = ((gun_index==2) ? 1: 0);
  7402. }
  7403. else
  7404. {
  7405. tempIndex = gun_index;
  7406. }
  7407. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7408. {
  7409. //tempIndex = ((gun_index==2) ? 1: 0);
  7410. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7411. {
  7412. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7413. {
  7414. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7415. }
  7416. }
  7417. }
  7418. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7419. {
  7420. //tempIndex = ((gun_index==2) ? 1: 0);
  7421. for (int index = 0; index < CCS_QUANTITY; index++)
  7422. {
  7423. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7424. {
  7425. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7426. }
  7427. }
  7428. }
  7429. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7430. {
  7431. //tempIndex = ((gun_index==2) ? 1: 0);
  7432. for (int index = 0; index < GB_QUANTITY; index++)
  7433. {
  7434. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7435. {
  7436. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7437. }
  7438. }
  7439. }
  7440. else if(gunType[gun_index] == GUN_TYPE_DO)
  7441. {
  7442. //tempIndex = ((gun_index==2) ? 1: 0);
  7443. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7444. {
  7445. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7446. {
  7447. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7448. }
  7449. }
  7450. }
  7451. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7452. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7453. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7454. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7455. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7456. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7457. }
  7458. }
  7459. //********************************(7)Current.Import L2************************************************/
  7460. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7461. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7462. (dataType == ReadingContext_Trigger))
  7463. {
  7464. // Only for AC 3 phase
  7465. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7466. {
  7467. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7468. {
  7469. tempIndex = 2;
  7470. }
  7471. else
  7472. {
  7473. tempIndex = gun_index;
  7474. }
  7475. for (int index = 0; index < AC_QUANTITY; index++)
  7476. {
  7477. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7478. {
  7479. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7480. }
  7481. }
  7482. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7483. }
  7484. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7486. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7487. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7488. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7489. }
  7490. //********************************(8)Current.Import L3************************************************/
  7491. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7492. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7493. (dataType == ReadingContext_Trigger))
  7494. {
  7495. // Only for AC 3 phase
  7496. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7497. {
  7498. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7499. {
  7500. tempIndex = 2;
  7501. }
  7502. else
  7503. {
  7504. tempIndex = gun_index;
  7505. }
  7506. for (int index = 0; index < AC_QUANTITY; index++)
  7507. {
  7508. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7509. {
  7510. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7511. }
  7512. }
  7513. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7514. }
  7515. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7516. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7517. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7518. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7519. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7520. }
  7521. //***********************************************(9)VOLTAGE L2******************************************************/
  7522. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7523. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7524. (dataType == ReadingContext_Trigger))
  7525. {
  7526. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7527. {
  7528. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7529. {
  7530. tempIndex = 2;
  7531. }
  7532. else
  7533. {
  7534. tempIndex = gun_index;
  7535. }
  7536. for (int index = 0; index < AC_QUANTITY; index++)
  7537. {
  7538. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7539. {
  7540. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7541. }
  7542. }
  7543. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7544. }
  7545. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7546. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7547. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7548. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7550. }
  7551. //***********************************************(10)VOLTAGE L3******************************************************/
  7552. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7553. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7554. (dataType == ReadingContext_Trigger))
  7555. {
  7556. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7557. {
  7558. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7559. {
  7560. tempIndex = 2;
  7561. }
  7562. else
  7563. {
  7564. tempIndex = gun_index;
  7565. }
  7566. for (int index = 0; index < AC_QUANTITY; index++)
  7567. {
  7568. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7569. {
  7570. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7571. }
  7572. }
  7573. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7574. }
  7575. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7576. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7577. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7579. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7580. }
  7581. //***********************************************(11)Current.Offered******************************************************/
  7582. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7583. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7584. (dataType == ReadingContext_Trigger))
  7585. {
  7586. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7587. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7588. {
  7589. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7590. {
  7591. tempIndex = ((gun_index==2) ? 1: 0);
  7592. }
  7593. else
  7594. {
  7595. tempIndex = gun_index;
  7596. }
  7597. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7598. {
  7599. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7600. {
  7601. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7602. }
  7603. } // END OF FOR CHAdeMO_QUANTITY
  7604. }
  7605. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7606. {
  7607. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7608. {
  7609. tempIndex = ((gun_index==2) ? 1: 0);
  7610. }
  7611. else
  7612. {
  7613. tempIndex = gun_index;
  7614. }
  7615. for (int index = 0; index < CCS_QUANTITY; index++)
  7616. {
  7617. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7618. {
  7619. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7620. }
  7621. } // END OF CCS_QUANTITY
  7622. }
  7623. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7624. {
  7625. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7626. {
  7627. tempIndex = ((gun_index==2) ? 1: 0);
  7628. }
  7629. else
  7630. {
  7631. tempIndex = gun_index;
  7632. }
  7633. for (int index = 0; index < GB_QUANTITY; index++)
  7634. {
  7635. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7636. {
  7637. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7638. }
  7639. } // END OF GB_QUANTITY
  7640. }
  7641. else if(gunType[gun_index] == GUN_TYPE_DO)
  7642. {
  7643. tempIndex = gun_index;
  7644. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7645. {
  7646. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7647. {
  7648. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7649. }
  7650. }
  7651. }
  7652. else
  7653. {
  7654. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7655. {
  7656. tempIndex = 2;
  7657. }
  7658. else
  7659. {
  7660. tempIndex = gun_index;
  7661. }
  7662. for (int index = 0; index < AC_QUANTITY; index++)
  7663. {
  7664. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7665. {
  7666. uint16_t currentOffer;
  7667. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7668. {
  7669. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7670. }
  7671. else
  7672. {
  7673. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7674. }
  7675. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7676. }
  7677. }
  7678. }
  7679. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7680. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7681. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7682. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7683. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7684. }
  7685. //***********************************************(12)Power.Offered******************************************************/
  7686. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7687. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7688. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7689. {
  7690. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7691. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7692. {
  7693. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7694. {
  7695. tempIndex = ((gun_index==2) ? 1: 0);
  7696. }
  7697. else
  7698. {
  7699. tempIndex = gun_index;
  7700. }
  7701. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7702. {
  7703. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7704. {
  7705. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7706. }
  7707. } // END OF FOR CHAdeMO_QUANTITY
  7708. }
  7709. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7710. {
  7711. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7712. {
  7713. tempIndex = ((gun_index==2) ? 1: 0);
  7714. }
  7715. else
  7716. {
  7717. tempIndex = gun_index;
  7718. }
  7719. for (int index = 0; index < CCS_QUANTITY; index++)
  7720. {
  7721. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7722. {
  7723. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7724. }
  7725. } // END OF CCS_QUANTITY
  7726. }
  7727. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7728. {
  7729. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7730. {
  7731. tempIndex = ((gun_index==2) ? 1: 0);
  7732. }
  7733. else
  7734. {
  7735. tempIndex = gun_index;
  7736. }
  7737. for (int index = 0; index < GB_QUANTITY; index++)
  7738. {
  7739. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7740. {
  7741. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7742. }
  7743. } // END OF GB_QUANTITY
  7744. }
  7745. else if(gunType[gun_index] == GUN_TYPE_DO)
  7746. {
  7747. tempIndex = gun_index;
  7748. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7749. {
  7750. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7751. {
  7752. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7753. }
  7754. }
  7755. }
  7756. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7757. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7758. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7759. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7760. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7761. }
  7762. // Message create ====================================================================================================
  7763. if(TRUE)
  7764. {
  7765. json_object *MeterValueReq = json_object_new_object();
  7766. json_object *MeterValues = json_object_new_array();
  7767. json_object *sampledValues = json_object_new_array();
  7768. json_object *sampledValuesBuffer = json_object_new_array();
  7769. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7770. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7771. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7772. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7773. {
  7774. json_object *MeterValue = json_object_new_object();
  7775. json_object *MeterValueBuffer = json_object_new_object();
  7776. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7777. {
  7778. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7779. {
  7780. json_object *sampledValue = json_object_new_object();
  7781. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7782. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7783. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7784. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7785. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7786. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7787. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7788. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7789. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7790. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7791. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7792. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7793. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7794. json_object_array_add(sampledValues, sampledValue);
  7795. // For StopTxn data
  7796. 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)) ||
  7797. ((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)))
  7798. {
  7799. json_object *sampledValue = json_object_new_object();
  7800. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7801. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7802. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7803. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7804. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7805. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7806. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7807. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7808. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7809. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7810. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7811. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7812. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7813. json_object_array_add(sampledValuesBuffer, sampledValue);
  7814. }
  7815. }
  7816. }
  7817. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7818. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7819. json_object_array_add(MeterValues, MeterValue);
  7820. // For StopTxn data
  7821. if((dataType != ReadingContext_Trigger) &&
  7822. (json_object_array_length(sampledValuesBuffer) > 0))
  7823. {
  7824. json_object_object_add(MeterValueBuffer, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7825. json_object_object_add(MeterValueBuffer, "sampledValue", sampledValuesBuffer);
  7826. 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));
  7827. json_object_put(MeterValueBuffer);
  7828. }
  7829. else
  7830. {
  7831. json_object_put(sampledValuesBuffer);
  7832. json_object_put(MeterValueBuffer);
  7833. }
  7834. }
  7835. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7836. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7837. ,gun_index + 1
  7838. ,MESSAGE_TYPE_CALL
  7839. ,guid
  7840. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7841. json_object_put(MeterValueReq);
  7842. }
  7843. // Put request guid to hash map
  7844. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7845. 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*/)
  7846. {
  7847. result = PASS;
  7848. //DEBUG_INFO("MeterValues mapitem pass\n");
  7849. }
  7850. if((dataType != ReadingContext_Trigger) &&
  7851. (dataType != ReadingContext_Sample_Clock) &&
  7852. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7853. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7854. else
  7855. {
  7856. if(FirstHeartBeat)
  7857. LWS_Send(queuedata +2);
  7858. }
  7859. return result;
  7860. }
  7861. int sendLogStatusNotificationRequest(char *status)
  7862. {
  7863. mtrace();
  7864. int result = PASS;
  7865. char message[4096]={0};
  7866. char guid[37]={0};
  7867. char tempdata[128]={0};
  7868. json_object *LogStatusNotification = json_object_new_object();
  7869. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7870. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7871. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7872. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7873. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7874. random_uuid(guid);
  7875. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7876. json_object_put(LogStatusNotification);
  7877. LWS_Send(message);
  7878. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7879. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7880. {
  7881. result = PASS;
  7882. }
  7883. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7884. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7885. return result;
  7886. }
  7887. int sendSecurityEventNotificationRequest()
  7888. {
  7889. mtrace();
  7890. int result = PASS;
  7891. char message[4096]={0};
  7892. char guid[37]={0};
  7893. char tempdata[128]={0};
  7894. json_object *SecurityEventNotification = json_object_new_object();
  7895. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7896. //Stop Transaction Time
  7897. struct timeval tmnow;
  7898. struct tm *tm;
  7899. gettimeofday(&tmnow, NULL);
  7900. time_t t;
  7901. t = time(NULL);
  7902. /*UTC time and date*/
  7903. tm = gmtime(&t);
  7904. strftime((char *)ShmOCPP16Data->SecurityEventNotification.timestamp, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.timestamp), "%Y-%m-%dT%H:%M:%SZ", tm);
  7905. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7906. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7907. if(strlen((char*)ShmOCPP16Data->SecurityEventNotification.techInfo) > 0)
  7908. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7909. random_uuid(guid);
  7910. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7911. json_object_put(SecurityEventNotification);
  7912. LWS_Send(message);
  7913. sprintf(tempdata, "SecurityEventNotification,0");
  7914. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7915. {
  7916. result = PASS;
  7917. }
  7918. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7919. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7920. return result;
  7921. }
  7922. int sendSignCertificateRequest()
  7923. {
  7924. mtrace();
  7925. int result = PASS;
  7926. char message[4096]={0};
  7927. char guid[37]={0};
  7928. char tempdata[128]={0};
  7929. json_object *SignCertificate = json_object_new_object();
  7930. DEBUG_INFO("sendSignCertificateRequest...\n");
  7931. // Read csr file content
  7932. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7933. FILE *fp=fopen(CSR_CP,"r");
  7934. char *line = NULL;
  7935. size_t len = 0;
  7936. while(getline(&line, &len, fp) != -1)
  7937. {
  7938. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7939. {
  7940. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7941. }
  7942. }
  7943. fclose(fp);
  7944. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7945. random_uuid(guid);
  7946. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7947. json_object_put(SignCertificate);
  7948. LWS_Send(message);
  7949. sprintf(tempdata, "SignCertificate,0");
  7950. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7951. {
  7952. result = PASS;
  7953. }
  7954. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7955. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7956. return result;
  7957. }
  7958. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7959. {
  7960. mtrace();
  7961. int result = PASS;
  7962. char message[4096]={0};
  7963. char guid[37]={0};
  7964. char tempdata[128]={0};
  7965. json_object *SignedFirmwareStatusNotification = json_object_new_object();
  7966. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7967. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7968. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7969. json_object_object_add(SignedFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7970. json_object_object_add(SignedFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7971. random_uuid(guid);
  7972. sprintf(message,"[%d,\"%s\",\"SignedFirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(SignedFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7973. json_object_put(SignedFirmwareStatusNotification);
  7974. LWS_Send(message);
  7975. sprintf(tempdata, "SignedFirmwareStatusNotification,%d", 0);
  7976. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7977. {
  7978. result = PASS;
  7979. }
  7980. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7981. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7982. return result;
  7983. }
  7984. //==========================================
  7985. // send confirm routine
  7986. //==========================================
  7987. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7988. {
  7989. mtrace();
  7990. int result = FAIL;
  7991. char message[100]={0};
  7992. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7993. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7994. LWS_Send(message);
  7995. result = TRUE;
  7996. return result;
  7997. }
  7998. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7999. {
  8000. mtrace();
  8001. int result = FAIL;
  8002. char message[100]={0};
  8003. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  8004. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8005. LWS_Send(message);
  8006. result = TRUE;
  8007. return result;
  8008. }
  8009. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  8010. {
  8011. mtrace();
  8012. int result = FAIL;
  8013. char message[100]={0};
  8014. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  8015. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8016. LWS_Send(message);
  8017. result = TRUE;
  8018. return result;
  8019. }
  8020. int sendClearCacheConfirmation(char *uuid,char *payload)
  8021. {
  8022. mtrace();
  8023. int result = FAIL;
  8024. char message[500]={0};
  8025. DEBUG_INFO("sendClearCacheConfirmation...\n");
  8026. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8027. LWS_Send(message);
  8028. return result;
  8029. }
  8030. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  8031. {
  8032. mtrace();
  8033. int result = FAIL;
  8034. char message[500]={0};
  8035. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  8036. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8037. LWS_Send(message);
  8038. return result;
  8039. }
  8040. int sendDataTransferConfirmation(char *uuid,char *payload)
  8041. {
  8042. mtrace();
  8043. char statusStr[20]={0};
  8044. char dataStr[10]={0};
  8045. char sstr[20]={0};
  8046. int c = 0;
  8047. char *loc;
  8048. int result = FAIL;
  8049. DEBUG_INFO("sendDataTransferConfirmation...\n");
  8050. /**********************status**************************/
  8051. loc = strstr(payload, "status");
  8052. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8053. c = 0;
  8054. while (loc[3+strlen("status")+c] != '\"')
  8055. {
  8056. sstr[c] = loc[3+strlen("status")+c];
  8057. c++;
  8058. }
  8059. sstr[c] = '\0';
  8060. strcpy(statusStr, sstr);
  8061. /**********************data**************************/
  8062. loc = strstr(payload, "data");
  8063. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8064. c = 0;
  8065. while (loc[3+strlen("data")+c] != '\"')
  8066. {
  8067. sstr[c] = loc[3+strlen("data")+c];
  8068. c++;
  8069. }
  8070. sstr[c] = '\0';
  8071. strcpy(dataStr, sstr);
  8072. return result;
  8073. }
  8074. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  8075. {
  8076. mtrace();
  8077. int result = FAIL;
  8078. char message[1000]={0};
  8079. int CompositeScheduleIndex = 0;
  8080. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  8081. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  8082. if(nPeriod == 0)
  8083. {
  8084. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  8085. {
  8086. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  8087. ,MESSAGE_TYPE_CALLRESULT
  8088. ,uuid
  8089. ,payload
  8090. ,connectorIdInt);
  8091. }
  8092. else
  8093. {
  8094. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  8095. ,MESSAGE_TYPE_CALLRESULT
  8096. ,uuid
  8097. ,payload
  8098. ,connectorIdInt
  8099. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8100. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8101. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8102. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  8103. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  8104. }
  8105. }
  8106. else
  8107. {
  8108. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  8109. ,MESSAGE_TYPE_CALLRESULT
  8110. ,uuid
  8111. ,payload
  8112. ,connectorIdInt
  8113. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8114. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8115. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8116. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  8117. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  8118. {
  8119. if (idx_sample == 0)
  8120. {
  8121. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8122. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8123. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8124. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8125. }
  8126. else
  8127. {
  8128. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8129. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8130. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8131. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8132. }
  8133. }
  8134. sprintf(message + strlen(message), "]}}]");
  8135. }
  8136. LWS_Send(message);
  8137. result = TRUE;
  8138. return result;
  8139. }
  8140. int sendGetConfigurationConfirmation(char *uuid)
  8141. {
  8142. mtrace();
  8143. int result = FAIL;
  8144. int MaxKeySupported = 0;
  8145. int sentConfigurationNumber= 0;
  8146. int sentunConfigurationNumber= 0;
  8147. char message[1024*10]={0};
  8148. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  8149. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8150. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  8151. ,MESSAGE_TYPE_CALLRESULT
  8152. ,uuid );
  8153. //configuration key
  8154. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  8155. {
  8156. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  8157. {
  8158. if (sentConfigurationNumber == 0)
  8159. {
  8160. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8161. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8162. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8163. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8164. }
  8165. else
  8166. {
  8167. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8168. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8169. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8170. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8171. }
  8172. sentConfigurationNumber = sentConfigurationNumber + 1;
  8173. }
  8174. }
  8175. sprintf(message + strlen(message), "]");
  8176. if(UnknownKeynum != 0)
  8177. {
  8178. sprintf(message + strlen(message), ",\"unknownKey\":[");
  8179. //unkown key
  8180. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8181. {
  8182. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  8183. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8184. if(sentunConfigurationNumber == 0)
  8185. {
  8186. sprintf(message + strlen(message), "\"%s\""
  8187. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8188. }
  8189. else
  8190. {
  8191. sprintf(message + strlen(message), ",\"%s\""
  8192. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8193. }
  8194. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8195. }
  8196. sprintf(message + strlen(message), "]");
  8197. }
  8198. sprintf(message + strlen(message), "}]");
  8199. LWS_Send(message);
  8200. return result;
  8201. }
  8202. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8203. {
  8204. mtrace();
  8205. int result = FAIL;
  8206. char message[400]={0};
  8207. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8208. if(strcmp(payload,"")==0)
  8209. {
  8210. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8211. }
  8212. else
  8213. {
  8214. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8215. }
  8216. LWS_Send(message);
  8217. result = TRUE;
  8218. return result;
  8219. }
  8220. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8221. {
  8222. mtrace();
  8223. int result = FAIL;
  8224. char message[80]={0};
  8225. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8226. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8227. LWS_Send(message);
  8228. result = TRUE;
  8229. return result;
  8230. }
  8231. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8232. {
  8233. mtrace();
  8234. int result = FAIL;
  8235. char message[80]={0};
  8236. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8237. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8238. LWS_Send(message);
  8239. result = TRUE;
  8240. return result;
  8241. }
  8242. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8243. {
  8244. mtrace();
  8245. int result = FAIL;
  8246. char message[80]={0};
  8247. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8248. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8249. LWS_Send(message);
  8250. result = TRUE;
  8251. return result;
  8252. }
  8253. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8254. {
  8255. mtrace();
  8256. int result = FAIL;
  8257. char message[80]={0};
  8258. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8259. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8260. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8261. LWS_Send(message);
  8262. result = TRUE;
  8263. return result;
  8264. }
  8265. int sendResetConfirmation(char *uuid,char *payload)
  8266. {
  8267. mtrace();
  8268. int result = FAIL;
  8269. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8270. char message[80]={0};
  8271. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8272. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8273. LWS_Send(message);
  8274. result = TRUE;
  8275. return result;
  8276. }
  8277. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8278. {
  8279. mtrace();
  8280. int result = FAIL;
  8281. char message[500]={0};
  8282. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8283. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8284. LWS_Send(message);
  8285. result = TRUE;
  8286. return result;
  8287. }
  8288. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8289. {
  8290. mtrace();
  8291. int result = FAIL;
  8292. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8293. char message[80]={0};
  8294. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8295. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8296. LWS_Send(message);
  8297. result = TRUE;
  8298. return result;
  8299. }
  8300. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8301. {
  8302. mtrace();
  8303. int result = FAIL;
  8304. char message[80]={0};
  8305. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8306. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8307. LWS_Send(message);
  8308. result = TRUE;
  8309. return result;
  8310. }
  8311. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8312. {
  8313. mtrace();
  8314. int result = FAIL;
  8315. char message[80]={0};
  8316. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8317. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8318. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8319. LWS_Send(message);
  8320. result = TRUE;
  8321. return result;
  8322. }
  8323. int sendUpdateFirmwareConfirmation(char *uuid)
  8324. {
  8325. mtrace();
  8326. int result = FAIL;
  8327. char message[60]={0};
  8328. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8329. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8330. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8331. LWS_Send(message);
  8332. result = TRUE;
  8333. return result;
  8334. }
  8335. int sendCertificateSignedConfirmation(char *uuid)
  8336. {
  8337. mtrace();
  8338. int result = PASS;
  8339. char message[4096]={0};
  8340. json_object *CertificateSigned = json_object_new_object();
  8341. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8342. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8343. sprintf(message,"[%d,\"%s\",%s]"
  8344. ,MESSAGE_TYPE_CALLRESULT
  8345. ,uuid
  8346. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8347. json_object_put(CertificateSigned);
  8348. LWS_Send(message);
  8349. return result;
  8350. }
  8351. int sendDeleteCertificateConfirmation(char *uuid)
  8352. {
  8353. mtrace();
  8354. int result = PASS;
  8355. char message[4096]={0};
  8356. json_object *DeleteCertificate = json_object_new_object();
  8357. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8358. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8359. sprintf(message,"[%d,\"%s\",%s]"
  8360. ,MESSAGE_TYPE_CALLRESULT
  8361. ,uuid
  8362. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8363. json_object_put(DeleteCertificate);
  8364. LWS_Send(message);
  8365. return result;
  8366. }
  8367. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8368. {
  8369. mtrace();
  8370. int result = PASS;
  8371. char message[4096]={0};
  8372. json_object *ExtendedTriggerMessage = json_object_new_object();
  8373. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8374. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8375. sprintf(message,"[%d,\"%s\",%s]"
  8376. ,MESSAGE_TYPE_CALLRESULT
  8377. ,uuid
  8378. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8379. json_object_put(ExtendedTriggerMessage);
  8380. LWS_Send(message);
  8381. return result;
  8382. }
  8383. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8384. {
  8385. mtrace();
  8386. int result = PASS;
  8387. char message[4096]={0};
  8388. json_object *GetInstalledCertificateIds = json_object_new_object();
  8389. json_object *certificateHashDataDatas = json_object_new_array();
  8390. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8391. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8392. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8393. {
  8394. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8395. {
  8396. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm) > 0)
  8397. {
  8398. json_object *certificateHashData = json_object_new_object();
  8399. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8400. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8401. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8402. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8403. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8404. }
  8405. }
  8406. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8407. }
  8408. else
  8409. {
  8410. json_object_put(certificateHashDataDatas);
  8411. }
  8412. sprintf(message,"[%d,\"%s\",%s]"
  8413. ,MESSAGE_TYPE_CALLRESULT
  8414. ,uuid
  8415. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8416. json_object_put(GetInstalledCertificateIds);
  8417. LWS_Send(message);
  8418. return result;
  8419. }
  8420. int sendGetLogConfirmation(char *uuid)
  8421. {
  8422. mtrace();
  8423. int result = PASS;
  8424. char message[4096]={0};
  8425. json_object *GetLog = json_object_new_object();
  8426. DEBUG_INFO("sendGetLogConfirmation...\n");
  8427. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8428. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8429. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8430. sprintf(message,"[%d,\"%s\",%s]"
  8431. ,MESSAGE_TYPE_CALLRESULT
  8432. ,uuid
  8433. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8434. json_object_put(GetLog);
  8435. LWS_Send(message);
  8436. return result;
  8437. }
  8438. int sendInstallCertificateConfirmation(char *uuid)
  8439. {
  8440. mtrace();
  8441. int result = PASS;
  8442. char message[4096]={0};
  8443. json_object *InstallCertificate = json_object_new_object();
  8444. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8445. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8446. sprintf(message,"[%d,\"%s\",%s]"
  8447. ,MESSAGE_TYPE_CALLRESULT
  8448. ,uuid
  8449. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8450. json_object_put(InstallCertificate);
  8451. LWS_Send(message);
  8452. return result;
  8453. }
  8454. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8455. {
  8456. mtrace();
  8457. int result = PASS;
  8458. char message[4096]={0};
  8459. json_object *SignedUpdateFirmware = json_object_new_object();
  8460. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8461. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8462. sprintf(message,"[%d,\"%s\",%s]"
  8463. ,MESSAGE_TYPE_CALLRESULT
  8464. ,uuid
  8465. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8466. json_object_put(SignedUpdateFirmware);
  8467. LWS_Send(message);
  8468. return result;
  8469. }
  8470. int sendUnknownConfirmation(char *uuid)
  8471. {
  8472. mtrace();
  8473. int result = PASS;
  8474. char message[256]={0};
  8475. DEBUG_INFO("sendUnknownConfirmation...\n");
  8476. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8477. LWS_Send(message);
  8478. return result;
  8479. }
  8480. //==========================================
  8481. // Handle server request routine Start
  8482. //==========================================
  8483. int handleCancelReservationRequest(char *uuid, char *payload)
  8484. {
  8485. mtrace();
  8486. int result = FAIL;
  8487. int gunNO = 0;
  8488. int reservationIdInt = -1;
  8489. char comfirmstr[20];
  8490. DEBUG_INFO("handleCancelReservationRequest...\n");
  8491. json_object *CancelReservation;
  8492. CancelReservation = json_tokener_parse(payload);
  8493. if(!is_error(CancelReservation))
  8494. {
  8495. // Required data
  8496. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8497. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8498. }
  8499. json_object_put(CancelReservation);
  8500. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8501. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8502. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8503. if(reservationIdInt != -1)
  8504. {
  8505. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8506. //check Transaction active
  8507. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8508. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8509. {
  8510. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8511. {
  8512. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8513. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8514. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8515. {
  8516. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8517. }
  8518. else
  8519. {
  8520. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8521. }
  8522. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8523. goto end;
  8524. }
  8525. }
  8526. for (int index = 0; index < CCS_QUANTITY; index++)
  8527. {
  8528. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8529. {
  8530. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8531. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8532. if(gunType[2] == GUN_TYPE_CCS)
  8533. {
  8534. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8535. }
  8536. else
  8537. {
  8538. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8539. }
  8540. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8541. goto end;
  8542. }
  8543. }
  8544. for (int index = 0; index < GB_QUANTITY; index++)
  8545. {
  8546. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8547. {
  8548. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8549. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8550. if(gunType[2] == GUN_TYPE_GBT)
  8551. {
  8552. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8553. }
  8554. else
  8555. {
  8556. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8557. }
  8558. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8559. goto end;
  8560. }
  8561. }
  8562. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8563. {
  8564. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8565. {
  8566. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8567. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8568. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8569. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8570. goto end;
  8571. }
  8572. }
  8573. for (int index = 0; index < AC_QUANTITY; index++)
  8574. {
  8575. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8576. {
  8577. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8578. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8579. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8580. {
  8581. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8582. }
  8583. else
  8584. {
  8585. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8586. }
  8587. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8588. goto end;
  8589. }
  8590. }
  8591. }
  8592. //The reservationId does NOT match the reservationId
  8593. sendCancelReservationConfirmation(uuid, comfirmstr);
  8594. end:
  8595. // Fill in ocpp packet uuid
  8596. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8597. return result;
  8598. }
  8599. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8600. {
  8601. mtrace();
  8602. int result = FAIL;
  8603. int gunIndex = -1;
  8604. char typeStr[16]={0};
  8605. char comfirmstr[20];
  8606. int specificId = FALSE;
  8607. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8608. json_object *ChangeAvailability;
  8609. ChangeAvailability = json_tokener_parse(payload);
  8610. if(!is_error(ChangeAvailability))
  8611. {
  8612. // Required data
  8613. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8614. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8615. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8616. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8617. }
  8618. json_object_put(ChangeAvailability);
  8619. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8620. {
  8621. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8622. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8623. }
  8624. else if(gunIndex == 0)
  8625. {
  8626. for(int i=0; i < gunTotalNumber; i++)
  8627. {
  8628. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8629. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8630. }
  8631. }
  8632. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8633. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8634. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8635. {
  8636. specificId = TRUE;
  8637. }
  8638. if(specificId == FALSE)
  8639. goto end;
  8640. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8641. {
  8642. //----------------------gunIndex is 0 ------------------------------------------------//
  8643. if(gunIndex == 0)
  8644. {
  8645. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8646. {
  8647. for(int i=0; i < gunTotalNumber; i++)
  8648. {
  8649. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8650. {
  8651. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8652. {
  8653. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8654. {
  8655. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8656. goto end;
  8657. }
  8658. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8659. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8660. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8661. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8662. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8663. {
  8664. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8665. goto end;
  8666. }
  8667. }
  8668. }//END FOR CHAdeMO_QUANTITY
  8669. for (int index = 0; index < CCS_QUANTITY; index++)
  8670. {
  8671. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8672. {
  8673. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8674. {
  8675. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8676. goto end;
  8677. }
  8678. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8679. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8680. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8681. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8682. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8683. {
  8684. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8685. goto end;
  8686. }
  8687. }
  8688. }//END FOR CCS_QUANTITY
  8689. for (int index = 0; index < GB_QUANTITY; index++)
  8690. {
  8691. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8692. {
  8693. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8694. {
  8695. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8696. goto end;
  8697. }
  8698. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8699. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8700. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8701. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8702. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8703. {
  8704. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8705. goto end;
  8706. }
  8707. }
  8708. }// END FOR GB_QUANTITY
  8709. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8710. {
  8711. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8712. {
  8713. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8714. {
  8715. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8716. goto end;
  8717. }
  8718. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8719. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8720. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8721. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8722. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8723. {
  8724. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8725. goto end;
  8726. }
  8727. }
  8728. }// END FOR GENERAL_GUN_QUANTITY
  8729. for (int index = 0; index < AC_QUANTITY; index++)
  8730. {
  8731. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8732. {
  8733. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8734. {
  8735. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8736. goto end;
  8737. }
  8738. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8739. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8740. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8741. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8742. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8743. {
  8744. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8745. goto end;
  8746. }
  8747. }
  8748. }//END FOR AC_QUANTITY
  8749. }// END FOR gunTotalNumber
  8750. }
  8751. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8752. {
  8753. for(int i=0; i < gunTotalNumber; i++)
  8754. {
  8755. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8756. {
  8757. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8758. goto end;
  8759. }
  8760. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8761. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8762. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8763. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8764. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8765. {
  8766. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8767. goto end;
  8768. }
  8769. }
  8770. }
  8771. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8772. goto end;
  8773. }
  8774. //----------------------gunIndex is not 0 ------------------------------------------------//
  8775. //check Transaction active
  8776. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8777. {
  8778. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8779. {
  8780. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8781. {
  8782. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8783. goto end;
  8784. }
  8785. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8786. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8787. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8788. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8789. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8790. {
  8791. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8792. goto end;
  8793. }
  8794. else
  8795. {
  8796. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8797. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8798. goto end;
  8799. }
  8800. }
  8801. }//END FOR CHAdeMO_QUANTITY
  8802. for (int index = 0; index < CCS_QUANTITY; index++)
  8803. {
  8804. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8805. {
  8806. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8807. {
  8808. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8809. goto end;
  8810. }
  8811. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8812. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8813. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8814. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8815. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8816. {
  8817. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8818. goto end;
  8819. }
  8820. else
  8821. {
  8822. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8823. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8824. goto end;
  8825. }
  8826. }
  8827. }//END FOR CCS_QUANTITY
  8828. for (int index = 0; index < GB_QUANTITY; index++)
  8829. {
  8830. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8831. {
  8832. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8833. {
  8834. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8835. goto end;
  8836. }
  8837. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8838. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8839. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8840. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8841. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8842. {
  8843. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8844. goto end;
  8845. }
  8846. else
  8847. {
  8848. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8849. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8850. goto end;
  8851. }
  8852. }
  8853. }// END FOR GB_QUANTITY
  8854. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8855. {
  8856. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8857. {
  8858. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8859. {
  8860. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8861. goto end;
  8862. }
  8863. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8864. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8865. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8866. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8867. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8868. {
  8869. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8870. goto end;
  8871. }
  8872. else
  8873. {
  8874. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8875. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8876. goto end;
  8877. }
  8878. }
  8879. }// END FOR GENERAL_GUN_QUANTITY
  8880. for (int index = 0; index < AC_QUANTITY; index++)
  8881. {
  8882. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8883. {
  8884. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8885. {
  8886. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8887. goto end;
  8888. }
  8889. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8890. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8891. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8892. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8893. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8894. {
  8895. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8896. goto end;
  8897. }
  8898. else
  8899. {
  8900. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8901. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8902. goto end;
  8903. }
  8904. }
  8905. }//END FOR AC_QUANTITY
  8906. }//END FOR AvailabilityTypeStr[Inoperative]
  8907. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8908. {
  8909. //----------------------gunIndex is 0 ------------------------------------------------//
  8910. if(gunIndex == 0)
  8911. {
  8912. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8913. {
  8914. for(int i=0; i < gunTotalNumber; i++)
  8915. {
  8916. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8917. {
  8918. 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
  8919. {
  8920. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8921. goto end;
  8922. }
  8923. }//END FOR CHAdeMO_QUANTITY
  8924. for (int index = 0; index < CCS_QUANTITY; index++)
  8925. {
  8926. 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
  8927. {
  8928. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8929. goto end;
  8930. }
  8931. }//END FOR CCS_QUANTITY
  8932. for (int index = 0; index < GB_QUANTITY; index++)
  8933. {
  8934. 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
  8935. {
  8936. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8937. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8938. goto end;
  8939. }
  8940. }// END FOR GB_QUANTITY
  8941. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8942. {
  8943. 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
  8944. {
  8945. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8946. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8947. goto end;
  8948. }
  8949. }// END FOR GENERAL_GUN_QUANTITY
  8950. for (int index = 0; index < AC_QUANTITY; index++)
  8951. {
  8952. 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
  8953. {
  8954. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8955. goto end;
  8956. }
  8957. }//END FOR CHAdeMO_QUANTITY
  8958. }// END FOR gunTotalNumber
  8959. }
  8960. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8961. {
  8962. for(int i=0; i < gunTotalNumber; i++)
  8963. {
  8964. for (int index = 0; index < AC_QUANTITY; index++)
  8965. {
  8966. 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
  8967. {
  8968. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8969. goto end;
  8970. }
  8971. }//END FOR CHAdeMO_QUANTITY
  8972. } // END FOR gunTotalNumber
  8973. }
  8974. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8975. goto end;
  8976. }
  8977. //----------------------gunIndex is not 0 ------------------------------------------------//
  8978. //check Transaction active
  8979. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8980. {
  8981. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8982. {
  8983. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8984. goto end;
  8985. }
  8986. }//END FOR CHAdeMO_QUANTITY
  8987. for (int index = 0; index < CCS_QUANTITY; index++)
  8988. {
  8989. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8990. {
  8991. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8992. goto end;
  8993. }
  8994. }//END FOR CCS_QUANTITY
  8995. for (int index = 0; index < GB_QUANTITY; index++)
  8996. {
  8997. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8998. {
  8999. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9000. goto end;
  9001. }
  9002. }// END FOR GB_QUANTITY
  9003. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9004. {
  9005. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9006. {
  9007. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9008. goto end;
  9009. }
  9010. }// END FOR GENERAL_GUN_QUANTITY
  9011. for (int index = 0; index < AC_QUANTITY; index++)
  9012. {
  9013. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9014. {
  9015. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9016. goto end;
  9017. }
  9018. }//END FOR AC_QUANTITY
  9019. }//END FOR AvailabilityTypeStr[Operative]
  9020. end:
  9021. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9022. {
  9023. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  9024. }
  9025. else
  9026. {
  9027. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  9028. }
  9029. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9030. {
  9031. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9032. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9033. }
  9034. else if(gunIndex == 0)
  9035. {
  9036. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9037. {
  9038. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  9039. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  9040. }
  9041. }
  9042. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  9043. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9044. return result;
  9045. }
  9046. int handleChangeConfigurationRequest(char *uuid, char *payload)
  9047. {
  9048. mtrace();
  9049. int valueInvalid = NO;
  9050. int result = FAIL;
  9051. char keystr[40]={0};
  9052. char valuestr[501]={0}; //value should be limited in 500 bytes
  9053. char comfirmstr[20]={0};
  9054. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  9055. json_object *ChangeConfiguration;
  9056. ChangeConfiguration = json_tokener_parse(payload);
  9057. if(!is_error(ChangeConfiguration))
  9058. {
  9059. // Required data
  9060. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  9061. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  9062. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  9063. {
  9064. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  9065. }
  9066. else
  9067. {
  9068. valueInvalid = YES;
  9069. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  9070. }
  9071. }
  9072. json_object_put(ChangeConfiguration);
  9073. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  9074. {
  9075. DEBUG_ERROR("Payload is null or value is invalid.\n");
  9076. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9077. }
  9078. else
  9079. {
  9080. int status = setKeyValue(keystr, valuestr);
  9081. switch(status)
  9082. {
  9083. case ConfigurationStatus_Accepted:
  9084. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  9085. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  9086. StoreConfigurationTable();
  9087. break;
  9088. case RebootRequired:
  9089. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  9090. StoreConfigurationTable();
  9091. break;
  9092. case NotSupported:
  9093. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  9094. break;
  9095. case ConfigurationStatus_Rejected:
  9096. default:
  9097. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9098. break;
  9099. }
  9100. }
  9101. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  9102. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  9103. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9104. {
  9105. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9106. SetOcppConnStatus(FALSE);
  9107. }
  9108. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9109. {
  9110. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9111. }
  9112. return result;
  9113. }
  9114. int handleClearCacheRequest(char *uuid, char *payload)
  9115. {
  9116. mtrace();
  9117. int result = FAIL;
  9118. char comfirmstr[20];
  9119. char rmFileCmd[100]={0};
  9120. struct stat stats;
  9121. DEBUG_INFO("handleClearCacheRequest...\n");
  9122. stat("/Storage/OCPP", &stats);
  9123. // Check for directory existence
  9124. if (S_ISDIR(stats.st_mode) == 1)
  9125. {}
  9126. else
  9127. {
  9128. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  9129. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  9130. system(rmFileCmd);
  9131. }
  9132. if(OCPP_cleanLocalCache())
  9133. {
  9134. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  9135. }
  9136. else
  9137. {
  9138. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  9139. }
  9140. sendClearCacheConfirmation(uuid, comfirmstr);
  9141. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9142. return result;
  9143. }
  9144. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9145. {
  9146. mtrace();
  9147. int result = FAIL;
  9148. int resultRename;
  9149. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9150. char chargingProfilePurposeStr[26]={0};
  9151. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9152. char tempchargingProfilePurposeStr[26]={0};
  9153. char str[100]={0};
  9154. char fname[200]={0};
  9155. char comfirmstr[20]={0};
  9156. char word[1600]={0};
  9157. int clearflag = FALSE;
  9158. int chargingProfileIdIsNULL = FALSE;
  9159. int connectorIsNULL = FALSE;
  9160. int chargingProfilePurposeIsNULL = FALSE;
  9161. int stackLevelIsNULL = FALSE;
  9162. //int GotoEnd = FALSE;
  9163. FILE *fptr1, *fptr2;
  9164. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9165. int n_chargingProfile=0;
  9166. int isEmptyFile = FALSE;
  9167. char sLineWord[1600]={0};
  9168. char chargingProfiles[10][100]={0};
  9169. int ChargeProfileCount = 0;
  9170. int ch;
  9171. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9172. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9173. json_object *ClearChargingProfile;
  9174. ClearChargingProfile = json_tokener_parse(payload);
  9175. if(!is_error(ClearChargingProfile))
  9176. {
  9177. // Optional data
  9178. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9179. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9180. else
  9181. chargingProfileIdIsNULL = TRUE;
  9182. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9183. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9184. else
  9185. connectorIsNULL = TRUE;
  9186. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9187. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9188. else
  9189. chargingProfilePurposeIsNULL = TRUE;
  9190. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9191. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9192. else
  9193. stackLevelIsNULL = TRUE;
  9194. }
  9195. json_object_put(ClearChargingProfile);
  9196. if(connectorIsNULL == FALSE)
  9197. {
  9198. switch(connectorIdInt)
  9199. {
  9200. case 0:
  9201. if(chargingProfilePurposeIsNULL == TRUE)
  9202. {
  9203. int l = 0;
  9204. strcpy(fname, ChargePointMaxProfile_JSON);
  9205. if((access(fname,F_OK))!=-1)
  9206. {
  9207. strcpy(chargingProfiles[l], fname);
  9208. l = l + 1;
  9209. }
  9210. strcpy(fname, TxDefaultProfile_0_JSON);
  9211. if((access(fname,F_OK))!=-1)
  9212. {
  9213. strcpy(chargingProfiles[l], fname);
  9214. l = l + 1;
  9215. }
  9216. ChargeProfileCount = l;
  9217. }
  9218. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  9219. {
  9220. strcpy(fname, ChargePointMaxProfile_JSON);
  9221. if((access(fname,F_OK))!=-1)
  9222. {
  9223. strcpy(chargingProfiles[0], fname);
  9224. ChargeProfileCount = 1;
  9225. }
  9226. }
  9227. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9228. {
  9229. strcpy(fname, TxDefaultProfile_0_JSON);
  9230. if((access(fname,F_OK))!=-1)
  9231. {
  9232. strcpy(chargingProfiles[0], fname);
  9233. ChargeProfileCount = 1;
  9234. }
  9235. }
  9236. break;
  9237. default:
  9238. if(chargingProfilePurposeIsNULL == TRUE)
  9239. {
  9240. int m = 0;
  9241. memset(fname, 0, ARRAY_SIZE(fname));
  9242. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9243. if((access(fname,F_OK))!=-1)
  9244. {
  9245. strcpy(chargingProfiles[m], fname);
  9246. m = m + 1;
  9247. }
  9248. memset(fname, 0, ARRAY_SIZE(fname));
  9249. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9250. if((access(fname,F_OK))!=-1)
  9251. {
  9252. strcpy(chargingProfiles[m], fname);
  9253. m = m + 1;
  9254. }
  9255. ChargeProfileCount = m;
  9256. }
  9257. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9258. {
  9259. //strcpy(fname, TxDefaultProfile_1_JSON);
  9260. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9261. if((access(fname,F_OK))!=-1)
  9262. {
  9263. strcpy(chargingProfiles[0], fname);
  9264. ChargeProfileCount = 1;
  9265. }
  9266. }
  9267. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9268. {
  9269. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9270. if((access(fname,F_OK))!=-1)
  9271. {
  9272. strcpy(chargingProfiles[0], fname);
  9273. ChargeProfileCount = 1;
  9274. }
  9275. //strcpy(fname, TxProfile_1_JSON);
  9276. }
  9277. //strcpy(fname, ChargePointMaxProfile_JSON );
  9278. break;
  9279. }
  9280. }
  9281. else // Check all Charging Profiles
  9282. {
  9283. int i = 0;
  9284. char fnametemp[200]={0};
  9285. ChargeProfileCount = 0;
  9286. //Check ChargePointMaxProfile.json exit
  9287. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9288. {
  9289. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9290. i = i + 1;
  9291. }
  9292. //Check TxDefaultProfile_0.json exit
  9293. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9294. {
  9295. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9296. i = i + 1;
  9297. }
  9298. //Check TxDefaultProfile_%d.json
  9299. for(int j=1; j <= gunTotalNumber; j++)
  9300. {
  9301. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9302. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9303. if((access(fnametemp,F_OK))!=-1)
  9304. {
  9305. strcpy(chargingProfiles[i], fnametemp);
  9306. i = i + 1;
  9307. }
  9308. }
  9309. //Check TxProfile_%d.json
  9310. for(int j=1; j <= gunTotalNumber; j++)
  9311. {
  9312. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9313. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9314. if((access(fnametemp,F_OK))!=-1)
  9315. {
  9316. strcpy(chargingProfiles[i], fnametemp);
  9317. i = i + 1;
  9318. }
  9319. }
  9320. ChargeProfileCount = i;
  9321. }// End connectorIsNULL is TRUE
  9322. if(ChargeProfileCount == 0)
  9323. {
  9324. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9325. goto end;
  9326. }
  9327. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9328. {
  9329. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9330. goto end;
  9331. }
  9332. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9333. {
  9334. memset(str, 0, ARRAY_SIZE(str));
  9335. // clear temp file
  9336. sprintf(str,"rm -f %s",temp);
  9337. system(str);
  9338. for(int k=0; k < ChargeProfileCount; k++)
  9339. {
  9340. memset(str, 0, ARRAY_SIZE(str));
  9341. //clear file in C
  9342. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9343. system(str);
  9344. }
  9345. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9346. goto end;
  9347. }
  9348. else if(connectorIsNULL == TRUE)
  9349. {
  9350. for(int k=0; k < ChargeProfileCount; k++)
  9351. {
  9352. fptr1 = fopen(chargingProfiles[k], "r");
  9353. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9354. //Check Charging Profile Count
  9355. while(fscanf(fptr1, "%s", word) != EOF)
  9356. {
  9357. //DEBUG_INFO("word=%s\n",word);
  9358. if(strstr(word, "chargingProfileId")!= NULL)
  9359. {
  9360. //DEBUG_INFO("test chargingProfileId \n");
  9361. n_chargingProfile = n_chargingProfile + 1;
  9362. //DEBUG_INFO("chargingProfileId Found\n");
  9363. }
  9364. }
  9365. rewind(fptr1);
  9366. //search Charging Profile Element
  9367. //int i= 0;
  9368. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9369. {
  9370. json_object *tmpProfilee;
  9371. tmpProfilee = json_tokener_parse(sLineWord);
  9372. if(!is_error(tmpProfilee))
  9373. {
  9374. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9375. {
  9376. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9377. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9378. }
  9379. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9380. {
  9381. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9382. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9383. }
  9384. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9385. {
  9386. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9387. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9388. }
  9389. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9390. {
  9391. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9392. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9393. }
  9394. }
  9395. json_object_put(tmpProfilee);
  9396. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9397. {
  9398. //------- not write to fptr2-------//
  9399. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9400. //clearflag = TRUE;
  9401. }
  9402. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9403. {
  9404. //------- not write to fptr2-------//
  9405. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9406. }
  9407. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9408. {
  9409. //------- not write to fptr2-------//
  9410. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9411. }
  9412. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9413. {
  9414. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9415. }
  9416. else
  9417. {
  9418. fprintf(fptr2, sLineWord);//writing data into file
  9419. }
  9420. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9421. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9422. if(clearflag == TRUE)
  9423. {
  9424. fclose(fptr1);
  9425. fclose(fptr2);
  9426. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9427. system(str);
  9428. // clear temp file
  9429. sprintf(str,"rm -f %s",temp);
  9430. system(str);
  9431. }
  9432. else
  9433. {
  9434. fclose(fptr1);
  9435. fclose(fptr2);
  9436. memset(str, 0, ARRAY_SIZE(str));
  9437. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9438. system(str);
  9439. resultRename = rename(temp, chargingProfiles[k]);
  9440. if(resultRename == 0)
  9441. {
  9442. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9443. }
  9444. else
  9445. {
  9446. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9447. }
  9448. if(comfirmstr[0]== 0)
  9449. {
  9450. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9451. }
  9452. //Check chargingProfile is empty file
  9453. /*------ Read the file ----------------*/
  9454. fptr1=fopen(chargingProfiles[k],"r");
  9455. ch=fgetc(fptr1);
  9456. rewind(fptr1);
  9457. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9458. if(ch!=EOF)
  9459. {
  9460. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9461. {
  9462. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9463. if(sLineWord[0]=='\0')
  9464. {
  9465. isEmptyFile = TRUE;
  9466. break;
  9467. }
  9468. else
  9469. {
  9470. isEmptyFile = FALSE;
  9471. break;
  9472. }
  9473. }
  9474. }
  9475. else
  9476. isEmptyFile = TRUE;
  9477. fclose(fptr1);
  9478. if(isEmptyFile == TRUE)
  9479. {
  9480. memset(str, 0, ARRAY_SIZE(str));
  9481. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9482. system(str);
  9483. }
  9484. }
  9485. }// End of while(int k=0; k < ChargePointCount; k++)
  9486. }
  9487. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9488. {
  9489. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9490. for(int k=0; k < ChargeProfileCount; k++)
  9491. {
  9492. fptr1 = fopen(chargingProfiles[k], "r");
  9493. fptr2 = fopen(temp, "w+");
  9494. //Check Charging Profile Count
  9495. while(fscanf(fptr1, "%s", word) != EOF)
  9496. {
  9497. //DEBUG_INFO("word=%s\n",word);
  9498. if(strstr(word, "chargingProfileId")!= NULL)
  9499. {
  9500. n_chargingProfile = n_chargingProfile + 1;
  9501. }
  9502. }
  9503. rewind(fptr1);
  9504. //search Charging Profile Element
  9505. //int i= 0;
  9506. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9507. {
  9508. json_object *tmpProfilee;
  9509. tmpProfilee = json_tokener_parse(sLineWord);
  9510. if(!is_error(tmpProfilee))
  9511. {
  9512. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9513. {
  9514. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9515. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9516. }
  9517. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9518. {
  9519. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9520. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9521. }
  9522. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9523. {
  9524. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9525. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9526. }
  9527. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9528. {
  9529. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9530. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9531. }
  9532. }
  9533. json_object_put(tmpProfilee);
  9534. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9535. {
  9536. //------- not write to fptr2-------//
  9537. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9538. //clearflag = TRUE;
  9539. }
  9540. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9541. {
  9542. //------- not write to fptr2-------//
  9543. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9544. }
  9545. else if(stackLevelIsNULL == TRUE)
  9546. {
  9547. //Clear Whole File
  9548. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9549. clearflag = TRUE;
  9550. break;
  9551. }
  9552. else
  9553. {
  9554. fprintf(fptr2, sLineWord);//writing data into file
  9555. }
  9556. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9557. }
  9558. if(clearflag == TRUE)
  9559. {
  9560. fclose(fptr1);
  9561. fclose(fptr2);
  9562. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9563. system(str);
  9564. // clear temp file
  9565. sprintf(str,"rm -f %s",temp);
  9566. system(str);
  9567. }
  9568. else
  9569. {
  9570. fclose(fptr1);
  9571. fclose(fptr2);
  9572. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9573. system(str);
  9574. resultRename = rename(temp, chargingProfiles[k]);
  9575. if(resultRename == 0)
  9576. {
  9577. DEBUG_INFO("File ChargingProfile renamed successfully");
  9578. }
  9579. else
  9580. {
  9581. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9582. }
  9583. if(comfirmstr[0]== 0)
  9584. {
  9585. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9586. }
  9587. //Check chargingProfile is empty file
  9588. /*------ Read the file ----------------*/
  9589. fptr1=fopen(chargingProfiles[k],"r");
  9590. ch=fgetc(fptr1);
  9591. rewind(fptr1);
  9592. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9593. if(ch!=EOF)
  9594. {
  9595. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9596. {
  9597. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9598. if(sLineWord[0]=='\0')
  9599. {
  9600. isEmptyFile = TRUE;
  9601. break;
  9602. }
  9603. else
  9604. {
  9605. isEmptyFile = FALSE;
  9606. break;
  9607. }
  9608. }
  9609. }
  9610. else
  9611. isEmptyFile = TRUE;
  9612. fclose(fptr1);
  9613. if(isEmptyFile == TRUE)
  9614. {
  9615. memset(str, 0, ARRAY_SIZE(str));
  9616. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9617. system(str);
  9618. }
  9619. /*------- End of reading ---------------*/
  9620. }
  9621. } // while(int k=0; k < ChargeProfileCount; k++)
  9622. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9623. end:
  9624. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9625. {
  9626. if(connectorIdInt == 0)
  9627. {
  9628. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9629. {
  9630. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9631. }
  9632. }
  9633. else
  9634. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9635. }
  9636. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9637. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9638. return result;
  9639. }
  9640. void createFirmwareVersionByDataTransfer(void)
  9641. {
  9642. json_object *FirmwareDataTransfer = json_object_new_object();
  9643. // AC & DC model
  9644. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9645. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9646. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9647. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9648. // DC model
  9649. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9650. {
  9651. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9652. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9653. (gunType[3] != GUN_TYPE_UNKNOWN))
  9654. {
  9655. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9656. }
  9657. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9658. {
  9659. // DS DM DW
  9660. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9661. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9662. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9663. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9664. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9665. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9666. }
  9667. else
  9668. {
  9669. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9670. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9671. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9672. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9673. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9674. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9675. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9676. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9677. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9678. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9679. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9680. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9681. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9682. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9683. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9684. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9685. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9686. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9687. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9688. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9689. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9690. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9691. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9692. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9693. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9694. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9695. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9696. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9697. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9698. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9699. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9700. }
  9701. }
  9702. // 4G model
  9703. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9704. {
  9705. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9706. }
  9707. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9708. json_object_put(FirmwareDataTransfer);
  9709. }
  9710. int handleDataTransferRequest(char *uuid, char *payload)
  9711. {
  9712. mtrace();
  9713. json_object *response = json_object_new_object();
  9714. int result = FAIL;
  9715. char tempvendorId[255]={0};
  9716. char tempmessageId[50]={0};
  9717. char tempdata[10240]={0};
  9718. char message[20480]={0};
  9719. DEBUG_INFO("handleDataTransferRequest...\n");
  9720. if((uuid != NULL) && (payload != NULL))
  9721. {
  9722. json_object *DataTransfer;
  9723. DataTransfer = json_tokener_parse(payload);
  9724. if(!is_error(DataTransfer))
  9725. {
  9726. // Required data
  9727. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9728. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9729. // Optional data
  9730. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9731. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9732. if(json_object_object_get(DataTransfer, "data") != NULL)
  9733. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9734. result = PASS;
  9735. }
  9736. json_object_put(DataTransfer);
  9737. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9738. {
  9739. // Send all moudle firmware version on EVSE
  9740. createFirmwareVersionByDataTransfer();
  9741. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9742. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9743. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9744. json_object_put(response);
  9745. }
  9746. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9747. {
  9748. system("/usr/bin/run_tmate_restart.sh &");
  9749. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9750. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9751. json_object_put(response);
  9752. }
  9753. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9754. {
  9755. json_object *data;
  9756. data = json_tokener_parse(tempdata);
  9757. if(!is_error(data))
  9758. {
  9759. 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))
  9760. {
  9761. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9762. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9763. if(json_object_object_get(data, "SOC") != NULL)
  9764. {
  9765. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9766. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9767. }
  9768. if(json_object_object_get(data, "Energy") != NULL)
  9769. {
  9770. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9771. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9772. }
  9773. if(json_object_object_get(data, "Duration") != NULL)
  9774. {
  9775. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9776. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9777. }
  9778. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9779. }
  9780. else
  9781. {
  9782. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9783. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9784. }
  9785. }
  9786. else
  9787. {
  9788. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9789. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9790. }
  9791. json_object_put(data);
  9792. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9793. json_object_put(response);
  9794. }
  9795. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9796. {
  9797. json_object *data;
  9798. data = json_tokener_parse(tempdata);
  9799. if(!is_error(data))
  9800. {
  9801. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9802. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9803. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9804. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9805. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9806. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9807. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9808. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9809. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9810. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9811. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9812. }
  9813. else
  9814. {
  9815. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9816. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9817. }
  9818. json_object_put(data);
  9819. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9820. json_object_put(response);
  9821. }
  9822. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9823. {
  9824. json_object *data;
  9825. data = json_tokener_parse(tempdata);
  9826. if(!is_error(data))
  9827. {
  9828. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9829. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9830. if(json_object_object_get(data, "idToken") != NULL)
  9831. {
  9832. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9833. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9834. }
  9835. else
  9836. {
  9837. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9838. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9839. }
  9840. if(json_object_object_get(data, "price") != NULL) //v1.0
  9841. {
  9842. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9843. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9844. }
  9845. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9846. {
  9847. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9848. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9849. }
  9850. else
  9851. {
  9852. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9853. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9854. }
  9855. }
  9856. else
  9857. {
  9858. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9859. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9860. }
  9861. json_object_put(data);
  9862. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9863. json_object_put(response);
  9864. }
  9865. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9866. {
  9867. json_object *data;
  9868. data = json_tokener_parse(tempdata);
  9869. if(!is_error(data))
  9870. {
  9871. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9872. if(json_object_object_get(data, "txId") != NULL)
  9873. {
  9874. // California pricing V1.0
  9875. DEBUG_INFO("California pricing V1.0\n");
  9876. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9877. sprintf((char*)dmsVersion, "1.0");
  9878. for(int idx = 0;idx<gunTotalNumber;idx++)
  9879. {
  9880. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9881. {
  9882. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9883. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9884. if(json_object_object_get(data, "description") != NULL)
  9885. {
  9886. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9887. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9888. }
  9889. else
  9890. {
  9891. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9892. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9893. }
  9894. }
  9895. }
  9896. }
  9897. else if(json_object_object_get(data, "transactionId") != NULL)
  9898. {
  9899. // California pricing V2.0
  9900. DEBUG_INFO("California pricing V2.0\n");
  9901. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9902. sprintf((char*)dmsVersion, "2.0");
  9903. for(int idx=0;idx<gunTotalNumber;idx++)
  9904. {
  9905. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9906. {
  9907. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9908. if(json_object_object_get(data, "timestamp") != NULL)
  9909. {
  9910. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9911. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9912. }
  9913. else
  9914. {
  9915. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9916. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9917. }
  9918. if(json_object_object_get(data, "meterValue") != NULL)
  9919. {
  9920. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9921. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9922. }
  9923. else
  9924. {
  9925. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9926. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9927. }
  9928. if(json_object_object_get(data, "cost") != NULL)
  9929. {
  9930. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9931. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9932. }
  9933. else
  9934. {
  9935. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9936. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9937. }
  9938. if(json_object_object_get(data, "state") != NULL)
  9939. {
  9940. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9941. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9942. }
  9943. else
  9944. {
  9945. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9946. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9947. }
  9948. if(json_object_object_get(data, "chargingPrice") != NULL)
  9949. {
  9950. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9951. {
  9952. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9953. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9954. }
  9955. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9956. {
  9957. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9958. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9959. }
  9960. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9961. {
  9962. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9963. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9964. }
  9965. }
  9966. else
  9967. {
  9968. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9969. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9970. }
  9971. if(json_object_object_get(data, "idlePrice") != NULL)
  9972. {
  9973. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9974. {
  9975. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9976. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9977. }
  9978. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9979. {
  9980. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9981. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9982. }
  9983. }
  9984. if(json_object_object_get(data, "nextPeriod") != NULL)
  9985. {
  9986. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9987. {
  9988. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9989. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9990. }
  9991. else
  9992. {
  9993. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9994. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9995. }
  9996. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9997. {
  9998. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9999. {
  10000. 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")));
  10001. 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"));
  10002. }
  10003. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  10004. {
  10005. 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")));
  10006. 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"));
  10007. }
  10008. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  10009. {
  10010. 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")));
  10011. 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"));
  10012. }
  10013. }
  10014. else
  10015. {
  10016. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10017. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  10018. }
  10019. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  10020. {
  10021. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  10022. {
  10023. 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")));
  10024. 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"));
  10025. }
  10026. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  10027. {
  10028. 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")));
  10029. 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"));
  10030. }
  10031. }
  10032. }
  10033. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  10034. {
  10035. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  10036. {
  10037. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10038. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10039. }
  10040. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  10041. {
  10042. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  10043. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  10044. }
  10045. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  10046. {
  10047. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  10048. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  10049. }
  10050. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  10051. {
  10052. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10053. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10054. }
  10055. }
  10056. }
  10057. }
  10058. }
  10059. else
  10060. {
  10061. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10062. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10063. }
  10064. }
  10065. else
  10066. {
  10067. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10068. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10069. }
  10070. json_object_put(data);
  10071. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10072. json_object_put(response);
  10073. }
  10074. else if(strstr(tempmessageId, "FinalCost") != NULL)
  10075. {
  10076. json_object *data;
  10077. data = json_tokener_parse(tempdata);
  10078. if(!is_error(data))
  10079. {
  10080. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10081. if(json_object_object_get(data, "txId") != NULL)
  10082. {
  10083. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  10084. for(int idx = 0;idx<gunTotalNumber;idx++)
  10085. {
  10086. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10087. {
  10088. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10089. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  10090. if(json_object_object_get(data, "description") != NULL)
  10091. {
  10092. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  10093. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  10094. }
  10095. else
  10096. {
  10097. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10098. json_object_object_add(response, "data", json_object_new_string("description not found."));
  10099. }
  10100. }
  10101. }
  10102. }
  10103. else if(json_object_object_get(data, "transactionId") != NULL)
  10104. {
  10105. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  10106. for(int idx = 0;idx<gunTotalNumber;idx++)
  10107. {
  10108. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  10109. {
  10110. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10111. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10112. if(json_object_object_get(data, "cost") != NULL)
  10113. {
  10114. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  10115. ShmOCPP16Data->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10116. }
  10117. else
  10118. {
  10119. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10120. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10121. }
  10122. if(json_object_object_get(data, "priceText") != NULL)
  10123. {
  10124. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10125. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10126. }
  10127. else
  10128. {
  10129. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10130. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  10131. }
  10132. if(json_object_object_get(data, "qrCodeText") != NULL)
  10133. {
  10134. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10135. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10136. }
  10137. }
  10138. }
  10139. }
  10140. else
  10141. {
  10142. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10143. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10144. }
  10145. }
  10146. else
  10147. {
  10148. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10149. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10150. }
  10151. json_object_put(data);
  10152. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10153. json_object_put(response);
  10154. }
  10155. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  10156. {
  10157. json_object *data;
  10158. data = json_tokener_parse(tempdata);
  10159. if(!is_error(data))
  10160. {
  10161. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10162. if(json_object_object_get(data, "Content_Type") != NULL)
  10163. {
  10164. 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))
  10165. {
  10166. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10167. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10168. {
  10169. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10170. }
  10171. }
  10172. else
  10173. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10174. }
  10175. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10176. }
  10177. else
  10178. {
  10179. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10180. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10181. }
  10182. json_object_put(data);
  10183. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10184. json_object_put(response);
  10185. }
  10186. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  10187. {
  10188. json_object *data;
  10189. data = json_tokener_parse(tempdata);
  10190. if(!is_error(data))
  10191. {
  10192. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10193. if(json_object_object_get(data, "ConnectorId") != NULL)
  10194. {
  10195. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  10196. }
  10197. if(json_object_object_get(data, "SerialNo") != NULL)
  10198. {
  10199. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  10200. }
  10201. if(json_object_object_get(data, "Page_Index") != NULL)
  10202. {
  10203. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10204. }
  10205. if(json_object_object_get(data, "Duration") != NULL)
  10206. {
  10207. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10208. }
  10209. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  10210. }
  10211. else
  10212. {
  10213. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10214. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10215. }
  10216. json_object_put(data);
  10217. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10218. json_object_put(response);
  10219. }
  10220. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  10221. {
  10222. json_object *data;
  10223. data = json_tokener_parse(tempdata);
  10224. if(!is_error(data))
  10225. {
  10226. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10227. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10228. {
  10229. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10230. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10231. else
  10232. {
  10233. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10234. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10235. }
  10236. }
  10237. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10238. {
  10239. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10240. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10241. else
  10242. {
  10243. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10244. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10245. }
  10246. }
  10247. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  10248. {
  10249. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  10250. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  10251. else
  10252. {
  10253. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10254. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10255. }
  10256. }
  10257. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  10258. {
  10259. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  10260. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  10261. else
  10262. {
  10263. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10264. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10265. }
  10266. }
  10267. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10268. {
  10269. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10270. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10271. else
  10272. {
  10273. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10274. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10275. }
  10276. }
  10277. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10278. {
  10279. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10280. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10281. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10282. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10283. else
  10284. {
  10285. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10286. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10287. }
  10288. }
  10289. if(json_object_object_get(data, "isAuthentication") != NULL)
  10290. {
  10291. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10292. {
  10293. case 0:
  10294. case 1:
  10295. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10296. break;
  10297. default:
  10298. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10299. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10300. break;
  10301. }
  10302. }
  10303. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10304. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10305. }
  10306. else
  10307. {
  10308. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10309. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10310. }
  10311. json_object_put(data);
  10312. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10313. json_object_put(response);
  10314. }
  10315. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10316. {
  10317. json_object *data;
  10318. data = json_tokener_parse(tempdata);
  10319. if(!is_error(data))
  10320. {
  10321. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10322. {
  10323. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10324. {
  10325. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10326. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10327. }
  10328. else
  10329. {
  10330. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10331. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10332. }
  10333. }
  10334. else
  10335. {
  10336. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10337. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10338. }
  10339. }
  10340. else
  10341. {
  10342. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10343. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10344. }
  10345. json_object_put(data);
  10346. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10347. json_object_put(response);
  10348. }
  10349. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10350. {
  10351. json_object *data;
  10352. data = json_tokener_parse(tempdata);
  10353. if(!is_error(data))
  10354. {
  10355. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10356. if(json_object_object_get(data, "stationName") != NULL)
  10357. {
  10358. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10359. }
  10360. else
  10361. {
  10362. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10363. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10364. }
  10365. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10366. {
  10367. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10368. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10369. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10370. }
  10371. }
  10372. else
  10373. {
  10374. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10375. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10376. }
  10377. json_object_put(data);
  10378. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10379. json_object_put(response);
  10380. }
  10381. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10382. {
  10383. json_object *data;
  10384. data = json_tokener_parse(tempdata);
  10385. if(!is_error(data))
  10386. {
  10387. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10388. if(json_object_object_get(data, "weatherId") != NULL)
  10389. {
  10390. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10391. }
  10392. else
  10393. {
  10394. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10395. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10396. }
  10397. if(json_object_object_get(data, "Temperature") != NULL)
  10398. {
  10399. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10400. }
  10401. else
  10402. {
  10403. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10404. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10405. }
  10406. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10407. {
  10408. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10409. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10410. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10411. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10412. );
  10413. }
  10414. }
  10415. else
  10416. {
  10417. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10418. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10419. }
  10420. json_object_put(data);
  10421. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10422. json_object_put(response);
  10423. }
  10424. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10425. {
  10426. json_object *data;
  10427. data = json_tokener_parse(tempdata);
  10428. if(!is_error(data))
  10429. {
  10430. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10431. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10432. {
  10433. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10434. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10435. }
  10436. else
  10437. {
  10438. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10439. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10440. }
  10441. }
  10442. else
  10443. {
  10444. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10445. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10446. }
  10447. json_object_put(data);
  10448. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10449. json_object_put(response);
  10450. }
  10451. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10452. {
  10453. json_object *data;
  10454. data = json_tokener_parse(tempdata);
  10455. if(!is_error(data))
  10456. {
  10457. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10458. {
  10459. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10460. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10461. if(gun_index < gunTotalNumber)
  10462. {
  10463. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10464. {
  10465. json_object *responsedata = json_object_new_object();
  10466. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10467. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10468. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10469. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10470. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10471. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10472. }
  10473. else
  10474. {
  10475. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10476. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10477. }
  10478. }
  10479. else
  10480. {
  10481. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10482. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10483. }
  10484. }
  10485. else
  10486. {
  10487. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10488. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10489. }
  10490. }
  10491. else
  10492. {
  10493. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10494. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10495. }
  10496. json_object_put(data);
  10497. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10498. json_object_put(response);
  10499. }
  10500. else if(strstr(tempmessageId, "ID_OccupancyFeeDisplay") != NULL)
  10501. {
  10502. json_object *data;
  10503. data = json_tokener_parse(tempdata);
  10504. if(!is_error(data))
  10505. {
  10506. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10507. int gun_index = 0;
  10508. if(json_object_object_get(data, "ConnectorId") != NULL)
  10509. {
  10510. gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10511. if(json_object_object_get(data, "occupancySN") != NULL)
  10512. {
  10513. sprintf((char *)ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].occupancySN, "%s", json_object_get_string(json_object_object_get(data,"occupancySN")));
  10514. }
  10515. else
  10516. {
  10517. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10518. json_object_object_add(response, "data", json_object_new_string("occupancySN data can not get."));
  10519. }
  10520. if(json_object_object_get(data, "actionId") != NULL)
  10521. {
  10522. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].actionId = json_object_get_int(json_object_object_get(data,"actionId"));
  10523. }
  10524. else
  10525. {
  10526. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10527. json_object_object_add(response, "data", json_object_new_string("actionId data can not get."));
  10528. }
  10529. }
  10530. else
  10531. {
  10532. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10533. json_object_object_add(response, "data", json_object_new_string("ConnectorId data can not get."));
  10534. }
  10535. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10536. {
  10537. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].OccupancyFeeDisplayReq = 1;
  10538. }
  10539. }
  10540. else
  10541. {
  10542. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10543. json_object_object_add(response, "data", json_object_new_string("OccupancyFeeDisplay content got something wrong."));
  10544. }
  10545. json_object_put(data);
  10546. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10547. json_object_put(response);
  10548. }
  10549. else if(strstr(tempmessageId, "ID_SetOccupancyPrice") != NULL)
  10550. {
  10551. json_object *data;
  10552. data = json_tokener_parse(tempdata);
  10553. if(!is_error(data))
  10554. {
  10555. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10556. if(json_object_object_get(data, "price") != NULL)
  10557. {
  10558. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.price = json_object_get_double(json_object_object_get(data,"price"));
  10559. }
  10560. else
  10561. {
  10562. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10563. json_object_object_add(response, "data", json_object_new_string("price data can not get."));
  10564. }
  10565. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10566. {
  10567. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.SetOccupancyPriceReq = 1;
  10568. }
  10569. }
  10570. else
  10571. {
  10572. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10573. json_object_object_add(response, "data", json_object_new_string("SetOccupancyPrice content got something wrong."));
  10574. }
  10575. json_object_put(data);
  10576. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10577. json_object_put(response);
  10578. }
  10579. // Support ISO-15118 related message
  10580. else if(strstr(tempmessageId, "TriggerMessage") != NULL)
  10581. {
  10582. char cmdBuf[1024]={0};
  10583. 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);
  10584. system(cmdBuf);
  10585. ShmOCPP16Data->v2g_extend.SignCertificateReq = 1;
  10586. json_object *responsedata = json_object_new_object();
  10587. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10588. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10589. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10590. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10591. json_object_put(response);
  10592. }
  10593. else if(strstr(tempmessageId, "CertificateSigned") != NULL)
  10594. {
  10595. json_object *data;
  10596. data = json_tokener_parse(tempdata);
  10597. if(!is_error(data))
  10598. {
  10599. FILE *fp = fopen(CERTIFICATE_V2G, "w");
  10600. fprintf(fp, "%s", json_object_get_string(json_object_object_get(data, "certificateChain")));
  10601. fclose(fp);
  10602. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10603. json_object *responsedata = json_object_new_object();
  10604. if(certVerify(PRIVATE_KEY_V2G, CERTIFICATE_V2G) == PASS)
  10605. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10606. else
  10607. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10608. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10609. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10610. }
  10611. else
  10612. {
  10613. json_object *responsedata = json_object_new_object();
  10614. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10615. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10616. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10617. }
  10618. json_object_put(data);
  10619. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10620. json_object_put(response);
  10621. }
  10622. else if(strstr(tempmessageId, "DeleteCertificate") != NULL)
  10623. {
  10624. json_object *data;
  10625. data = json_tokener_parse(tempdata);
  10626. DEBUG_INFO("DeleteCertificate processing...\n");
  10627. if(!is_error(data))
  10628. {
  10629. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm") != NULL)
  10630. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm")));
  10631. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash") != NULL)
  10632. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash")));
  10633. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash") != NULL)
  10634. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash")));
  10635. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber") != NULL)
  10636. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber")));
  10637. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm);
  10638. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash);
  10639. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash);
  10640. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber);
  10641. char temp[256] = {0};
  10642. char compareData[256] = {0};
  10643. int isMatch = TRUE;
  10644. // Check certV2G
  10645. if(access(CERTIFICATE_V2G,F_OK) != -1)
  10646. {
  10647. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_SerialNumber, compareData);
  10648. if(strcmp(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber) != 0)
  10649. isMatch = FALSE;
  10650. if(isMatch == TRUE)
  10651. {
  10652. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerNameHash, compareData);
  10653. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  10654. isMatch = FALSE;
  10655. }
  10656. if(isMatch == TRUE)
  10657. {
  10658. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerKeyHash, compareData);
  10659. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  10660. isMatch = FALSE;
  10661. }
  10662. if(isMatch == TRUE)
  10663. {
  10664. sprintf(temp, "rm -f %s", CERTIFICATE_V2G);
  10665. system(temp);
  10666. json_object *responsedata = json_object_new_object();
  10667. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10668. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10669. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10670. }
  10671. else
  10672. {
  10673. json_object *responsedata = json_object_new_object();
  10674. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10675. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10676. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10677. }
  10678. }
  10679. else
  10680. {
  10681. json_object *responsedata = json_object_new_object();
  10682. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10683. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10684. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10685. }
  10686. }
  10687. else
  10688. {
  10689. json_object *responsedata = json_object_new_object();
  10690. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10691. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10692. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10693. }
  10694. json_object_put(data);
  10695. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10696. json_object_put(response);
  10697. }
  10698. else if(strstr(tempmessageId, "GetInstalledCertificateIds") != NULL)
  10699. {
  10700. json_object *data;
  10701. data = json_tokener_parse(tempdata);
  10702. if(!is_error(data))
  10703. {
  10704. /*
  10705. * TODO:
  10706. * 1. Query certificate to response
  10707. */
  10708. json_object *responsedata = json_object_new_object();
  10709. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10710. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10711. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10712. }
  10713. else
  10714. {
  10715. json_object *responsedata = json_object_new_object();
  10716. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10717. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10718. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10719. }
  10720. json_object_put(data);
  10721. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10722. json_object_put(response);
  10723. }
  10724. else if(strstr(tempmessageId, "InstallCertificate") != NULL)
  10725. {
  10726. json_object *data;
  10727. data = json_tokener_parse(tempdata);
  10728. if(!is_error(data))
  10729. {
  10730. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  10731. if(json_object_object_get(data, "certificateType") != NULL)
  10732. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(data, "certificateType")));
  10733. if(json_object_object_get(data, "certificate") != NULL)
  10734. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(data, "certificate")));
  10735. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType);
  10736. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10737. char temp[1024];
  10738. FILE *fp = fopen(tempCert, "w");
  10739. fprintf(fp, "%s", ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10740. fclose(fp);
  10741. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  10742. char strExpDate[30];
  10743. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  10744. fp = popen(temp, "r");
  10745. if(fp)
  10746. {
  10747. while(fgets(temp, sizeof(temp), fp) != NULL)
  10748. {
  10749. if(strstr(temp, "notAfter=") != NULL)
  10750. {
  10751. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  10752. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  10753. break;
  10754. }
  10755. }
  10756. }
  10757. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  10758. struct tm tmExpDate;
  10759. struct timeb tbExpDate;
  10760. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  10761. tbExpDate.time = mktime(&tmExpDate);
  10762. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  10763. {
  10764. DEBUG_INFO("The enddate is already expired...\n");
  10765. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Rejected");
  10766. }
  10767. else
  10768. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted");
  10769. if(strcmp((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted") == 0)
  10770. {
  10771. if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "V2GRootCertificate") != NULL)
  10772. {
  10773. if(access(ROOTCA_V2G,F_OK) != -1)
  10774. {
  10775. DEBUG_INFO("Existed V2GRootCertificate is found. Replacing...\n");
  10776. rename(ROOTCA_V2G, "/Storage/OCPP/rootCaV2g_fallback.pem");
  10777. rename(tempCert, ROOTCA_V2G);
  10778. }
  10779. else
  10780. {
  10781. DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
  10782. rename(tempCert, ROOTCA_V2G);
  10783. }
  10784. json_object *responsedata = json_object_new_object();
  10785. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10786. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10787. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10788. }
  10789. else if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "MORootCertificate") != NULL)
  10790. {
  10791. if(access(ROOTCA_MO,F_OK) != -1)
  10792. {
  10793. DEBUG_INFO("Existed MORootCertificate is found. Replacing...\n");
  10794. rename(ROOTCA_MO, "/Storage/OCPP/rootCaMo_fallback.pem");
  10795. rename(tempCert, ROOTCA_MO);
  10796. }
  10797. else
  10798. {
  10799. DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
  10800. rename(tempCert, ROOTCA_MO);
  10801. }
  10802. json_object *responsedata = json_object_new_object();
  10803. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10804. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10805. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10806. }
  10807. else
  10808. {
  10809. json_object *responsedata = json_object_new_object();
  10810. json_object_object_add(responsedata, "status", json_object_new_string("Failed"));
  10811. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10812. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10813. }
  10814. }
  10815. else
  10816. {
  10817. json_object *responsedata = json_object_new_object();
  10818. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10819. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10820. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10821. }
  10822. }
  10823. else
  10824. {
  10825. json_object *responsedata = json_object_new_object();
  10826. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10827. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10828. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10829. }
  10830. json_object_put(data);
  10831. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10832. json_object_put(response);
  10833. }
  10834. else
  10835. {
  10836. // Can not find valid message id
  10837. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10838. }
  10839. }
  10840. else
  10841. {
  10842. // Payload is null
  10843. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10844. }
  10845. LWS_Send(message);
  10846. return result;
  10847. }
  10848. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10849. {
  10850. mtrace();
  10851. int result = FAIL;
  10852. int connectorIdInt, durationInt;
  10853. char chargingRateUnitStr[4]={0};
  10854. char comfirmstr[20];
  10855. int confirmPeriods = 0;
  10856. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10857. json_object *GetCompositeSchedule;
  10858. GetCompositeSchedule = json_tokener_parse(payload);
  10859. if(!is_error(GetCompositeSchedule))
  10860. {
  10861. // Required data
  10862. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10863. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10864. else
  10865. connectorIdInt = -1;
  10866. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10867. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10868. else
  10869. durationInt = 86400;
  10870. // Optional data
  10871. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10872. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10873. }
  10874. json_object_put(GetCompositeSchedule);
  10875. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10876. if((connectorIdInt == 0) ||
  10877. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10878. {
  10879. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10880. struct StructChargingProfile tmpProfile[1];
  10881. if(strstr(chargingRateUnitStr, "W") != NULL)
  10882. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10883. else
  10884. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10885. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10886. {
  10887. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10888. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10889. }
  10890. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10891. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10892. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10893. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10894. {
  10895. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10896. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10897. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10898. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10899. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10900. {
  10901. confirmPeriods = idx;
  10902. break;
  10903. }
  10904. }
  10905. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10906. {
  10907. confirmPeriods += 1;
  10908. }
  10909. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10910. }
  10911. else
  10912. {
  10913. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10914. }
  10915. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10916. return result;
  10917. }
  10918. int handleGetConfigurationRequest(char *uuid, char *payload)
  10919. {
  10920. mtrace();
  10921. int result = FAIL;
  10922. int MaxKeySupported = 0;
  10923. int n_keys = 0;
  10924. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10925. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10926. json_object *GetConfiguration;
  10927. GetConfiguration = json_tokener_parse(payload);
  10928. if(!is_error(GetConfiguration))
  10929. {
  10930. // Optional data
  10931. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10932. {
  10933. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10934. {
  10935. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10936. n_keys = idx + 1;
  10937. }
  10938. }
  10939. }
  10940. json_object_put(GetConfiguration);
  10941. UnknownKeynum = 0;
  10942. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10943. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10944. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10945. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10946. if(n_keys != 0)
  10947. {
  10948. for(int i=0;i<n_keys;i++)
  10949. {
  10950. getKeyValue(requestKey[i]);
  10951. }
  10952. }
  10953. else
  10954. {
  10955. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10956. getKeyValue("");
  10957. }
  10958. processUnkownKey();
  10959. sendGetConfigurationConfirmation(uuid);
  10960. return result;
  10961. }
  10962. static char fnamePlusPath[100]={0};
  10963. static char fnamePWithNoPath[60]={0};
  10964. void checkUploadLog(void)
  10965. {
  10966. FILE *fp;
  10967. /* Open the command for reading. */
  10968. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10969. if (fp == NULL) {
  10970. DEBUG_WARN("Failed to run command\n" );
  10971. exit(1);
  10972. }
  10973. int ftppathlen = 0;
  10974. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10975. int i = 0;
  10976. /* Read the output a line at a time - output it. */
  10977. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10978. if(i==0)
  10979. {
  10980. ftppathlen = strlen(fnamePlusPath);
  10981. DEBUG_INFO("%s\n", fnamePlusPath);
  10982. fnamePlusPath[ftppathlen]='\0';
  10983. break;
  10984. }
  10985. i= i+1;
  10986. }
  10987. /* close */
  10988. pclose(fp);
  10989. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10990. {
  10991. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10992. {
  10993. fnamePlusPath[k]='\0';
  10994. }
  10995. }
  10996. i=1;
  10997. //char fname[60]={0};
  10998. while(i < ftppathlen)
  10999. {
  11000. int len=ftppathlen-i;
  11001. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  11002. {
  11003. DEBUG_INFO("compare '/' all right\n");
  11004. break;
  11005. }
  11006. i=i+1;
  11007. }
  11008. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  11009. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  11010. fnamePWithNoPath[i+1] = '\0';
  11011. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  11012. {
  11013. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  11014. {
  11015. fnamePWithNoPath[j]='\0';
  11016. }
  11017. }
  11018. FILE* fp1 = fopen(fnamePlusPath, "r");
  11019. if (fp1)
  11020. {
  11021. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  11022. // file exists
  11023. fclose(fp1);
  11024. }
  11025. else
  11026. {
  11027. // file doesn't exist
  11028. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  11029. }
  11030. }
  11031. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  11032. {
  11033. mtrace();
  11034. int result = FAIL;
  11035. time_t CurrentTime;
  11036. struct tm *tm;
  11037. pthread_t th_Status;
  11038. CurrentTime = time(NULL);
  11039. tm = localtime(&CurrentTime);
  11040. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  11041. 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);
  11042. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11043. if(!interLock.isGetDiagnosticGoing)
  11044. {
  11045. interLock.isGetDiagnosticGoing = 1;
  11046. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, payload);
  11047. sleep(1);
  11048. }
  11049. else
  11050. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  11051. return result;
  11052. }
  11053. void* GetDiagnosticsProcess(void* data)
  11054. {
  11055. pthread_detach(pthread_self());
  11056. mtrace();
  11057. int retriesInt=0, retryIntervalInt=0;
  11058. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  11059. 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};
  11060. int port=0;
  11061. int isSuccess = FALSE;
  11062. char cmdBuf[2048];
  11063. struct tm *tmNow;
  11064. time_t CurrentTime;
  11065. struct tm tmStart;
  11066. struct tm tmStop;
  11067. CurrentTime = time(NULL);
  11068. tmNow=localtime(&CurrentTime);
  11069. uint16_t targetYear, targetMonth;
  11070. json_object *GetDiagnostics;
  11071. DEBUG_INFO("GetDiagnosticsProcess...\n");
  11072. GetDiagnostics = json_tokener_parse(data);
  11073. if(!is_error(GetDiagnostics))
  11074. {
  11075. // Required data
  11076. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  11077. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  11078. // Optional data
  11079. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  11080. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  11081. else
  11082. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  11083. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  11084. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  11085. else
  11086. retryIntervalInt = 30;
  11087. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  11088. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  11089. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  11090. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  11091. }
  11092. json_object_put(GetDiagnostics);
  11093. // Pack log to compress file
  11094. 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) &&
  11095. (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))
  11096. {
  11097. // Pack system log
  11098. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11099. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  11100. targetYear = tmStart.tm_year;
  11101. targetMonth = tmStart.tm_mon;
  11102. do
  11103. {
  11104. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11105. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  11106. if(targetMonth+1>=13)
  11107. {
  11108. targetYear += 1;
  11109. targetMonth = 1;
  11110. }
  11111. else
  11112. {
  11113. targetMonth += 1;
  11114. }
  11115. }while((targetYear < (tmNow->tm_year+1900)) ||
  11116. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11117. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  11118. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  11119. system(cmdBuf);
  11120. // Pack charging & event log
  11121. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11122. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  11123. targetYear = tmStart.tm_year;
  11124. targetMonth = tmStart.tm_mon;
  11125. do
  11126. {
  11127. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11128. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*Ocpp*MessageLog*", cmdBuf, targetYear, targetMonth);
  11129. if(targetMonth+1>=13)
  11130. {
  11131. targetYear += 1;
  11132. targetMonth = 1;
  11133. }
  11134. else
  11135. {
  11136. targetMonth += 1;
  11137. }
  11138. }while((targetYear < (tmNow->tm_year+1900)) ||
  11139. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11140. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  11141. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  11142. system(cmdBuf);
  11143. // Combine log file
  11144. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  11145. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  11146. }
  11147. else
  11148. {
  11149. system("exec /root/logPackTools 'log' 6");
  11150. }
  11151. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11152. system(cmdBuf);
  11153. checkUploadLog();
  11154. //****************location*******************/
  11155. if(strcmp(locationstr,"")==0)
  11156. {
  11157. DEBUG_INFO("location is <Empty>!\n");
  11158. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11159. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11160. goto end;
  11161. }
  11162. memset(protocol, 0, ARRAY_SIZE(protocol));
  11163. memset(user, 0, ARRAY_SIZE(user) );
  11164. memset(password, 0, ARRAY_SIZE(password));
  11165. memset(host, 0, ARRAY_SIZE(host));
  11166. memset(path, 0, ARRAY_SIZE(path));
  11167. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11168. memset(host1, 0, ARRAY_SIZE(host1));
  11169. memset(path1, 0, ARRAY_SIZE(path1));
  11170. /*location: ftp://user:password@host:port/path*/
  11171. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  11172. if((access(fnamePlusPath,F_OK))!=-1)
  11173. {
  11174. DEBUG_INFO("fnamePlusPath exist.\n");
  11175. }
  11176. else
  11177. {
  11178. DEBUG_INFO("fnamePlusPath not exist!\n");
  11179. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11180. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11181. goto end;
  11182. }
  11183. if(strchr(locationstr,'@')==NULL)
  11184. {
  11185. sscanf(locationstr,
  11186. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11187. protocol, host, &port, path);
  11188. strcpy(user,"anonymous");
  11189. strcpy(password,"");
  11190. }
  11191. else
  11192. {
  11193. //DEBUG_INFO("pch=%s\n", pch);
  11194. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11195. protocol, user, password, host, &port, path);
  11196. }
  11197. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  11198. {
  11199. DEBUG_INFO("protocol is not ftp/http ! \n");
  11200. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11201. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11202. goto end;
  11203. }
  11204. if(strncmp(locationstr,"http", 4) == 0)
  11205. {
  11206. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11207. sprintf(ftppath,"/%s", path);
  11208. do
  11209. {
  11210. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11211. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11212. sleep(3);
  11213. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  11214. if(!isSuccess)
  11215. {
  11216. DEBUG_INFO("Diagnostics fail.\n");
  11217. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11218. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11219. sleep(retryIntervalInt);
  11220. }
  11221. else
  11222. {
  11223. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11224. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11225. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11226. }
  11227. retriesInt--;
  11228. }while((isSuccess == 0)&&(retriesInt >= 0));
  11229. }
  11230. else
  11231. {
  11232. sscanf(host,"%[^/]%s",host1, path1);
  11233. if(strlen(path) > 0)
  11234. sprintf(ftppath,"/%s", path);
  11235. else
  11236. sprintf(ftppath,"/%s", path1);
  11237. int ftppathlen=strlen(ftppath);
  11238. int i=1;
  11239. char filenametemp[50];
  11240. while(i < ftppathlen)
  11241. {
  11242. int len=ftppathlen-i;
  11243. if(ftppath[len]== 47) // '/' ascll code: 47
  11244. {
  11245. DEBUG_INFO("find '/' all right\n");
  11246. break;
  11247. }
  11248. i=i+1;
  11249. }
  11250. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11251. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11252. filenametemp[i+1] = 0;
  11253. if(port == 0)
  11254. port = 21;
  11255. do
  11256. {
  11257. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11258. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11259. sleep(3);
  11260. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  11261. if(!isSuccess)
  11262. {
  11263. DEBUG_INFO("Diagnostics fail.\n");
  11264. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11265. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11266. sleep(retryIntervalInt);
  11267. }
  11268. else
  11269. {
  11270. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11271. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11272. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11273. }
  11274. retriesInt--;
  11275. }while((!isSuccess)&&(retriesInt >= 0));
  11276. }
  11277. end:
  11278. system("rm -f /mnt/*");
  11279. sleep(5);
  11280. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11281. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11282. interLock.isGetDiagnosticGoing = 0;
  11283. pthread_exit(NULL);
  11284. }
  11285. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  11286. {
  11287. mtrace();
  11288. int result = FAIL;
  11289. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  11290. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  11291. {
  11292. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  11293. locallistVersion = -1;
  11294. }
  11295. else
  11296. {
  11297. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  11298. locallistVersion = 0;
  11299. OCPP_getListVerion();
  11300. }
  11301. //from db.OCPP_getListVerion
  11302. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  11303. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  11304. sendGetLocalListVersionConfirmation(uuid,"");
  11305. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  11306. return result;
  11307. }
  11308. int handleRemoteStartRequest(char *uuid, char *payload)
  11309. {
  11310. mtrace();
  11311. int result = PASS;
  11312. int connectorIdInt=-1;
  11313. int tempIndex = 0;
  11314. char comfirmstr[20]={0};
  11315. char cmdBuf[512];
  11316. json_object *RemoteStartTransaction;
  11317. FILE *fp;
  11318. DEBUG_INFO("handleRemoteStartRequest ...\n");
  11319. if(server_pending == TRUE)
  11320. {
  11321. result = FAIL;
  11322. }
  11323. RemoteStartTransaction = json_tokener_parse(payload);
  11324. if(!is_error(RemoteStartTransaction))
  11325. {
  11326. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  11327. {
  11328. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  11329. }
  11330. else
  11331. {
  11332. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11333. {
  11334. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  11335. {
  11336. connectorIdInt = (gun_index+1);
  11337. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  11338. break;
  11339. }
  11340. }
  11341. }
  11342. if(connectorIdInt == 0)
  11343. {
  11344. DEBUG_WARN("Connector id shall not equal 0.\n");
  11345. result = FAIL;
  11346. }
  11347. else if(json_object_object_get(RemoteStartTransaction, "idTag") == NULL)
  11348. {
  11349. DEBUG_WARN("idTag should not be NULL.\n");
  11350. result = FAIL;
  11351. }
  11352. else if(connectorIdInt == -1)
  11353. {
  11354. DEBUG_INFO("Connector id does not specific.\n");
  11355. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11356. {
  11357. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11358. // Required data
  11359. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11360. // Optional data
  11361. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11362. {
  11363. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11364. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11365. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11366. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11367. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11368. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11369. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11370. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11371. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11372. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11373. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11374. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11375. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11376. {
  11377. 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")));
  11378. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11379. 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"));
  11380. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11381. 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"));
  11382. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11383. 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")));
  11384. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11385. {
  11386. 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++)
  11387. {
  11388. 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"));
  11389. 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"));
  11390. 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)
  11391. 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"));
  11392. }
  11393. }
  11394. }
  11395. }
  11396. else
  11397. {
  11398. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11399. }
  11400. }
  11401. }
  11402. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11403. {
  11404. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11405. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11406. // Required data
  11407. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11408. // Optional data
  11409. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11410. {
  11411. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11412. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11413. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11414. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11415. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11416. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11417. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11418. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11419. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11420. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11421. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11422. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11423. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11424. {
  11425. 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")));
  11426. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11427. 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"));
  11428. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11429. 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"));
  11430. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11431. 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")));
  11432. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11433. {
  11434. 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++)
  11435. {
  11436. 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"));
  11437. 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"));
  11438. 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)
  11439. 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"));
  11440. }
  11441. }
  11442. }
  11443. }
  11444. else
  11445. {
  11446. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11447. }
  11448. }
  11449. else
  11450. {
  11451. DEBUG_WARN("Connector id is over maximun value.\n");
  11452. result = FAIL;
  11453. }
  11454. }
  11455. if(result == PASS)
  11456. {
  11457. if(connectorIdInt > 0)
  11458. {
  11459. //check Transaction active
  11460. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11461. {
  11462. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11463. {
  11464. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11465. }
  11466. else
  11467. {
  11468. tempIndex = connectorIdInt -1;
  11469. }
  11470. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11471. {
  11472. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11473. {
  11474. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11475. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11476. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11477. {
  11478. //Reserved
  11479. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11480. }
  11481. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11482. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11483. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11484. {
  11485. //Reserved
  11486. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11487. {
  11488. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11489. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11490. goto end;
  11491. }
  11492. }
  11493. else
  11494. {
  11495. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11496. {
  11497. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11498. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11499. goto end;
  11500. }
  11501. }//END FOR ELSE
  11502. }
  11503. }// END FOR CHAdeMO_QUANTITY
  11504. }
  11505. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11506. {
  11507. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11508. {
  11509. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11510. }
  11511. else
  11512. {
  11513. tempIndex = connectorIdInt -1;
  11514. }
  11515. for (int index = 0; index < CCS_QUANTITY; index++)
  11516. {
  11517. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11518. {
  11519. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11520. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11521. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11522. {
  11523. //Reserved
  11524. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11525. }
  11526. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11527. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11528. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11529. {
  11530. //Reserved
  11531. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11532. {
  11533. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11534. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11535. goto end;
  11536. }
  11537. }
  11538. else
  11539. {
  11540. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11541. {
  11542. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11543. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11544. goto end;
  11545. }
  11546. }// END FOR ELSE
  11547. }
  11548. }// END FOR CCS_QUANTITY
  11549. }
  11550. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11551. {
  11552. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11553. {
  11554. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11555. }
  11556. else
  11557. {
  11558. tempIndex = connectorIdInt -1;
  11559. }
  11560. for (int index = 0; index < GB_QUANTITY; index++)
  11561. {
  11562. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11563. {
  11564. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11565. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11566. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11567. {
  11568. //Reserved
  11569. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11570. }
  11571. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11572. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11573. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11574. {
  11575. //Reserved
  11576. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11577. {
  11578. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11579. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11580. goto end;
  11581. }
  11582. }
  11583. else
  11584. {
  11585. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11586. {
  11587. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11588. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11589. goto end;
  11590. }
  11591. }// END FOR ELSE
  11592. }
  11593. } // END FOR GB_QUANTITY
  11594. }
  11595. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11596. {
  11597. tempIndex = connectorIdInt -1;
  11598. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11599. {
  11600. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11601. {
  11602. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11603. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11604. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11605. {
  11606. //Reserved
  11607. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11608. }
  11609. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11610. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11611. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11612. {
  11613. //Reserved
  11614. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11615. {
  11616. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11617. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11618. goto end;
  11619. }
  11620. }
  11621. else
  11622. {
  11623. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11624. {
  11625. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11626. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11627. goto end;
  11628. }
  11629. }// END FOR ELSE
  11630. }
  11631. } // END FOR GB_QUANTITY
  11632. }
  11633. else
  11634. {
  11635. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11636. {
  11637. tempIndex = 2;
  11638. }
  11639. else
  11640. {
  11641. tempIndex = connectorIdInt -1;
  11642. }
  11643. for (int index = 0; index < AC_QUANTITY; index++)
  11644. {
  11645. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11646. {
  11647. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11648. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11649. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11650. {
  11651. //Reserved
  11652. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11653. }
  11654. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11655. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11656. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11657. {
  11658. //Reserved
  11659. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11660. {
  11661. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11662. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11663. goto end;
  11664. }
  11665. }
  11666. else
  11667. {
  11668. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11669. {
  11670. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11671. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11672. goto end;
  11673. }
  11674. }//END FOR ELSE
  11675. }
  11676. }// END FOR AC_QUANTITY
  11677. }
  11678. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11679. {
  11680. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11681. {
  11682. // Save profile to file
  11683. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11684. system(cmdBuf);
  11685. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11686. fp = fopen(cmdBuf, "w");
  11687. 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));
  11688. fclose(fp);
  11689. }
  11690. else
  11691. {
  11692. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11693. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11694. goto end;
  11695. }
  11696. }
  11697. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11698. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11699. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11700. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11701. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11702. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11703. }
  11704. else
  11705. {
  11706. uint8_t isHasIdleConnector = FALSE;
  11707. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11708. {
  11709. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11710. {
  11711. isHasIdleConnector = TRUE;
  11712. break;
  11713. }
  11714. }
  11715. if((isHasIdleConnector == TRUE) && !ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11716. {
  11717. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11718. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11719. {
  11720. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11721. {
  11722. // Save profile to file
  11723. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11724. system(cmdBuf);
  11725. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11726. fp = fopen(cmdBuf, "w");
  11727. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11728. fclose(fp);
  11729. refreshStartTimer(&clientTime.RemoteStartWait);
  11730. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11731. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11732. }
  11733. else
  11734. {
  11735. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11736. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11737. }
  11738. }
  11739. else
  11740. {
  11741. refreshStartTimer(&clientTime.RemoteStartWait);
  11742. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11743. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11744. }
  11745. }
  11746. else
  11747. {
  11748. DEBUG_INFO("There is not any connector is idle.\n");
  11749. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11750. }
  11751. }
  11752. }
  11753. else
  11754. {
  11755. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11756. }
  11757. end:
  11758. json_object_put(RemoteStartTransaction);
  11759. sendRemoteStartConfirmation(uuid, comfirmstr);
  11760. return result;
  11761. }
  11762. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11763. {
  11764. mtrace();
  11765. int result = FAIL;
  11766. int match = FALSE;
  11767. int GunNO = 0;
  11768. int tempIndex = 0;
  11769. int transactionIdInt=0;
  11770. int transactionIdIsNULL= TRUE;
  11771. char comfirmstr[20];
  11772. json_object *RemoteStopTransaction;
  11773. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11774. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11775. if(server_pending == TRUE)
  11776. {
  11777. return 0;
  11778. }
  11779. RemoteStopTransaction = json_tokener_parse(payload);
  11780. if(!is_error(RemoteStopTransaction))
  11781. {
  11782. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11783. {
  11784. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11785. transactionIdIsNULL = FALSE;
  11786. }
  11787. }
  11788. json_object_put(RemoteStopTransaction);
  11789. if(transactionIdIsNULL == FALSE)
  11790. {
  11791. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11792. {
  11793. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11794. {
  11795. //check Transaction active
  11796. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11797. {
  11798. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11799. {
  11800. tempIndex = ((gun_index==2) ? 1: 0);
  11801. }
  11802. else
  11803. {
  11804. tempIndex = gun_index;
  11805. }
  11806. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11807. {
  11808. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11809. {
  11810. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11811. {
  11812. match = TRUE;
  11813. GunNO = gun_index;
  11814. }
  11815. }
  11816. }// END FOR CHAdeMO_QUANTITY
  11817. }
  11818. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11819. {
  11820. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11821. {
  11822. tempIndex = ((gun_index==2) ? 1: 0);
  11823. }
  11824. else
  11825. {
  11826. tempIndex = gun_index;
  11827. }
  11828. for (int index = 0; index < CCS_QUANTITY; index++)
  11829. {
  11830. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11831. {
  11832. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11833. {
  11834. match = TRUE;
  11835. GunNO = gun_index;
  11836. }
  11837. }
  11838. }// END FOR CCS_QUANTITY
  11839. }
  11840. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11841. {
  11842. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11843. {
  11844. tempIndex = ((gun_index==2) ? 1: 0);
  11845. }
  11846. else
  11847. {
  11848. tempIndex = gun_index;
  11849. }
  11850. for (int index = 0; index < GB_QUANTITY; index++)
  11851. {
  11852. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11853. {
  11854. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11855. {
  11856. match = TRUE;
  11857. GunNO = gun_index;
  11858. }
  11859. }
  11860. }// END FOR GB_QUANTITY
  11861. }
  11862. else if(gunType[gun_index] == GUN_TYPE_DO)
  11863. {
  11864. tempIndex = gun_index;
  11865. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11866. {
  11867. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11868. {
  11869. 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
  11870. {
  11871. match = TRUE;
  11872. GunNO = gun_index;
  11873. }
  11874. }
  11875. }// END FOR GB_QUANTITY
  11876. }
  11877. else
  11878. {
  11879. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11880. {
  11881. tempIndex = 2;
  11882. }
  11883. else
  11884. {
  11885. tempIndex = gun_index;
  11886. }
  11887. for (int index = 0; index < AC_QUANTITY; index++)
  11888. {
  11889. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11890. {
  11891. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11892. {
  11893. match = TRUE;
  11894. GunNO = gun_index;
  11895. }
  11896. }
  11897. }// END FOR CHAdeMO_QUANTITY
  11898. } // END FOR AC ELSE
  11899. }// CHECK IF ResponseTransactionId == transactionIdInt
  11900. }//END FOR
  11901. if( match == TRUE)
  11902. {
  11903. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11904. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11905. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11906. }
  11907. else
  11908. {
  11909. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11910. }
  11911. }
  11912. else
  11913. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11914. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11915. return result;
  11916. }
  11917. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11918. {
  11919. mtrace();
  11920. int result = FAIL;
  11921. int connectorIdInt=0, reservationIdInt=0;
  11922. int tempIndex = 0;
  11923. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11924. char comfirmstr[20]={0};
  11925. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11926. int c = 0;
  11927. char *loc;
  11928. //char *ptr;
  11929. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11930. strcpy(sstrtemp, stringtrimspace(payload));
  11931. //***(1)connectorId ****/
  11932. c=0;
  11933. loc = strstr(sstrtemp, "connectorId");
  11934. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11935. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11936. {
  11937. sstr[c] = loc[strlen("connectorId")+2+c];
  11938. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11939. c++;
  11940. }
  11941. sstr[c] = '\0';
  11942. connectorIdInt = atoi(sstr);
  11943. //***(2)expiryDate ****/
  11944. loc = strstr(sstrtemp, "expiryDate");
  11945. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11946. c = 0;
  11947. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11948. {
  11949. sstr[c] = loc[3+strlen("expiryDate")+c];
  11950. c++;
  11951. }
  11952. sstr[c] = '\0';
  11953. strcpy(expiryDatestr, sstr);
  11954. //***(3)idTag ****/
  11955. loc = strstr(sstrtemp, "idTag");
  11956. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11957. c = 0;
  11958. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11959. {
  11960. sstr[c] = loc[3+strlen("idTag")+c];
  11961. c++;
  11962. }
  11963. sstr[c] = '\0';
  11964. strcpy(idTagstr, sstr);
  11965. //***(4)parentIdTag ****/
  11966. loc = strstr(sstrtemp, "parentIdTag");
  11967. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11968. c = 0;
  11969. if(loc == NULL)
  11970. {
  11971. strcpy(parentIdTagstr, "");
  11972. }
  11973. else
  11974. {
  11975. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11976. {
  11977. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11978. c++;
  11979. }
  11980. sstr[c] = '\0';
  11981. strcpy(parentIdTagstr, sstr);
  11982. }
  11983. //***(5)reservationId ****/
  11984. c=0;
  11985. loc = strstr(sstrtemp, "reservationId");
  11986. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11987. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11988. {
  11989. sstr[c] = loc[strlen("reservationId")+2+c];
  11990. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11991. c++;
  11992. }
  11993. sstr[c] = '\0';
  11994. reservationIdInt = atoi(sstr);
  11995. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11996. /*
  11997. enum SYSTEM_STATUS
  11998. {
  11999. SYS_MODE_BOOTING = 0,
  12000. SYS_MODE_IDLE = 1,
  12001. SYS_MODE_AUTHORIZING = 2,
  12002. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  12003. SYS_MODE_REASSIGN = 4,
  12004. SYS_MODE_PREPARING = 5,
  12005. SYS_MODE_PREPARE_FOR_EV = 6,
  12006. SYS_MODE_PREPARE_FOR_EVSE = 7,
  12007. SYS_MODE_CHARGING = 8,
  12008. SYS_MODE_TERMINATING = 9,
  12009. SYS_MODE_COMPLETE = 10,
  12010. SYS_MODE_ALARM = 11,
  12011. SYS_MODE_FAULT = 12,
  12012. SYS_MODE_RESERVATION = 13,
  12013. SYS_MODE_BOOKING = 14,
  12014. SYS_MODE_MAINTAIN = 15,
  12015. SYS_MODE_DEBUG = 16,
  12016. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  12017. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  12018. SYS_MODE_UPDATE = 19
  12019. };
  12020. */
  12021. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  12022. {
  12023. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12024. goto end;
  12025. }
  12026. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  12027. {
  12028. //check Transaction active
  12029. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  12030. {
  12031. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12032. {
  12033. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12034. }
  12035. else
  12036. {
  12037. tempIndex = connectorIdInt -1;
  12038. }
  12039. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12040. {
  12041. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12042. {
  12043. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12044. {
  12045. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12046. {
  12047. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12048. {
  12049. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  12050. {
  12051. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12052. }
  12053. else
  12054. {
  12055. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12056. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12057. }
  12058. }
  12059. 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'))
  12060. {
  12061. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12062. }
  12063. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12064. {
  12065. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12066. }
  12067. else
  12068. {
  12069. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12070. }
  12071. }
  12072. 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
  12073. {
  12074. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12075. }
  12076. }
  12077. else
  12078. {
  12079. //replace reservation
  12080. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12081. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12082. }
  12083. }
  12084. } // END FOR CHAdeMO_QUANTITY
  12085. }
  12086. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  12087. {
  12088. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12089. {
  12090. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12091. }
  12092. else
  12093. {
  12094. tempIndex = connectorIdInt -1;
  12095. }
  12096. for (int index = 0; index < CCS_QUANTITY; index++)
  12097. {
  12098. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12099. {
  12100. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12101. {
  12102. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12103. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12104. {
  12105. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12106. {
  12107. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  12108. {
  12109. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12110. }
  12111. else
  12112. {
  12113. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12114. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12115. }
  12116. }
  12117. 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'))
  12118. {
  12119. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12120. }
  12121. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  12122. {
  12123. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12124. }
  12125. else
  12126. {
  12127. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12128. }
  12129. }
  12130. 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
  12131. {
  12132. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12133. }
  12134. }
  12135. else
  12136. {
  12137. //replace reservation
  12138. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12139. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12140. }
  12141. }
  12142. } // END FOR CCS_QUANTITY
  12143. }
  12144. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  12145. {
  12146. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12147. {
  12148. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12149. }
  12150. else
  12151. {
  12152. tempIndex = connectorIdInt -1;
  12153. }
  12154. for (int index = 0; index < GB_QUANTITY; index++)
  12155. {
  12156. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12157. {
  12158. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12159. {
  12160. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12161. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12162. {
  12163. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12164. {
  12165. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  12166. {
  12167. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12168. }
  12169. else
  12170. {
  12171. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12172. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12173. }
  12174. }
  12175. 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'))
  12176. {
  12177. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12178. }
  12179. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12180. {
  12181. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12182. }
  12183. else
  12184. {
  12185. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12186. }
  12187. }
  12188. 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
  12189. {
  12190. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12191. }
  12192. }
  12193. else
  12194. {
  12195. //replace reservation
  12196. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12197. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12198. }
  12199. }
  12200. }// END FOR GB_QUANTITY
  12201. }
  12202. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  12203. {
  12204. tempIndex = connectorIdInt -1;
  12205. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12206. {
  12207. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12208. {
  12209. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  12210. {
  12211. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12212. 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
  12213. {
  12214. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12215. {
  12216. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  12217. {
  12218. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12219. }
  12220. else
  12221. {
  12222. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12223. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12224. }
  12225. }
  12226. 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'))
  12227. {
  12228. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12229. }
  12230. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12231. {
  12232. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12233. }
  12234. else
  12235. {
  12236. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12237. }
  12238. }
  12239. 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
  12240. {
  12241. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12242. }
  12243. }
  12244. else
  12245. {
  12246. //replace reservation
  12247. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12248. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12249. }
  12250. }
  12251. }// END FOR GB_QUANTITY
  12252. }
  12253. else
  12254. {
  12255. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12256. {
  12257. tempIndex = 2;
  12258. }
  12259. else
  12260. {
  12261. tempIndex = (connectorIdInt -1);
  12262. }
  12263. for (int index = 0; index < AC_QUANTITY; index++)
  12264. {
  12265. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12266. {
  12267. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12268. {
  12269. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12270. {
  12271. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12272. {
  12273. 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))
  12274. {
  12275. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12276. }
  12277. else
  12278. {
  12279. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12280. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12281. }
  12282. }
  12283. 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'))
  12284. {
  12285. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12286. }
  12287. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12288. {
  12289. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12290. }
  12291. else
  12292. {
  12293. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12294. }
  12295. }
  12296. 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
  12297. {
  12298. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12299. }
  12300. }
  12301. else
  12302. {
  12303. //replace reservation
  12304. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12305. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12306. }
  12307. }
  12308. } // END FOR AC_QUANTITY
  12309. }
  12310. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12311. }
  12312. else if(connectorIdInt == 0)
  12313. {
  12314. //check Transaction active
  12315. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12316. {
  12317. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12318. {
  12319. 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'))
  12320. {
  12321. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12322. goto end;
  12323. }
  12324. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12325. {
  12326. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12327. goto end;
  12328. }
  12329. 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
  12330. {
  12331. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12332. goto end;
  12333. }
  12334. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12335. {
  12336. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12337. goto end;
  12338. }
  12339. }
  12340. }// END FOR CHAdeMO_QUANTITY
  12341. for (int index = 0; index < CCS_QUANTITY; index++)
  12342. {
  12343. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12344. {
  12345. 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'))
  12346. {
  12347. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12348. goto end;
  12349. }
  12350. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12351. {
  12352. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12353. goto end;
  12354. }
  12355. 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
  12356. {
  12357. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12358. goto end;
  12359. }
  12360. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12361. {
  12362. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12363. goto end;
  12364. }
  12365. }
  12366. } // END FOR CCS_QUANTITY
  12367. for (int index = 0; index < GB_QUANTITY; index++)
  12368. {
  12369. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12370. {
  12371. 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'))
  12372. {
  12373. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12374. goto end;
  12375. }
  12376. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12377. {
  12378. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12379. goto end;
  12380. }
  12381. 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
  12382. {
  12383. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12384. goto end;
  12385. }
  12386. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12387. {
  12388. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12389. goto end;
  12390. }
  12391. }
  12392. } // END FOR GB_QUANTITY
  12393. for (int index = 0; index < AC_QUANTITY; index++)
  12394. {
  12395. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12396. {
  12397. 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'))
  12398. {
  12399. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12400. goto end;
  12401. }
  12402. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12403. {
  12404. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12405. goto end;
  12406. }
  12407. 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
  12408. {
  12409. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12410. goto end;
  12411. }
  12412. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12413. {
  12414. 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))
  12415. {
  12416. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12417. goto end;
  12418. }
  12419. }
  12420. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12421. {
  12422. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12423. goto end;
  12424. }
  12425. }
  12426. }// END FOR AC_QUANTITY
  12427. //The connectorId is 0
  12428. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12429. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12430. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12431. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12432. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12433. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12434. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12435. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12436. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12437. result = TRUE;
  12438. return result;
  12439. }
  12440. else
  12441. {
  12442. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12443. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12444. }
  12445. if(strcmp(comfirmstr,"Accepted") == 0)
  12446. {
  12447. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12448. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12449. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12450. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12451. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12452. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12453. result = TRUE;
  12454. return result;
  12455. }
  12456. end:
  12457. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12458. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12459. return result;
  12460. }
  12461. int handleResetRequest(char *uuid, char *payload)
  12462. {
  12463. mtrace();
  12464. int result = FAIL;
  12465. char sstr[10]={0},sstrtemp[30]={ 0 };
  12466. char typestr[10]={0};
  12467. char comfirmstr[20]={0};
  12468. int c = 0;
  12469. char *loc;
  12470. DEBUG_INFO("handleResetRequest...\n");
  12471. strcpy(sstrtemp, stringtrimspace(payload));
  12472. loc = strstr(sstrtemp, "type");
  12473. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12474. c = 0;
  12475. while (loc[3+strlen("type")+c] != '\"')
  12476. {
  12477. sstr[c] = loc[3+strlen("type")+c];
  12478. c++;
  12479. }
  12480. sstr[c] = '\0';
  12481. strcpy(typestr,sstr);
  12482. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12483. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12484. {
  12485. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12486. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12487. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12488. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12489. }
  12490. else
  12491. {
  12492. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12493. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12494. result = PASS;
  12495. }
  12496. sendResetConfirmation(uuid, comfirmstr);
  12497. return result;
  12498. }
  12499. int handleSendLocalListRequest(char *uuid, char *payload)
  12500. {
  12501. mtrace();
  12502. int result = FAIL;
  12503. char comfirmstr[20];
  12504. int checkState_Faulted = FALSE;
  12505. json_object *SendLocalList;
  12506. DEBUG_INFO("handleSendLocalListRequest...\n");
  12507. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12508. {
  12509. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12510. goto end;
  12511. }
  12512. //check Charge Point state
  12513. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12514. {
  12515. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12516. {
  12517. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12518. }
  12519. }
  12520. for (int index = 0; index < CCS_QUANTITY; index++)
  12521. {
  12522. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12523. {
  12524. checkState_Faulted = TRUE; //OCPP Status
  12525. }
  12526. }
  12527. for (int index = 0; index < GB_QUANTITY; index++)
  12528. {
  12529. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12530. {
  12531. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12532. }
  12533. }
  12534. //check Charge Point state
  12535. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12536. {
  12537. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12538. {
  12539. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12540. }
  12541. }
  12542. //check Charge Point state
  12543. for (int index = 0; index < AC_QUANTITY; index++)
  12544. {
  12545. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12546. {
  12547. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12548. }
  12549. }
  12550. if(checkState_Faulted == TRUE)
  12551. {
  12552. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12553. goto end;
  12554. }
  12555. // Parsing payload
  12556. SendLocalList = json_tokener_parse(payload);
  12557. if(!is_error(SendLocalList))
  12558. {
  12559. // Required data
  12560. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12561. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12562. // Optional data
  12563. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12564. {
  12565. //Check UpdateType
  12566. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12567. {
  12568. //Local list full update
  12569. DEBUG_INFO("Local list full update.\n");
  12570. locallistVersion = 0;
  12571. OCPP_getListVerion();
  12572. if((ShmOCPP16Data->SendLocalList.ListVersion > 0) && (ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion))
  12573. {
  12574. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12575. goto end;
  12576. }
  12577. OCPP_cleanLocalList();
  12578. }
  12579. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12580. {
  12581. //Local list different update
  12582. DEBUG_INFO("Local list different update.\n");
  12583. locallistVersion = 0;
  12584. OCPP_getListVerion();
  12585. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12586. {
  12587. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12588. goto end;
  12589. }
  12590. }
  12591. else
  12592. {
  12593. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12594. goto end;
  12595. }
  12596. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  12597. {
  12598. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  12599. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12600. goto end;
  12601. }
  12602. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12603. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12604. {
  12605. 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"))));
  12606. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12607. {
  12608. 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"))));
  12609. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12610. 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"))));
  12611. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12612. 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"))));
  12613. }
  12614. // Add to db
  12615. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12616. {
  12617. //Local list full update
  12618. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12619. idx,
  12620. ShmOCPP16Data->SendLocalList.ListVersion,
  12621. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12622. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12623. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12624. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12625. // update list
  12626. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12627. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12628. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12629. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12630. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12631. }
  12632. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12633. {
  12634. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12635. idx,
  12636. ShmOCPP16Data->SendLocalList.ListVersion,
  12637. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12638. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12639. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12640. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12641. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12642. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12643. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12644. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12645. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12646. }
  12647. }
  12648. }
  12649. else
  12650. {
  12651. //Check UpdateType
  12652. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12653. {
  12654. //Local list full update
  12655. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12656. OCPP_cleanLocalList();
  12657. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12658. goto end;
  12659. }
  12660. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12661. {
  12662. //Local list different update
  12663. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12664. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12665. goto end;
  12666. }
  12667. }
  12668. result = PASS;
  12669. }
  12670. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12671. end:
  12672. json_object_put(SendLocalList);
  12673. sendSendLocalListConfirmation(uuid, comfirmstr);
  12674. return result;
  12675. }
  12676. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12677. {
  12678. mtrace();
  12679. int result = FAIL;
  12680. struct StructSetChargingProfile SetProfileReq = {0};
  12681. int tempchargingProfileIdInt;
  12682. int tempstackLevelInt;
  12683. int chargingSchedulePeriodCount = 0;
  12684. char comfirmstr[20]={0};
  12685. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12686. char rmFileCmd[128]={0};
  12687. int profileQuantity = 0;
  12688. int replaceableProfileCnt = 0;
  12689. json_object *SetChargingProfile;
  12690. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12691. SetChargingProfile = json_tokener_parse(payload);
  12692. if(!is_error(SetChargingProfile))
  12693. {
  12694. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12695. {
  12696. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12697. }
  12698. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12699. {
  12700. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12701. {
  12702. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12703. }
  12704. else
  12705. {
  12706. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12707. DEBUG_WARN("Cannot find chargingProfileId field.");
  12708. goto end;
  12709. }
  12710. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12711. {
  12712. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12713. }
  12714. else
  12715. {
  12716. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12717. DEBUG_WARN("Cannot find stackLevel field.");
  12718. goto end;
  12719. }
  12720. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12721. {
  12722. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12723. }
  12724. else
  12725. {
  12726. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12727. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12728. goto end;
  12729. }
  12730. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12731. {
  12732. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12733. }
  12734. else
  12735. {
  12736. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12737. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12738. goto end;
  12739. }
  12740. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12741. {
  12742. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12743. }
  12744. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12745. {
  12746. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12747. }
  12748. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12749. {
  12750. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12751. }
  12752. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12753. {
  12754. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12755. }
  12756. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12757. {
  12758. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12759. {
  12760. 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")));
  12761. }
  12762. else
  12763. {
  12764. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12765. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12766. goto end;
  12767. }
  12768. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12769. {
  12770. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12771. }
  12772. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12773. {
  12774. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12775. }
  12776. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12777. {
  12778. 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")));
  12779. }
  12780. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12781. {
  12782. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12783. if(chargingSchedulePeriodCount <= 10)
  12784. {
  12785. 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++)
  12786. {
  12787. 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)
  12788. {
  12789. 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"));
  12790. }
  12791. else
  12792. {
  12793. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12794. DEBUG_WARN("Cannot find startPeriod field.");
  12795. goto end;
  12796. }
  12797. 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)
  12798. {
  12799. 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"));
  12800. }
  12801. else
  12802. {
  12803. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12804. DEBUG_WARN("Cannot find limit field.");
  12805. goto end;
  12806. }
  12807. 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)
  12808. {
  12809. 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"));
  12810. }
  12811. }
  12812. }
  12813. }
  12814. else
  12815. {
  12816. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12817. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12818. goto end;
  12819. }
  12820. }
  12821. else
  12822. {
  12823. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12824. DEBUG_WARN("Cannot find chargingSchedule field.");
  12825. goto end;
  12826. }
  12827. }
  12828. }
  12829. // Profile periods quantity check
  12830. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12831. {
  12832. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12833. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12834. goto end;
  12835. }
  12836. // Check invalid limit
  12837. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12838. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12839. {
  12840. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12841. {
  12842. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12843. {
  12844. 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)))) ||
  12845. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12846. {
  12847. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12848. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12849. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12850. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12851. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12852. goto end;
  12853. }
  12854. }
  12855. }
  12856. else
  12857. {
  12858. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12859. {
  12860. 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) ||
  12861. (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)))
  12862. {
  12863. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12864. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12865. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12866. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12867. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12868. goto end;
  12869. }
  12870. }
  12871. }
  12872. }
  12873. // Profile purpose info check
  12874. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12875. {
  12876. FILE *fp;
  12877. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12878. if(SetProfileReq.ConnectorId != 0)
  12879. {
  12880. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12881. DEBUG_WARN("Profile connector id is not 0.\n");
  12882. goto end;
  12883. }
  12884. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12885. if (!fp)
  12886. {
  12887. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12888. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12889. }
  12890. else
  12891. {
  12892. char *line = NULL;
  12893. size_t len = 0;
  12894. while(getline(&line, &len, fp) != -1)
  12895. {
  12896. json_object *obj = NULL;
  12897. obj = json_tokener_parse(line);
  12898. if(is_error(obj))
  12899. {
  12900. DEBUG_ERROR("Parse txProfile from file error.\n");
  12901. }
  12902. else
  12903. {
  12904. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12905. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12906. {
  12907. profileQuantity += 1;
  12908. }
  12909. else
  12910. replaceableProfileCnt += 1;
  12911. }
  12912. }
  12913. }
  12914. fclose(fp);
  12915. }
  12916. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12917. {
  12918. FILE *fp;
  12919. char filename[128]={0};
  12920. int tmpProfileQuantity;
  12921. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12922. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12923. {
  12924. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12925. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12926. goto end;
  12927. }
  12928. if(SetProfileReq.ConnectorId == 0)
  12929. {
  12930. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12931. {
  12932. tmpProfileQuantity = 0;
  12933. memset(filename, 0, ARRAY_SIZE(filename));
  12934. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12935. fp = fopen(filename, "r");
  12936. if (!fp)
  12937. {
  12938. DEBUG_INFO("%s does not create.\n", filename);
  12939. fp = fopen(filename, "w+");
  12940. }
  12941. else
  12942. {
  12943. char *line = NULL;
  12944. size_t len = 0;
  12945. while(getline(&line, &len, fp) != -1)
  12946. {
  12947. json_object *obj = NULL;
  12948. obj = json_tokener_parse(line);
  12949. if(is_error(obj))
  12950. {
  12951. DEBUG_ERROR("Parse txProfile from file error.\n");
  12952. }
  12953. else
  12954. {
  12955. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12956. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12957. {
  12958. tmpProfileQuantity += 1;
  12959. }
  12960. else
  12961. replaceableProfileCnt += 1;
  12962. }
  12963. }
  12964. }
  12965. fclose(fp);
  12966. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12967. }
  12968. }
  12969. else
  12970. {
  12971. memset(filename, 0, ARRAY_SIZE(filename));
  12972. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12973. fp = fopen(filename, "r");
  12974. if (!fp)
  12975. {
  12976. DEBUG_INFO("%s does not create.\n", filename);
  12977. fp = fopen(filename, "w+");
  12978. }
  12979. else
  12980. {
  12981. char *line = NULL;
  12982. size_t len = 0;
  12983. while(getline(&line, &len, fp) != -1)
  12984. {
  12985. json_object *obj = NULL;
  12986. obj = json_tokener_parse(line);
  12987. if(is_error(obj))
  12988. {
  12989. DEBUG_ERROR("Parse txProfile from file error.\n");
  12990. }
  12991. else
  12992. {
  12993. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12994. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12995. {
  12996. profileQuantity += 1;
  12997. }
  12998. else
  12999. replaceableProfileCnt += 1;
  13000. }
  13001. }
  13002. }
  13003. fclose(fp);
  13004. }
  13005. }
  13006. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  13007. {
  13008. int isMatchTransactiodId= FALSE;
  13009. FILE *fp;
  13010. char filename[128]={0};
  13011. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  13012. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  13013. if(SetProfileReq.ConnectorId == 0)
  13014. {
  13015. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13016. DEBUG_WARN("Profile connector id is 0.\n");
  13017. goto end;
  13018. }
  13019. int tempIndex = 0;
  13020. //check Transaction active
  13021. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  13022. {
  13023. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13024. {
  13025. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13026. }
  13027. else
  13028. {
  13029. tempIndex = SetProfileReq.ConnectorId -1;
  13030. }
  13031. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13032. {
  13033. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13034. {
  13035. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13036. {
  13037. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13038. {
  13039. isMatchTransactiodId = TRUE;
  13040. break;
  13041. }
  13042. }
  13043. }
  13044. }
  13045. }
  13046. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  13047. {
  13048. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13049. {
  13050. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13051. }
  13052. else
  13053. {
  13054. tempIndex = SetProfileReq.ConnectorId -1;
  13055. }
  13056. for (int index = 0; index < CCS_QUANTITY; index++)
  13057. {
  13058. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13059. {
  13060. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  13061. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13062. {
  13063. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13064. {
  13065. isMatchTransactiodId = TRUE;
  13066. break;
  13067. }
  13068. }
  13069. }
  13070. }
  13071. }
  13072. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  13073. {
  13074. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13075. {
  13076. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13077. }
  13078. else
  13079. {
  13080. tempIndex = SetProfileReq.ConnectorId -1;
  13081. }
  13082. for (int index = 0; index < GB_QUANTITY; index++)
  13083. {
  13084. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13085. {
  13086. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13087. {
  13088. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13089. {
  13090. isMatchTransactiodId = TRUE;
  13091. break;
  13092. }
  13093. }
  13094. }
  13095. }
  13096. }
  13097. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  13098. {
  13099. tempIndex = SetProfileReq.ConnectorId -1;
  13100. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13101. {
  13102. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13103. {
  13104. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  13105. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13106. {
  13107. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13108. {
  13109. isMatchTransactiodId = TRUE;
  13110. break;
  13111. }
  13112. }
  13113. }
  13114. }
  13115. }
  13116. else
  13117. {
  13118. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13119. {
  13120. tempIndex = 2;
  13121. }
  13122. else
  13123. {
  13124. tempIndex = (SetProfileReq.ConnectorId -1);
  13125. }
  13126. for (int index = 0; index < AC_QUANTITY; index++)
  13127. {
  13128. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13129. {
  13130. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  13131. {
  13132. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13133. {
  13134. isMatchTransactiodId = TRUE;
  13135. break;
  13136. }
  13137. }
  13138. }
  13139. }
  13140. }
  13141. //check Transaction active
  13142. if(isMatchTransactiodId == FALSE)
  13143. {
  13144. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13145. DEBUG_WARN("Tx profile transaction id is not match.\n");
  13146. goto end;
  13147. }
  13148. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13149. {
  13150. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13151. DEBUG_WARN("Connector id is over max gun number.\n");
  13152. goto end;
  13153. }
  13154. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13155. fp = fopen(filename, "r");
  13156. if (!fp)
  13157. {
  13158. DEBUG_INFO("%s does not create.\n", filename);
  13159. fp = fopen(filename, "w+");
  13160. }
  13161. else
  13162. {
  13163. char *line = NULL;
  13164. size_t len = 0;
  13165. while(getline(&line, &len, fp) != -1)
  13166. {
  13167. json_object *obj = NULL;
  13168. obj = json_tokener_parse(line);
  13169. if(is_error(obj))
  13170. {
  13171. DEBUG_ERROR("Parse txProfile from file error.\n");
  13172. }
  13173. else
  13174. {
  13175. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13176. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13177. {
  13178. profileQuantity += 1;
  13179. }
  13180. else
  13181. replaceableProfileCnt += 1;
  13182. }
  13183. }
  13184. }
  13185. fclose(fp);
  13186. }
  13187. // Check ChargeProfileMaxStackLevel
  13188. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  13189. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  13190. {
  13191. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13192. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13193. goto end;
  13194. }
  13195. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13196. {
  13197. FILE *fp;
  13198. char dataLine[4096]={0};
  13199. char fnametemp[128]={0};
  13200. int tmpProfileQuantity;
  13201. //Check ChargePointMaxProfile.json exit
  13202. profileQuantity = 0;
  13203. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  13204. {
  13205. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  13206. //Check Charging Profile Count
  13207. tmpProfileQuantity = 0;
  13208. while(fscanf(fp, "%s", dataLine) != EOF)
  13209. {
  13210. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13211. {
  13212. profileQuantity += 1;
  13213. tmpProfileQuantity += 1;
  13214. }
  13215. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13216. }
  13217. fclose(fp);
  13218. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  13219. }
  13220. //Check TxDefaultProfile_%d.json
  13221. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13222. {
  13223. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13224. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13225. if((access(fnametemp,F_OK))!=-1)
  13226. {
  13227. fp = fopen(fnametemp, "r");
  13228. //Check Charging Profile Count
  13229. tmpProfileQuantity = 0;
  13230. while(fscanf(fp, "%s", dataLine) != EOF)
  13231. {
  13232. //DEBUG_INFO("word=%s\n",word);
  13233. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13234. {
  13235. profileQuantity += 1;
  13236. tmpProfileQuantity += 1;
  13237. }
  13238. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13239. }
  13240. fclose(fp);
  13241. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13242. }
  13243. }
  13244. //Check TxProfile_%d.json
  13245. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13246. {
  13247. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13248. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  13249. if((access(fnametemp,F_OK))!=-1)
  13250. {
  13251. fp = fopen(fnametemp, "r");
  13252. //Check Charging Profile Count
  13253. tmpProfileQuantity = 0;
  13254. while(fscanf(fp, "%s", dataLine) != EOF)
  13255. {
  13256. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13257. {
  13258. profileQuantity += 1;
  13259. tmpProfileQuantity += 1;
  13260. }
  13261. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13262. }
  13263. fclose(fp);
  13264. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13265. }
  13266. }
  13267. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  13268. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  13269. // To check total Profile quantity
  13270. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  13271. {
  13272. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13273. {
  13274. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13275. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13276. goto end;
  13277. }
  13278. }
  13279. else
  13280. {
  13281. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13282. {
  13283. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13284. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13285. goto end;
  13286. }
  13287. }
  13288. }
  13289. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13290. //**********************************Write to File********************************************************/
  13291. {
  13292. FILE *infile;
  13293. FILE *outfile;
  13294. char dataLine[4096]={0};
  13295. char filename[128]={0};
  13296. int chkChar=0;
  13297. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  13298. {
  13299. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13300. {
  13301. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  13302. }
  13303. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13304. {
  13305. if(SetProfileReq.ConnectorId==0)
  13306. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13307. else
  13308. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13309. }
  13310. else
  13311. {
  13312. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13313. }
  13314. infile = fopen (filename, "r");
  13315. outfile = fopen (tempfile, "w");
  13316. chkChar = fgetc(infile);
  13317. rewind(infile);
  13318. if(chkChar == EOF)
  13319. {
  13320. // Profile is empty
  13321. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13322. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13323. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13324. fclose(infile);
  13325. fclose(outfile);
  13326. sprintf(rmFileCmd,"rm -f %s",filename);
  13327. system(rmFileCmd);
  13328. rename(tempfile, filename);
  13329. }
  13330. else
  13331. {
  13332. // Profile is not empty
  13333. int ChargingProfileAdded = FALSE;
  13334. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  13335. {
  13336. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  13337. json_object *tmpChargingProfile;
  13338. tmpChargingProfile = json_tokener_parse(dataLine);
  13339. if(!is_error(SetChargingProfile))
  13340. {
  13341. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13342. {
  13343. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13344. {
  13345. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13346. }
  13347. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13348. {
  13349. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13350. }
  13351. }
  13352. }
  13353. json_object_put(tmpChargingProfile);
  13354. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  13355. {
  13356. if(ChargingProfileAdded == FALSE)
  13357. {
  13358. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13359. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13360. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13361. ChargingProfileAdded = TRUE;
  13362. }
  13363. }
  13364. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13365. {
  13366. if(ChargingProfileAdded == FALSE)
  13367. {
  13368. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13369. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13370. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13371. ChargingProfileAdded = TRUE;
  13372. }
  13373. }
  13374. else
  13375. {
  13376. fprintf(outfile,"%s\n",dataLine);
  13377. if(ChargingProfileAdded == FALSE)
  13378. {
  13379. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13380. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13381. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13382. ChargingProfileAdded = TRUE;
  13383. }
  13384. }
  13385. } // end of while loop
  13386. fclose(infile);
  13387. fclose(outfile);
  13388. sprintf(rmFileCmd,"rm -f %s",filename);
  13389. system(rmFileCmd);
  13390. rename(tempfile, filename);
  13391. }
  13392. }
  13393. sleep(1);
  13394. result = TRUE;
  13395. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13396. }
  13397. end:
  13398. json_object_put(SetChargingProfile);
  13399. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13400. {
  13401. if(SetProfileReq.ConnectorId == 0)
  13402. {
  13403. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13404. {
  13405. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13406. }
  13407. }
  13408. else
  13409. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13410. }
  13411. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13412. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13413. return result;
  13414. }
  13415. int handleTriggerMessageRequest(char *uuid, char *payload)
  13416. {
  13417. mtrace();
  13418. int result = FAIL;
  13419. int connectorIdIsNULL = FALSE;
  13420. int connectorIdInt =0;
  13421. char sstr[40]={0},sstrtemp[100]={ 0 };
  13422. char requestedMessagestr[40]={0};
  13423. char comfirmstr[20]={0};
  13424. int c = 0;
  13425. char *loc;
  13426. DEBUG_INFO("handleTriggerMessageRequest\n");
  13427. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13428. strcpy(sstrtemp, stringtrimspace(payload));
  13429. c = 0;
  13430. loc = strstr(sstrtemp, "requestedMessage");
  13431. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13432. {
  13433. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13434. c++;
  13435. }
  13436. sstr[c] = '\0';
  13437. strcpy(requestedMessagestr, sstr);
  13438. c = 0;
  13439. loc = strstr(sstrtemp, "connectorId");
  13440. if(loc == NULL)
  13441. {
  13442. connectorIdIsNULL = TRUE;
  13443. }
  13444. else
  13445. {
  13446. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13447. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13448. {
  13449. sstr[c] = loc[strlen("connectorId")+2+c];
  13450. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13451. c++;
  13452. }
  13453. sstr[c] = '\0';
  13454. connectorIdInt = atoi(sstr);
  13455. }
  13456. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13457. {
  13458. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13459. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13460. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13461. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13462. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13463. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13464. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13465. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13466. {
  13467. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13468. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13469. return TRUE;
  13470. }
  13471. else
  13472. {
  13473. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13474. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13475. }
  13476. }
  13477. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13478. {
  13479. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13480. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13481. return TRUE;
  13482. }
  13483. //==========================
  13484. // Trigger message
  13485. //==========================
  13486. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13487. {
  13488. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13489. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13490. {
  13491. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13492. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13493. }
  13494. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13495. }
  13496. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13497. {
  13498. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13499. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13500. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13501. }
  13502. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13503. {
  13504. //sendBootNotificationRequest();
  13505. server_sign = FALSE;
  13506. }
  13507. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13508. {
  13509. refreshStartTimer(&clientTime.Heartbeat);
  13510. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13511. }
  13512. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13513. {
  13514. if(connectorIdIsNULL == FALSE)
  13515. {
  13516. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13517. {
  13518. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13519. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13520. }
  13521. }
  13522. else
  13523. {
  13524. for(int idx=0;idx< gunTotalNumber;idx++)
  13525. {
  13526. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13527. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13528. }
  13529. }
  13530. }
  13531. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13532. {
  13533. if(connectorIdIsNULL == FALSE)
  13534. {
  13535. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13536. {
  13537. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13538. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13539. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13540. }
  13541. }
  13542. else
  13543. {
  13544. for(int idx=0;idx< gunTotalNumber;idx++)
  13545. {
  13546. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13547. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13548. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13549. }
  13550. }
  13551. }
  13552. return result;
  13553. }
  13554. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13555. {
  13556. mtrace();
  13557. int result = FAIL;
  13558. int connectorIdInt =0;
  13559. char comfirmstr[20]={0};
  13560. int tempIndex = 0;
  13561. json_object *UnlockConnector;
  13562. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13563. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13564. UnlockConnector = json_tokener_parse(payload);
  13565. if(!is_error(UnlockConnector))
  13566. {
  13567. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13568. {
  13569. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13570. }
  13571. }
  13572. json_object_put(UnlockConnector);
  13573. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13574. if(gunTotalNumber == 0)
  13575. {
  13576. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13577. goto end;
  13578. }
  13579. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13580. {
  13581. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13582. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13583. goto end;
  13584. }
  13585. else
  13586. {
  13587. //check Transaction active
  13588. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13589. {
  13590. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13591. {
  13592. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13593. }
  13594. else
  13595. {
  13596. tempIndex = connectorIdInt -1;
  13597. }
  13598. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13599. {
  13600. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13601. {
  13602. //stop Transaction
  13603. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13604. }
  13605. }
  13606. }
  13607. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13608. {
  13609. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13610. {
  13611. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13612. }
  13613. else
  13614. {
  13615. tempIndex = connectorIdInt -1;
  13616. }
  13617. for (int index = 0; index < CCS_QUANTITY; index++)
  13618. {
  13619. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13620. {
  13621. //stop Transaction
  13622. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13623. }
  13624. }
  13625. }
  13626. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13627. {
  13628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13629. {
  13630. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13631. }
  13632. else
  13633. {
  13634. tempIndex = connectorIdInt -1;
  13635. }
  13636. for (int index = 0; index < GB_QUANTITY; index++)
  13637. {
  13638. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13639. {
  13640. //stop Transaction
  13641. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13642. }
  13643. }
  13644. }
  13645. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13646. {
  13647. tempIndex = connectorIdInt -1;
  13648. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13649. {
  13650. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13651. {
  13652. //stop Transaction
  13653. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13654. }
  13655. }
  13656. }
  13657. else
  13658. {
  13659. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13660. {
  13661. tempIndex = 2;
  13662. }
  13663. else
  13664. {
  13665. tempIndex = connectorIdInt-1;
  13666. }
  13667. for (int index = 0; index < AC_QUANTITY; index++)
  13668. {
  13669. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13670. {
  13671. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13672. }
  13673. }
  13674. }
  13675. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13676. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13677. result = TRUE;
  13678. return result;
  13679. }
  13680. end:
  13681. //json_object_put(obj); --- remove temporally
  13682. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13683. return result;
  13684. }
  13685. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13686. {
  13687. mtrace();
  13688. int result = FAIL;
  13689. pthread_t t;
  13690. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13691. sendUpdateFirmwareConfirmation(uuid);
  13692. if(!interLock.isUpdateFirmwareGoing)
  13693. {
  13694. interLock.isUpdateFirmwareGoing = 1;
  13695. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  13696. sleep(1);
  13697. }
  13698. else
  13699. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13700. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13701. return result;
  13702. }
  13703. void *UpdateFirmwareProcess(void *data)
  13704. {
  13705. pthread_detach(pthread_self());
  13706. mtrace();
  13707. int retriesInt =0, retryIntervalInt=0;
  13708. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13709. int port=0;
  13710. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13711. int isSuccess = 0;
  13712. char ftpbuf[1024];
  13713. char temp[1024];
  13714. char * pch;
  13715. json_object *UpdateFirmware;
  13716. UpdateFirmware = json_tokener_parse(data);
  13717. if(!is_error(UpdateFirmware))
  13718. {
  13719. // Required data
  13720. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13721. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13722. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13723. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13724. // Optional data
  13725. if(json_object_object_get(UpdateFirmware, "retries"))
  13726. {
  13727. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13728. }
  13729. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13730. {
  13731. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13732. }
  13733. }
  13734. json_object_put(UpdateFirmware);
  13735. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13736. memset(path, 0, ARRAY_SIZE(path));
  13737. // Wait retrieveData
  13738. if(strlen(retrieveDatestr) > 10)
  13739. {
  13740. do
  13741. {
  13742. sleep(1);
  13743. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13744. }
  13745. // Ready to download
  13746. system("rm -f /mnt/*");
  13747. if(strncmp(locationstr,"http", 4) == 0)
  13748. {
  13749. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13750. sprintf(ftppath,"/%s", path);
  13751. DEBUG_INFO("locationstr: %s\n", locationstr);
  13752. DEBUG_INFO("protocol: %s\n",protocol);
  13753. DEBUG_INFO("host: %s\n",host);
  13754. DEBUG_INFO("path: %s\n",path);
  13755. DEBUG_INFO("ftppath: %s\n",ftppath);
  13756. int ftppathlen=strlen(ftppath);
  13757. int i=1;
  13758. char filenametemp[50];
  13759. while(i < ftppathlen)
  13760. {
  13761. int len=ftppathlen-i;
  13762. if(ftppath[len]== 47) // '/' ascll code: 47
  13763. {
  13764. DEBUG_INFO("compare '/' all right\n");
  13765. break;
  13766. }
  13767. i=i+1;
  13768. }
  13769. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13770. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13771. filenametemp[i+1] = 0;
  13772. do
  13773. {
  13774. sleep(1);
  13775. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13776. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13777. sleep(1);
  13778. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13779. if(!isSuccess)
  13780. {
  13781. sleep(1);
  13782. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13783. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13784. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13785. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13786. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13787. }
  13788. else
  13789. {
  13790. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13791. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13792. }
  13793. retriesInt--;
  13794. }while((isSuccess == 0)&&(retriesInt >= 0));
  13795. }
  13796. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13797. {
  13798. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13799. memset(temp, 0, ARRAY_SIZE(temp));
  13800. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13801. strcpy(ftpbuf, locationstr);
  13802. int ftppathlen=strlen(ftpbuf);
  13803. int i=1;
  13804. char filenametemp[50];
  13805. while(i < ftppathlen)
  13806. {
  13807. int len=ftppathlen-i;
  13808. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13809. {
  13810. DEBUG_INFO(" compare '/' all right\n");
  13811. break;
  13812. }
  13813. i=i+1;
  13814. }
  13815. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13816. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13817. filenametemp[i+1] = 0;
  13818. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13819. pch=strchr(temp,'@');
  13820. if(pch==NULL)
  13821. {
  13822. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13823. protocol, host, &port, path);
  13824. strcpy(user,"anonymous");
  13825. strcpy(password,"");
  13826. }
  13827. else
  13828. {
  13829. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13830. protocol, user, host, &port, path);
  13831. }
  13832. sscanf(host,"%[^/]%s",host1, path1);
  13833. sprintf(ftppath,"%s:/%s", host,path);
  13834. if(port == 0)
  13835. {
  13836. port = 21;
  13837. }
  13838. do
  13839. {
  13840. sleep(1);
  13841. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13842. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13843. sleep(1);
  13844. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13845. if(!isSuccess)
  13846. {
  13847. //BulldogUtil.sleepMs(interval*1000);
  13848. DEBUG_INFO("Update firmware request and download file fail.\n");
  13849. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13850. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13851. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13852. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13853. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13854. }
  13855. else
  13856. {
  13857. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13858. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13859. }
  13860. retriesInt--;
  13861. }while((!isSuccess)&&(retriesInt >= 0));
  13862. }
  13863. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13864. {
  13865. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13866. memset(temp, 0, ARRAY_SIZE(temp));
  13867. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13868. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13869. int ftppathlen=strlen(ftpbuf);
  13870. int i=1;
  13871. char filenametemp[50];
  13872. while(i < ftppathlen)
  13873. {
  13874. int len=ftppathlen-i;
  13875. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13876. {
  13877. DEBUG_INFO(" compare '/' all right\n");
  13878. break;
  13879. }
  13880. i=i+1;
  13881. }
  13882. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13883. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13884. filenametemp[i+1] = 0;
  13885. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13886. pch=strchr(temp,'@');
  13887. if(pch==NULL)
  13888. {
  13889. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13890. protocol, host, &port, path);
  13891. strcpy(user,"anonymous");
  13892. strcpy(password,"");
  13893. }
  13894. else
  13895. {
  13896. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13897. protocol, user, password, host, &port, path);
  13898. }
  13899. sscanf(host,"%[^/]%s",host1, path1);
  13900. sprintf(ftppath,"%s", path1);
  13901. //DEBUG_INFO("protocol =%s\n",protocol);
  13902. //DEBUG_INFO("user =%s\n",user);
  13903. //DEBUG_INFO("password =%s\n",password);
  13904. //DEBUG_INFO("host1 =%s\n",host1);
  13905. //DEBUG_INFO("port =%d\n",port);
  13906. //DEBUG_INFO("path1 =%s\n",path1);
  13907. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13908. //ftpFile(host, user, password, port, ftppath, fname);
  13909. //download firmware pthred
  13910. if(port == 0)
  13911. {
  13912. port = 21;
  13913. }
  13914. do
  13915. {
  13916. sleep(1);
  13917. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13918. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13919. sleep(1);
  13920. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13921. if(!isSuccess)
  13922. {
  13923. //BulldogUtil.sleepMs(interval*1000);
  13924. DEBUG_INFO("Update firmware request and download file fail.\n");
  13925. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13926. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13927. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13928. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13929. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13930. }
  13931. else
  13932. {
  13933. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13934. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13935. }
  13936. retriesInt--;
  13937. }while((!isSuccess)&&(retriesInt >= 0));
  13938. }
  13939. else
  13940. {
  13941. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13942. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13943. sleep(1);
  13944. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13945. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13946. }
  13947. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)
  13948. {
  13949. sleep(3);
  13950. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13951. }
  13952. interLock.isUpdateFirmwareGoing = 0;
  13953. pthread_exit(NULL);
  13954. }
  13955. int handleCertificateSignedRequest(char *uuid, char *payload)
  13956. {
  13957. mtrace();
  13958. int result = PASS;
  13959. json_object *CertificateSigned;
  13960. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13961. CertificateSigned = json_tokener_parse(payload);
  13962. if(!is_error(CertificateSigned))
  13963. {
  13964. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13965. }
  13966. json_object_put(CertificateSigned);
  13967. FILE *fp = fopen("/Storage/OCPP/tempCP.pem", "w");
  13968. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13969. fclose(fp);
  13970. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13971. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13972. if(certVerify(PRIVATE_KEY_CP, "/Storage/OCPP/tempCP.pem") == PASS)
  13973. {
  13974. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13975. system("rm -f /Storage/OCPP/certCP_fallback.pem");
  13976. rename(CERTIFICATE_CP, "/Storage/OCPP/certCP_fallback.pem");
  13977. rename("/Storage/OCPP/tempCP.pem", CERTIFICATE_CP);
  13978. }
  13979. else
  13980. {
  13981. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Rejected");
  13982. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  13983. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  13984. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  13985. }
  13986. sendCertificateSignedConfirmation(uuid);
  13987. return result;
  13988. }
  13989. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13990. {
  13991. mtrace();
  13992. int result = PASS;
  13993. json_object *DeleteCertificate;
  13994. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13995. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  13996. DeleteCertificate = json_tokener_parse(payload);
  13997. if(!is_error(DeleteCertificate))
  13998. {
  13999. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  14000. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  14001. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  14002. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  14003. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14004. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  14005. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  14006. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  14007. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i]; i++)
  14008. {
  14009. ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i]);
  14010. }
  14011. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]; i++)
  14012. {
  14013. ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]);
  14014. }
  14015. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i]; i++)
  14016. {
  14017. ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i]);
  14018. }
  14019. char temp[256] = {0};
  14020. char compareData[256] = {0};
  14021. int isMatch = TRUE;
  14022. // Check CentralSystemRootCertificate
  14023. if(access(ROOTCA_CS,F_OK) != -1)
  14024. {
  14025. DEBUG_INFO("Checking CentralSystemRootCertificate...\n");
  14026. parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, compareData);
  14027. for(int i = 0; compareData[i]; i++)
  14028. {
  14029. compareData[i] = tolower(compareData[i]);
  14030. }
  14031. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14032. isMatch = FALSE;
  14033. if(isMatch == TRUE)
  14034. {
  14035. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, compareData);
  14036. for(int i = 0; compareData[i]; i++)
  14037. {
  14038. compareData[i] = tolower(compareData[i]);
  14039. }
  14040. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14041. isMatch = FALSE;
  14042. }
  14043. if(isMatch == TRUE)
  14044. {
  14045. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, compareData);
  14046. for(int i = 0; compareData[i]; i++)
  14047. {
  14048. compareData[i] = tolower(compareData[i]);
  14049. }
  14050. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14051. isMatch = FALSE;
  14052. }
  14053. if(isMatch == TRUE)
  14054. {
  14055. DEBUG_INFO("Deleting CentralSystemRootCertificate...\n");
  14056. sprintf(temp, "rm -f %s", ROOTCA_CS);
  14057. system(temp);
  14058. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14059. goto End;
  14060. }
  14061. }
  14062. // Check ManufacturerRootCertificate
  14063. if(access(ROOTCA_MFG,F_OK) != -1)
  14064. {
  14065. DEBUG_INFO("Checking ManufacturerRootCertificate...\n");
  14066. isMatch = TRUE;
  14067. parseCertInfo(ROOTCA_MFG, CERT_PARSE_SerialNumber, compareData);
  14068. for(int i = 0; compareData[i]; i++)
  14069. {
  14070. compareData[i] = tolower(compareData[i]);
  14071. }
  14072. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14073. isMatch = FALSE;
  14074. if(isMatch == TRUE)
  14075. {
  14076. parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerNameHash, compareData);
  14077. for(int i = 0; compareData[i]; i++)
  14078. {
  14079. compareData[i] = tolower(compareData[i]);
  14080. }
  14081. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14082. isMatch = FALSE;
  14083. }
  14084. if(isMatch == TRUE)
  14085. {
  14086. parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerKeyHash, compareData);
  14087. for(int i = 0; compareData[i]; i++)
  14088. {
  14089. compareData[i] = tolower(compareData[i]);
  14090. }
  14091. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14092. isMatch = FALSE;
  14093. }
  14094. if(isMatch == TRUE)
  14095. {
  14096. DEBUG_INFO("Deleting ManufacturerRootCertificate...\n");
  14097. sprintf(temp, "rm -f %s", ROOTCA_MFG);
  14098. system(temp);
  14099. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14100. goto End;
  14101. }
  14102. }
  14103. // Check certCP
  14104. if(access(CERTIFICATE_CP,F_OK) != -1)
  14105. {
  14106. DEBUG_INFO("Checking certCP...\n");
  14107. isMatch = TRUE;
  14108. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_SerialNumber, compareData);
  14109. for(int i = 0; compareData[i]; i++)
  14110. {
  14111. compareData[i] = tolower(compareData[i]);
  14112. }
  14113. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14114. isMatch = FALSE;
  14115. if(isMatch == TRUE)
  14116. {
  14117. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerNameHash, compareData);
  14118. for(int i = 0; compareData[i]; i++)
  14119. {
  14120. compareData[i] = tolower(compareData[i]);
  14121. }
  14122. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14123. isMatch = FALSE;
  14124. }
  14125. if(isMatch == TRUE)
  14126. {
  14127. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerKeyHash, compareData);
  14128. for(int i = 0; compareData[i]; i++)
  14129. {
  14130. compareData[i] = tolower(compareData[i]);
  14131. }
  14132. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14133. isMatch = FALSE;
  14134. }
  14135. if(isMatch == TRUE)
  14136. {
  14137. DEBUG_INFO("Deleting certCP...\n");
  14138. sprintf(temp, "rm -f %s", CERTIFICATE_CP);
  14139. system(temp);
  14140. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14141. goto End;
  14142. }
  14143. }
  14144. }
  14145. End:
  14146. json_object_put(DeleteCertificate);
  14147. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  14148. sendDeleteCertificateConfirmation(uuid);
  14149. return result;
  14150. }
  14151. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  14152. {
  14153. mtrace();
  14154. int result = PASS;
  14155. json_object *ExtendedTriggerMessage;
  14156. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  14157. ExtendedTriggerMessage = json_tokener_parse(payload);
  14158. if(!is_error(ExtendedTriggerMessage))
  14159. {
  14160. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  14161. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  14162. {
  14163. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  14164. }
  14165. else
  14166. {
  14167. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  14168. }
  14169. }
  14170. json_object_put(ExtendedTriggerMessage);
  14171. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  14172. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  14173. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  14174. {
  14175. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  14176. }
  14177. else
  14178. {
  14179. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  14180. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  14181. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  14182. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  14183. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  14184. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  14185. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  14186. {
  14187. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  14188. }
  14189. else
  14190. {
  14191. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  14192. }
  14193. }
  14194. sendExtendedTriggerMessageConfirmation(uuid);
  14195. //==========================
  14196. // Trigger message
  14197. //==========================
  14198. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  14199. {
  14200. //sendBootNotificationRequest();
  14201. server_sign = FALSE;
  14202. }
  14203. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  14204. {
  14205. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14206. }
  14207. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  14208. {
  14209. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  14210. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  14211. {
  14212. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  14213. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  14214. }
  14215. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14216. }
  14217. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  14218. {
  14219. refreshStartTimer(&clientTime.Heartbeat);
  14220. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  14221. }
  14222. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  14223. {
  14224. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14225. {
  14226. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  14227. }
  14228. else
  14229. {
  14230. for(int idx=0;idx< gunTotalNumber;idx++)
  14231. {
  14232. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  14233. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  14234. }
  14235. }
  14236. }
  14237. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  14238. {
  14239. char cmdBuf[1024]={0};
  14240. 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);
  14241. system(cmdBuf);
  14242. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  14243. }
  14244. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  14245. {
  14246. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14247. {
  14248. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  14249. }
  14250. else
  14251. {
  14252. for(int idx=0;idx< gunTotalNumber;idx++)
  14253. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  14254. }
  14255. }
  14256. return result;
  14257. }
  14258. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  14259. {
  14260. mtrace();
  14261. int result = PASS;
  14262. json_object *GetInstalledCertificateIds;
  14263. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  14264. GetInstalledCertificateIds = json_tokener_parse(payload);
  14265. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  14266. if(!is_error(GetInstalledCertificateIds))
  14267. {
  14268. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  14269. DEBUG_INFO("Requested Certificate: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14270. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "Accepted");
  14271. DEBUG_INFO("Access ROOTCA_CS result: %d\n", access(ROOTCA_CS,F_OK));
  14272. // Check CentralSystemRootCertificate
  14273. if(strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "CentralSystemRootCertificate")!= NULL)
  14274. {
  14275. if(access(ROOTCA_CS,F_OK) != -1)
  14276. {
  14277. char parseData[512] = {0};
  14278. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14279. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14280. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, parseData) == PASS)
  14281. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14282. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14283. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14284. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14285. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14286. }
  14287. else
  14288. {
  14289. DEBUG_INFO(">>> No CentralSystemRootCertificate was found.\n");
  14290. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14291. }
  14292. }
  14293. // Check ManufacturerRootCertificate
  14294. else if(strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "ManufacturerRootCertificate") != NULL)
  14295. {
  14296. if(access(ROOTCA_MFG,F_OK) != -1)
  14297. {
  14298. char parseData[512] = {0};
  14299. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14300. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14301. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_SerialNumber, parseData) == PASS)
  14302. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14303. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14304. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14305. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14306. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14307. }
  14308. else
  14309. {
  14310. DEBUG_INFO(">>> No ManufacturerRootCertificate was found.\n");
  14311. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14312. }
  14313. }
  14314. else
  14315. {
  14316. DEBUG_INFO(">>> No %s was found.\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14317. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14318. }
  14319. }
  14320. json_object_put(GetInstalledCertificateIds);
  14321. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  14322. sendGetInstalledCertificateIdsConfirmation(uuid);
  14323. return result;
  14324. }
  14325. void* GetLogProcess(void* data)
  14326. {
  14327. pthread_detach(pthread_self());
  14328. mtrace();
  14329. 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};
  14330. int port=0;
  14331. int isSuccess = FALSE;
  14332. char cmdBuf[2048];
  14333. struct tm *tmNow;
  14334. time_t CurrentTime;
  14335. struct tm tmStart;
  14336. struct tm tmStop;
  14337. CurrentTime = time(NULL);
  14338. tmNow=localtime(&CurrentTime);
  14339. uint16_t targetYear, targetMonth;
  14340. json_object *GetLog;
  14341. DEBUG_INFO("GetLogProcess...\n");
  14342. GetLog = json_tokener_parse(data);
  14343. if(!is_error(GetLog))
  14344. {
  14345. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  14346. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  14347. if(json_object_object_get(GetLog, "retries") != NULL)
  14348. {
  14349. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  14350. }
  14351. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  14352. {
  14353. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  14354. }
  14355. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  14356. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  14357. {
  14358. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  14359. }
  14360. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  14361. {
  14362. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  14363. }
  14364. }
  14365. json_object_put(GetLog);
  14366. // Pack log to compress file
  14367. 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) &&
  14368. (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))
  14369. {
  14370. // Pack system log
  14371. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14372. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14373. targetYear = tmStart.tm_year;
  14374. targetMonth = tmStart.tm_mon;
  14375. do
  14376. {
  14377. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14378. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  14379. if(targetMonth+1>=13)
  14380. {
  14381. targetYear += 1;
  14382. targetMonth = 1;
  14383. }
  14384. else
  14385. {
  14386. targetMonth += 1;
  14387. }
  14388. }while((targetYear < (tmNow->tm_year+1900)) ||
  14389. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14390. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  14391. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  14392. system(cmdBuf);
  14393. // Pack charging & event log
  14394. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14395. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  14396. targetYear = tmStart.tm_year;
  14397. targetMonth = tmStart.tm_mon;
  14398. do
  14399. {
  14400. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14401. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  14402. if(targetMonth+1>=13)
  14403. {
  14404. targetYear += 1;
  14405. targetMonth = 1;
  14406. }
  14407. else
  14408. {
  14409. targetMonth += 1;
  14410. }
  14411. }while((targetYear < (tmNow->tm_year+1900)) ||
  14412. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14413. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  14414. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  14415. system(cmdBuf);
  14416. // Combine log file
  14417. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  14418. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  14419. }
  14420. else
  14421. {
  14422. system("exec /root/logPackTools 'log' 6");
  14423. }
  14424. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetLog.Response_filename);
  14425. system(cmdBuf);
  14426. checkUploadLog();
  14427. //****************location*******************/
  14428. if(strcmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"")==0)
  14429. {
  14430. DEBUG_INFO("location is <Empty>!\n");
  14431. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14432. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14433. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14434. goto end;
  14435. }
  14436. memset(protocol, 0, ARRAY_SIZE(protocol));
  14437. memset(user, 0, ARRAY_SIZE(user) );
  14438. memset(password, 0, ARRAY_SIZE(password));
  14439. memset(host, 0, ARRAY_SIZE(host));
  14440. memset(path, 0, ARRAY_SIZE(path));
  14441. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14442. memset(host1, 0, ARRAY_SIZE(host1));
  14443. memset(path1, 0, ARRAY_SIZE(path1));
  14444. /*location: ftp://user:password@host:port/path*/
  14445. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  14446. if((access(fnamePlusPath,F_OK))!=-1)
  14447. {
  14448. DEBUG_INFO("fnamePlusPath exist.\n");
  14449. }
  14450. else
  14451. {
  14452. DEBUG_INFO("fnamePlusPath not exist!\n");
  14453. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14454. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14455. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14456. goto end;
  14457. }
  14458. if(strchr((char*)ShmOCPP16Data->GetLog.log.remoteLocation,'@')==NULL)
  14459. {
  14460. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,
  14461. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14462. protocol, host, &port, path);
  14463. strcpy(user,"anonymous");
  14464. strcpy(password,"");
  14465. }
  14466. else
  14467. {
  14468. //DEBUG_INFO("pch=%s\n", pch);
  14469. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14470. protocol, user, password, host, &port, path);
  14471. }
  14472. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  14473. {
  14474. DEBUG_INFO("protocol is not ftp/http ! \n");
  14475. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14476. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14477. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14478. goto end;
  14479. }
  14480. if(strncmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"http", 4) == 0)
  14481. {
  14482. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14483. sprintf(ftppath,"/%s", path);
  14484. do
  14485. {
  14486. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14487. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14488. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14489. sleep(3);
  14490. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, (char*)ShmOCPP16Data->GetLog.log.remoteLocation);
  14491. if(!isSuccess)
  14492. {
  14493. DEBUG_INFO("Diagnostics fail.\n");
  14494. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14495. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14496. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14497. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14498. }
  14499. else
  14500. {
  14501. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14502. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14503. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14504. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14505. }
  14506. ShmOCPP16Data->GetLog.retries--;
  14507. }while((isSuccess == 0)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14508. }
  14509. else
  14510. {
  14511. sscanf(host,"%[^/]%s",host1, path1);
  14512. if(strlen(path) > 0)
  14513. sprintf(ftppath,"/%s", path);
  14514. else
  14515. sprintf(ftppath,"/%s", path1);
  14516. int ftppathlen=strlen(ftppath);
  14517. int i=1;
  14518. char filenametemp[50];
  14519. while(i < ftppathlen)
  14520. {
  14521. int len=ftppathlen-i;
  14522. if(ftppath[len]== 47) // '/' ascll code: 47
  14523. {
  14524. DEBUG_INFO("find '/' all right\n");
  14525. break;
  14526. }
  14527. i=i+1;
  14528. }
  14529. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14530. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  14531. filenametemp[i+1] = 0;
  14532. if(port == 0)
  14533. port = 21;
  14534. do
  14535. {
  14536. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14537. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14538. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14539. sleep(3);
  14540. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  14541. if(!isSuccess)
  14542. {
  14543. DEBUG_INFO("Diagnostics fail.\n");
  14544. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14545. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14546. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14547. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14548. }
  14549. else
  14550. {
  14551. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14552. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14553. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14554. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14555. }
  14556. ShmOCPP16Data->GetLog.retries--;
  14557. }while((!isSuccess)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14558. }
  14559. end:
  14560. system("rm -f /mnt/*");
  14561. sleep(5);
  14562. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14563. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Idle");
  14564. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14565. interLock.isGetDiagnosticGoing = 0;
  14566. pthread_exit(NULL);
  14567. }
  14568. int handleGetLogRequest(char *uuid, char *payload)
  14569. {
  14570. mtrace();
  14571. int result = PASS;
  14572. time_t CurrentTime;
  14573. struct tm *tm;
  14574. DEBUG_INFO("handleGetLogRequest...\n");
  14575. pthread_t th_Status;
  14576. CurrentTime = time(NULL);
  14577. tm = localtime(&CurrentTime);
  14578. memset(ShmOCPP16Data->GetLog.Response_filename, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetLog.Response_filename));
  14579. 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);
  14580. if(!interLock.isGetDiagnosticGoing)
  14581. {
  14582. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Accepted");
  14583. interLock.isGetDiagnosticGoing = 1;
  14584. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  14585. sleep(1);
  14586. }
  14587. else
  14588. {
  14589. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  14590. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  14591. }
  14592. sendGetLogConfirmation(uuid);
  14593. return result;
  14594. }
  14595. int handleInstallCertificateRequest(char *uuid, char *payload)
  14596. {
  14597. mtrace();
  14598. int result = PASS;
  14599. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  14600. json_object *InstallCertificate;
  14601. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14602. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14603. InstallCertificate = json_tokener_parse(payload);
  14604. if(!is_error(InstallCertificate))
  14605. {
  14606. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14607. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14608. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  14609. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  14610. char temp[1024];
  14611. FILE *fp = fopen(tempCert, "w");
  14612. fprintf(fp, "%s", ShmOCPP16Data->InstallCertificate.certificate);
  14613. fclose(fp);
  14614. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  14615. char strExpDate[30];
  14616. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  14617. fp = popen(temp, "r");
  14618. if(fp)
  14619. {
  14620. while(fgets(temp, sizeof(temp), fp) != NULL)
  14621. {
  14622. if(strstr(temp, "notAfter=") != NULL)
  14623. {
  14624. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14625. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  14626. break;
  14627. }
  14628. }
  14629. }
  14630. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  14631. struct tm tmExpDate;
  14632. struct timeb tbExpDate;
  14633. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  14634. tbExpDate.time = mktime(&tmExpDate);
  14635. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  14636. {
  14637. DEBUG_INFO("The enddate is already expired...\n");
  14638. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14639. goto End;
  14640. }
  14641. // Verify certificate with rootCA
  14642. sprintf(temp ,"openssl verify -CAfile /root/cacert.pem /Storage/OCPP/tempInstallCertificate.pem");
  14643. fp = popen(temp, "r");
  14644. if(fp)
  14645. {
  14646. while(fgets(temp, sizeof(temp), fp) != NULL)
  14647. {
  14648. if((strstr(temp, "tempInstallCertificate.pem: OK") != NULL) || (strstr(temp, "self signed certificate") != NULL))
  14649. {
  14650. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14651. break;
  14652. }
  14653. else
  14654. {
  14655. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14656. }
  14657. }
  14658. }
  14659. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14660. {
  14661. //=====================================================
  14662. // Verify if the certificate is valid or not. (OCSP?)
  14663. //=====================================================
  14664. /*
  14665. DEBUG_INFO("openssl CA verifying...FAIL --> Start OCSP process...\n");
  14666. // Get ocsp url
  14667. char ocspUrl[512];
  14668. sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", tempCert);
  14669. fp = popen(temp, "r");
  14670. if(fp)
  14671. {
  14672. while(fgets(temp, sizeof(temp), fp) != NULL)
  14673. {
  14674. if(strstr(temp, "://") != NULL)
  14675. {
  14676. strcpy(ocspUrl, temp);
  14677. break;
  14678. }
  14679. }
  14680. }
  14681. // Get certificate chain for issuer
  14682. * openssl s_client -connect [serverURL:port] -showcerts | sed -n '/-----BEGIN/,/-------END/p' > tempChain.pem
  14683. *
  14684. // Execute OCSP
  14685. sprintf(temp ,"openssl ocsp -issuer tempChain.pem -cert /Storage/OCPP/tempInstallCertificate.pem -text -url %s", ocspUrl);
  14686. fp = popen(temp, "r");
  14687. if(fp)
  14688. {
  14689. while(fgets(temp, sizeof(temp), fp) != NULL)
  14690. {
  14691. if(strstr(temp, "tempInstallCertificate.pem: good") != NULL)
  14692. {
  14693. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14694. break;
  14695. }
  14696. }
  14697. }
  14698. system("rm -f /Storage/OCPP/tempChain.pem");
  14699. pclose(fp);
  14700. */
  14701. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14702. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14703. {
  14704. DEBUG_INFO("OCSP verifying...FAIL.\n");
  14705. goto End;
  14706. }
  14707. else
  14708. DEBUG_INFO("OCSP verifying...PASS.\n");
  14709. }
  14710. else
  14711. DEBUG_INFO("openssl CA verifying...PASS.\n");
  14712. }
  14713. End:
  14714. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") == 0)
  14715. {
  14716. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "CentralSystemRootCertificate") == 0)
  14717. {
  14718. if(access(ROOTCA_CS,F_OK) != -1)
  14719. {
  14720. DEBUG_INFO("Existed CentralSystemRootCertificate is found. Replacing...\n");
  14721. rename(ROOTCA_CS, "/Storage/OCPP/CentralSystemRootCertificate_fallback.pem");
  14722. rename(tempCert, ROOTCA_CS);
  14723. }
  14724. else
  14725. {
  14726. DEBUG_INFO("No existed CentralSystemRootCertificate. Creating...\n");
  14727. rename(tempCert, ROOTCA_CS);
  14728. }
  14729. }
  14730. else if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "ManufacturerRootCertificate") == 0)
  14731. {
  14732. if(access(ROOTCA_MFG,F_OK) != -1)
  14733. {
  14734. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14735. rename(ROOTCA_MFG, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14736. rename(tempCert, ROOTCA_MFG);
  14737. }
  14738. else
  14739. {
  14740. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14741. rename(tempCert, ROOTCA_MFG);
  14742. }
  14743. }
  14744. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  14745. }
  14746. sendInstallCertificateConfirmation(uuid);
  14747. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14748. {
  14749. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidCentralSystemCertificate");
  14750. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14751. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14752. }
  14753. json_object_put(InstallCertificate);
  14754. return result;
  14755. }
  14756. void *SignedUpdateFirmwareProcess(void *data)
  14757. {
  14758. pthread_detach(pthread_self());
  14759. mtrace();
  14760. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  14761. int port=0;
  14762. int isSuccess = 0;
  14763. char ftpbuf[1024];
  14764. char temp[1024];
  14765. char * pch;
  14766. char firmwareFileName[50];
  14767. DEBUG_INFO("SignedUpdateFirmwareProcess ...\n");
  14768. json_object *SignedUpdateFirmware;
  14769. SignedUpdateFirmware = json_tokener_parse(data);
  14770. if(!is_error(SignedUpdateFirmware))
  14771. {
  14772. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  14773. {
  14774. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  14775. }
  14776. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  14777. {
  14778. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  14779. }
  14780. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  14781. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  14782. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  14783. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  14784. {
  14785. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  14786. }
  14787. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  14788. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  14789. }
  14790. json_object_put(SignedUpdateFirmware);
  14791. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14792. memset(path, 0, ARRAY_SIZE(path));
  14793. // Wait retrieveData
  14794. if(strlen((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location) > 10)
  14795. {
  14796. do
  14797. {
  14798. sleep(1);
  14799. }while(!isOvertNow((uint8_t*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime));
  14800. }
  14801. // Ready to download
  14802. system("rm -f /mnt/*");
  14803. if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"http", 4) == 0)
  14804. {
  14805. sscanf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14806. sprintf(ftppath,"/%s", path);
  14807. DEBUG_INFO("locationstr: %s\n", (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14808. DEBUG_INFO("protocol: %s\n",protocol);
  14809. DEBUG_INFO("host: %s\n",host);
  14810. DEBUG_INFO("path: %s\n",path);
  14811. DEBUG_INFO("ftppath: %s\n",ftppath);
  14812. int ftppathlen=strlen(ftppath);
  14813. int i=1;
  14814. while(i < ftppathlen)
  14815. {
  14816. int len=ftppathlen-i;
  14817. if(ftppath[len]== 47) // '/' ascll code: 47
  14818. {
  14819. DEBUG_INFO("compare '/' all right\n");
  14820. break;
  14821. }
  14822. i=i+1;
  14823. }
  14824. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14825. strncpy(firmwareFileName, ftppath+(ftppathlen-i+1), i+1);
  14826. firmwareFileName[i+1] = 0;
  14827. do
  14828. {
  14829. sleep(1);
  14830. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14831. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14832. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14833. sleep(1);
  14834. isSuccess = httpDownLoadFile(host, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14835. if(!isSuccess)
  14836. {
  14837. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14838. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14839. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14840. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14841. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14842. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14843. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14844. }
  14845. else
  14846. {
  14847. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14848. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14849. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14850. }
  14851. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14852. }while((isSuccess == 0)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14853. }
  14854. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"sftp", 4) == 0) // sftp
  14855. {
  14856. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14857. memset(temp, 0, ARRAY_SIZE(temp));
  14858. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14859. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14860. int ftppathlen=strlen(ftpbuf);
  14861. int i=1;
  14862. while(i < ftppathlen)
  14863. {
  14864. int len=ftppathlen-i;
  14865. if(ftpbuf[len]== 47) // '/' ascii code: 47
  14866. {
  14867. DEBUG_INFO(" compare '/' all right\n");
  14868. break;
  14869. }
  14870. i=i+1;
  14871. }
  14872. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14873. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14874. firmwareFileName[i+1] = 0;
  14875. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14876. pch=strchr(temp,'@');
  14877. if(pch==NULL)
  14878. {
  14879. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14880. protocol, host, &port, path);
  14881. strcpy(user,"anonymous");
  14882. strcpy(password,"");
  14883. }
  14884. else
  14885. {
  14886. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  14887. protocol, user, host, &port, path);
  14888. }
  14889. sscanf(host,"%[^/]%s",host1, path1);
  14890. sprintf(ftppath,"%s:/%s", host,path);
  14891. if(port == 0)
  14892. {
  14893. port = 21;
  14894. }
  14895. do
  14896. {
  14897. sleep(1);
  14898. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14899. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14900. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14901. sleep(1);
  14902. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14903. if(!isSuccess)
  14904. {
  14905. sleep(1);
  14906. DEBUG_INFO("Update firmware request and download file fail.\n");
  14907. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14908. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14909. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14910. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14911. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14912. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14913. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14914. }
  14915. else
  14916. {
  14917. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14918. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14919. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14920. }
  14921. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14922. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14923. }
  14924. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"ftp", 3) == 0) // ftp
  14925. {
  14926. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14927. memset(temp, 0, ARRAY_SIZE(temp));
  14928. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14929. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14930. int ftppathlen=strlen(ftpbuf);
  14931. int i=1;
  14932. while(i < ftppathlen)
  14933. {
  14934. int len=ftppathlen-i;
  14935. if(ftpbuf[len]== 47) // '/' ascll code: 47
  14936. {
  14937. DEBUG_INFO(" compare '/' all right\n");
  14938. break;
  14939. }
  14940. i=i+1;
  14941. }
  14942. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14943. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14944. firmwareFileName[i+1] = 0;
  14945. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14946. pch=strchr(temp,'@');
  14947. if(pch==NULL)
  14948. {
  14949. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14950. protocol, host, &port, path);
  14951. strcpy(user,"anonymous");
  14952. strcpy(password,"");
  14953. }
  14954. else
  14955. {
  14956. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14957. protocol, user, password, host, &port, path);
  14958. }
  14959. sscanf(host,"%[^/]%s",host1, path1);
  14960. sprintf(ftppath,"%s", path1);
  14961. //DEBUG_INFO("protocol =%s\n",protocol);
  14962. //DEBUG_INFO("user =%s\n",user);
  14963. //DEBUG_INFO("password =%s\n",password);
  14964. //DEBUG_INFO("host1 =%s\n",host1);
  14965. //DEBUG_INFO("port =%d\n",port);
  14966. //DEBUG_INFO("path1 =%s\n",path1);
  14967. //DEBUG_INFO("ftppath=%s\n",ftppath);
  14968. //ftpFile(host, user, password, port, ftppath, fname);
  14969. //download firmware pthred
  14970. if(port == 0)
  14971. {
  14972. port = 21;
  14973. }
  14974. do
  14975. {
  14976. sleep(1);
  14977. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14978. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14979. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14980. sleep(1);
  14981. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14982. if(!isSuccess)
  14983. {
  14984. //BulldogUtil.sleepMs(interval*1000);
  14985. DEBUG_INFO("Update firmware request and download file fail.\n");
  14986. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14987. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14988. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14989. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14990. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14991. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14992. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14993. }
  14994. else
  14995. {
  14996. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14997. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14998. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14999. }
  15000. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15001. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15002. }
  15003. else
  15004. {
  15005. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15006. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15007. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15008. sleep(1);
  15009. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15010. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15011. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15012. }
  15013. // Verify firmware image signature
  15014. struct stat st;
  15015. FILE *fp = fopen("/tmp/signingFirmwareUpdate.crt", "w");
  15016. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  15017. fclose(fp);
  15018. system("openssl x509 -pubkey -noout -in /tmp/signingFirmwareUpdate.crt > /tmp/signingFirmwareUpdate.key");
  15019. fp = fopen("/tmp/signingFirmwareUpdate.sign", "w");
  15020. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  15021. fclose(fp);
  15022. system("openssl base64 -d -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15023. stat("/tmp/signingFirmwareUpdate.sign.256", &st);
  15024. if(st.st_size == 0)
  15025. system("openssl base64 -d -A -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15026. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "Downloaded") != NULL)
  15027. {
  15028. sprintf(temp ,"openssl dgst -verify /tmp/signingFirmwareUpdate.key -signature /tmp/signingFirmwareUpdate.sign.256 /mnt/%s", firmwareFileName);
  15029. fp = popen(temp, "r");
  15030. if(fp)
  15031. {
  15032. while(fgets(temp, sizeof(temp), fp) != NULL)
  15033. {
  15034. if(strstr(temp, "Verified OK") != NULL)
  15035. {
  15036. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15037. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "SignatureVerified");
  15038. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15039. }
  15040. else
  15041. {
  15042. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15043. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InvalidSignature");
  15044. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15045. sleep(1);
  15046. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15047. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InstallationFailed");
  15048. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15049. sleep(1);
  15050. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15051. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15052. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15053. }
  15054. break;
  15055. }
  15056. }
  15057. pclose(fp);
  15058. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "SignatureVerified") != NULL)ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  15059. }
  15060. interLock.isUpdateFirmwareGoing = 0;
  15061. pthread_exit(NULL);
  15062. }
  15063. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  15064. {
  15065. mtrace();
  15066. int result = PASS;
  15067. pthread_t t;
  15068. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  15069. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Accepted");
  15070. sendSignedUpdateFirmwareConfirmation(uuid);
  15071. if(!interLock.isUpdateFirmwareGoing)
  15072. {
  15073. interLock.isUpdateFirmwareGoing = 1;
  15074. pthread_create(&t, NULL, SignedUpdateFirmwareProcess, payload);
  15075. sleep(1);
  15076. }
  15077. else
  15078. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  15079. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareConf = 1;
  15080. return result;
  15081. }
  15082. int handleUnknownRequest(char *uuid, char *payload)
  15083. {
  15084. mtrace();
  15085. int result = PASS;
  15086. DEBUG_INFO("handleUnknownRequest...\n");
  15087. sendUnknownConfirmation(uuid);
  15088. return result;
  15089. }
  15090. //==========================================
  15091. // Handle server response routine
  15092. //==========================================
  15093. void handleAuthorizeResponse(char *payload, int gun_index)
  15094. {
  15095. mtrace();
  15096. char expiryDatestr[36]={0};
  15097. char parentIdTagstr[21]={0};
  15098. char statusstr[20]={0};
  15099. int expiryDateISNULL=FALSE;
  15100. int parentIdTagISNULL=FALSE;
  15101. DEBUG_INFO("handleAuthorizeResponse...\n");
  15102. json_object *Authorize;
  15103. Authorize = json_tokener_parse(payload);
  15104. if(!is_error(Authorize))
  15105. {
  15106. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  15107. {
  15108. // Required data
  15109. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  15110. // Optional data
  15111. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  15112. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  15113. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  15114. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  15115. }
  15116. }
  15117. json_object_put(Authorize);
  15118. if(expiryDateISNULL == FALSE)
  15119. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  15120. if(parentIdTagISNULL == FALSE)
  15121. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  15122. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  15123. //Update idTag information to authorization cache if supproted
  15124. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  15125. {
  15126. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  15127. }
  15128. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  15129. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  15130. authorizeRetryTimes = 0;
  15131. }
  15132. void handleBootNotificationResponse(char *payload, int gun_index)
  15133. {
  15134. mtrace();
  15135. char statusStr[12]={0};
  15136. char currentTimeStr[30]={0};
  15137. int intervalInt = 0;
  15138. DEBUG_INFO("handleBootNotificationResponse...\n");
  15139. json_object *BootNotification;
  15140. BootNotification = json_tokener_parse(payload);
  15141. if(!is_error(BootNotification))
  15142. {
  15143. // Required data
  15144. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  15145. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  15146. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  15147. }
  15148. json_object_put(BootNotification);
  15149. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15150. BootNotificationInterval = intervalInt;
  15151. //write back to ShmOCPP16Data->BootNotification
  15152. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  15153. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15154. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  15155. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  15156. {
  15157. BootNotificationInterval = 0;
  15158. if((intervalInt == 0) || (intervalInt >= 10))
  15159. {
  15160. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  15161. HeartBeatWaitTime = intervalInt;
  15162. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  15163. }
  15164. server_sign = TRUE;
  15165. server_pending =FALSE;
  15166. }
  15167. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  15168. {
  15169. server_pending = TRUE;
  15170. }
  15171. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  15172. srand(time(NULL));
  15173. refreshStartTimer(&clientTime.Heartbeat);
  15174. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  15175. SetOcppConnStatus(TRUE);
  15176. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  15177. }
  15178. void handleDataTransferResponse(char *payload, int gun_index)
  15179. {
  15180. json_object *DataTransfer = json_tokener_parse(payload);
  15181. DEBUG_INFO("Corresponding gun-%d MessageId: %s\n", gun_index, ShmOCPP16Data->DataTransfer[gun_index].MessageId);
  15182. if(!is_error(DataTransfer))
  15183. {
  15184. // Required data
  15185. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  15186. // Optional data
  15187. if(json_object_object_get(DataTransfer, "data") != NULL)
  15188. {
  15189. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15190. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15191. if(!is_error(Data))
  15192. {
  15193. if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Authorize") != NULL)
  15194. {
  15195. if(json_object_object_get(Data, "certificateStatus") != NULL)
  15196. {
  15197. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "%s", json_object_get_string(json_object_object_get(Data, "certificateStatus")));
  15198. }
  15199. if(json_object_object_get(Data, "idTokenInfo") != NULL)
  15200. {
  15201. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "status") != NULL)
  15202. {
  15203. 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")));
  15204. }
  15205. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "cacheExpiryDateTime") != NULL)
  15206. {
  15207. 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")));
  15208. }
  15209. }
  15210. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  15211. }
  15212. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Get15118EVCertificate") != NULL)
  15213. {
  15214. if(json_object_object_get(Data, "status") != NULL)
  15215. {
  15216. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15217. }
  15218. if(json_object_object_get(Data, "exiResponse") != NULL)
  15219. {
  15220. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_exiResponse, "%s", json_object_get_string(json_object_object_get(Data, "exiResponse")));
  15221. }
  15222. ShmOCPP16Data->v2g_extend.Get15118EVCertificateConf = 1;
  15223. }
  15224. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "GetCertificateStatus") != NULL)
  15225. {
  15226. if(json_object_object_get(Data, "status") != NULL)
  15227. {
  15228. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15229. }
  15230. if(json_object_object_get(Data, "ocspResult") != NULL)
  15231. {
  15232. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_ocspResult, "%s", json_object_get_string(json_object_object_get(Data, "ocspResult")));
  15233. }
  15234. ShmOCPP16Data->v2g_extend.GetCertificateStatusConf = 1;
  15235. }
  15236. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "SignCertificate") != NULL)
  15237. {
  15238. sprintf((char*)ShmOCPP16Data->v2g_extend.SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15239. ShmOCPP16Data->v2g_extend.SignCertificateConf = 1;
  15240. }
  15241. else
  15242. {
  15243. if(json_object_object_get(Data, "msgId") != NULL)
  15244. {
  15245. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  15246. {
  15247. 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")));
  15248. }
  15249. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  15250. {
  15251. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15252. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  15253. }
  15254. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_OccupancyFeeAct") != NULL)
  15255. {
  15256. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15257. {
  15258. sprintf((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_status, "%s", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  15259. if(json_object_object_get(Data, "occupancySN") != NULL)
  15260. sprintf((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_occupancySN, "%s", json_object_get_string(json_object_object_get(Data, "occupancySN")));
  15261. if(json_object_object_get(Data, "startTime") != NULL)
  15262. sprintf((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_startTime, "%s", json_object_get_string(json_object_object_get(Data, "startTime")));
  15263. if(json_object_object_get(Data, "duration") != NULL)
  15264. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_duration = json_object_get_int(json_object_object_get(Data, "duration"));
  15265. if(json_object_object_get(Data, "occupancyFee") != NULL)
  15266. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_occupancyFee = json_object_get_double(json_object_object_get(Data, "occupancyFee"));
  15267. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].OccupancyFeeActReq = 0;
  15268. }
  15269. else
  15270. {
  15271. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  15272. {
  15273. if(ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].OccupancyFeeActReq)
  15274. {
  15275. strcpy((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].response_status, "Rejected");
  15276. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].OccupancyFeeActReq = 0;
  15277. }
  15278. }
  15279. }
  15280. }
  15281. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_OccupancyDeductResult") != NULL)
  15282. {
  15283. if(json_object_object_get(Data, "occupancySN") != NULL)
  15284. OCPP_update_occupancyDeduct_info((char*)json_object_get_string(json_object_object_get(Data, "occupancySN")));
  15285. }
  15286. }
  15287. }
  15288. }
  15289. json_object_put(Data);
  15290. }
  15291. }
  15292. json_object_put(DataTransfer);
  15293. }
  15294. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  15295. {
  15296. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  15297. //struct json_object *obj;
  15298. // obj = json_tokener_parse(payload);
  15299. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  15300. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  15301. //No fields are defined.
  15302. }
  15303. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15304. {
  15305. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  15306. //struct json_object *obj;
  15307. // obj = json_tokener_parse(payload);
  15308. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  15309. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  15310. //No fields are defined.
  15311. }
  15312. void handleHeartbeatResponse(char *payload, int gun_index)
  15313. {
  15314. mtrace();
  15315. DEBUG_INFO("handleHeartbeatResponse...\n");
  15316. json_object *Heartbeat;
  15317. Heartbeat = json_tokener_parse(payload);
  15318. if(!is_error(Heartbeat))
  15319. {
  15320. // Required data
  15321. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  15322. }
  15323. json_object_put(Heartbeat);
  15324. if(FirstHeartBeat == 0)
  15325. {
  15326. FirstHeartBeat = 1;
  15327. DEBUG_INFO("FirstHeartBeat \n");
  15328. }
  15329. HeartBeatWithNOResponse = 0;
  15330. refreshStartTimer(&clientTime.Heartbeat);
  15331. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  15332. }
  15333. void handleMeterValuesResponse(char *payload, int gun_index)
  15334. {
  15335. mtrace();
  15336. DEBUG_INFO("handleMeterValuesResponse...\n");
  15337. isQueueSendable = 1;
  15338. }
  15339. void handleStartTransactionResponse(char *payload, int gun_index)
  15340. {
  15341. mtrace();
  15342. //int transactionIdInt = 0;
  15343. FILE *outfile;
  15344. char data[100]={0};
  15345. DEBUG_INFO("handleStartTransactionResponse...\n");
  15346. json_object *StartTransaction;
  15347. StartTransaction = json_tokener_parse(payload);
  15348. if(!is_error(StartTransaction))
  15349. {
  15350. // Required data
  15351. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  15352. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  15353. // Optional data
  15354. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  15355. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  15356. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15357. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  15358. }
  15359. json_object_put(StartTransaction);
  15360. OCPP_updatePeriodEnergy(gun_index);
  15361. //-----------Start : write to the Queue TransactionId file -----------------//
  15362. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  15363. {}
  15364. else
  15365. {
  15366. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  15367. if(log == NULL)
  15368. {
  15369. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  15370. return ;
  15371. }
  15372. else
  15373. {
  15374. fclose(log);
  15375. }
  15376. }
  15377. // open file for writing
  15378. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  15379. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  15380. {
  15381. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  15382. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  15383. fputs(data, outfile);
  15384. fclose (outfile);
  15385. }
  15386. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15387. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15388. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  15389. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  15390. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15391. isQueueSendable = 1;
  15392. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  15393. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  15394. }
  15395. void handleStatusNotificationResponse(char *payload, int gun_index)
  15396. {
  15397. mtrace();
  15398. DEBUG_INFO("handleStatusNotificationResponse...\n");
  15399. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15400. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15401. if(gun_index != 99)
  15402. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  15403. }
  15404. void handleStopTransactionnResponse(char *payload, int gun_index)
  15405. {
  15406. mtrace();
  15407. DEBUG_INFO("handleStopTransactionnResponse...\n");
  15408. json_object *StopTransaction;
  15409. StopTransaction = json_tokener_parse(payload);
  15410. if(!is_error(StopTransaction))
  15411. {
  15412. // Optional data
  15413. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  15414. {
  15415. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  15416. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  15417. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  15418. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15419. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  15420. }
  15421. }
  15422. json_object_put(StopTransaction);
  15423. isQueueSendable = 1;
  15424. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  15425. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  15426. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15427. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15428. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  15429. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  15430. }
  15431. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  15432. {
  15433. mtrace();
  15434. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  15435. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  15436. }
  15437. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  15438. {
  15439. mtrace();
  15440. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  15441. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  15442. }
  15443. void handleSignCertificateResponse(char *payload, int gun_index)
  15444. {
  15445. mtrace();
  15446. DEBUG_INFO("handleSignCertificateResponse...\n");
  15447. json_object *SignCertificate;
  15448. SignCertificate = json_tokener_parse(payload);
  15449. if(!is_error(SignCertificate))
  15450. {
  15451. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  15452. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  15453. }
  15454. json_object_put(SignCertificate);
  15455. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  15456. }
  15457. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15458. {
  15459. mtrace();
  15460. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  15461. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  15462. }
  15463. //==========================================
  15464. // Handle Error routine
  15465. //==========================================
  15466. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  15467. {
  15468. mtrace();
  15469. #ifdef SystemLogMessage
  15470. DEBUG_INFO("errorCode: %s\n", errorCode);
  15471. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  15472. DEBUG_INFO("errorDetails: %s\n", payload);
  15473. #endif
  15474. }
  15475. //===============================================
  15476. // Common routine
  15477. //===============================================
  15478. int initialConfigurationTable(void)
  15479. {
  15480. //clock_t start_t, end_t, total_t;
  15481. FILE *fp;
  15482. FILE *outfile;
  15483. char str[512]={0};
  15484. char sstr[256]={0};
  15485. int c = 0;
  15486. char *loc;
  15487. int confVersion = 23;
  15488. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  15489. //start_t = clock();
  15490. //printf("Starting of the program, start_t = %ld\n", start_t);
  15491. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  15492. // Check configuration file size is correct
  15493. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  15494. {
  15495. struct stat st;
  15496. stat("/Storage/OCPP/OCPPConfiguration", &st);
  15497. if(st.st_size < 3100)
  15498. {
  15499. system("rm -f /Storage/OCPP/OCPPConfiguration");
  15500. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  15501. }
  15502. }
  15503. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  15504. {
  15505. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15506. if(outfile == NULL)
  15507. {
  15508. DEBUG_INFO("Error opening file\n");
  15509. return FALSE;
  15510. }
  15511. /*Core Profile*/
  15512. //AllowOfflineTxForUnknownId
  15513. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  15516. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15517. //AuthorizationCacheEnabled
  15518. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15521. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15522. //AuthorizeRemoteTxRequests
  15523. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  15524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  15526. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15527. //BlinkRepeat
  15528. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15530. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15531. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15532. //ClockAlignedDataInterval
  15533. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15536. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15537. //ConnectionTimeOut
  15538. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15540. if(ShmSysConfigAndInfo->SysConfig.ModelName[3]=='J')
  15541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "55" );
  15542. else
  15543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15544. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15545. //GetConfigurationMaxKeys
  15546. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15548. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  15549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15550. // HeartbeatInterval
  15551. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  15554. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15555. // LightIntensity
  15556. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15559. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15560. // LocalAuthorizeOffline
  15561. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  15562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15564. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15565. // LocalPreAuthorize
  15566. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  15567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15569. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15570. // MaxEnergyOnInvalidId
  15571. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15574. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15575. // MeterValuesAlignedData
  15576. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15578. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15579. 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" );
  15580. else
  15581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15582. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15583. // MeterValuesAlignedDataMaxLength
  15584. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15586. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  15588. else
  15589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  15590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15591. // MeterValuesSampledData
  15592. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15594. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15595. 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" );
  15596. else
  15597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15599. // MeterValuesSampledDataMaxLength
  15600. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15602. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  15604. else
  15605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  15606. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15607. // MeterValueSampleInterval
  15608. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  15611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15612. // MinimumStatusDuration
  15613. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  15616. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  15617. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15618. // NumberOfConnectors
  15619. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15621. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15622. {
  15623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15624. }
  15625. else
  15626. {
  15627. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15628. }
  15629. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15630. // ResetRetries
  15631. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15634. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15635. // ConnectorPhaseRotation
  15636. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15640. // ConnectorPhaseRotationMaxLength
  15641. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15644. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15645. // StopTransactionOnEVSideDisconnect
  15646. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  15647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15649. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15650. // StopTransactionOnInvalidId
  15651. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  15652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15655. // StopTxnAlignedData
  15656. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  15659. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15660. // StopTxnAlignedDataMaxLength
  15661. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15663. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15664. {
  15665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", 8);
  15666. }
  15667. else
  15668. {
  15669. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", 10);
  15670. }
  15671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15672. // StopTxnSampledData
  15673. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "" );
  15676. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15677. // StopTxnSampledDataMaxLength
  15678. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15680. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15681. {
  15682. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 8);
  15683. }
  15684. else
  15685. {
  15686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 10);
  15687. }
  15688. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15689. // SupportedFeatureProfiles
  15690. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15694. // SupportedFeatureProfilesMaxLength
  15695. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15699. // TransactionMessageAttempts
  15700. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15703. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15704. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15705. // TransactionMessageRetryInterval
  15706. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15709. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15710. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15711. // UnlockConnectorOnEVSideDisconnect
  15712. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  15713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15715. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15716. // WebSocketPingInterval
  15717. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15721. // QueueOffLineMeterValues
  15722. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  15723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  15725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15726. // AuthorizationKey
  15727. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  15730. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15731. // SecurityProfile
  15732. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15734. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  15735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15736. // DefaultPrice
  15737. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15740. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15741. // CustomDisplayCostAndPrice
  15742. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15745. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15746. // CustomIdleFeeAfterStop
  15747. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15751. // TimeOffset
  15752. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  15755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15756. // NextTimeOffsetTransitionDateTime
  15757. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  15760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15761. // TimeOffsetNextTransition
  15762. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  15765. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15766. // SystemUptimeSec
  15767. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15771. // FreeVend
  15772. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15776. // FreeVendIdtag
  15777. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15780. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15781. // OcppServer
  15782. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15784. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15785. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15786. // MaintainServer
  15787. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15789. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  15790. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15791. // StatusNotificationPeriodically
  15792. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  15793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15795. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15796. // StatusNotificationInterval
  15797. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15800. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15801. // PreAuthAmount
  15802. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  15805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15806. // isEnableLocalPowerSharing
  15807. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15809. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15811. // PowerSharingServerIP
  15812. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15814. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  15815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15816. // EVCCID_PREFIX
  15817. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15821. // OffLineMaxChargingPower
  15822. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  15825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15826. // Configuration Version
  15827. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  15828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15829. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  15830. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15831. // Charging profile refresh interval
  15832. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  15833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  15834. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  15835. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  15836. // CpoName
  15837. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  15838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  15839. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "Zerova");
  15840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  15841. // Ocpp Software certificated version
  15842. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  15843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  15844. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  15845. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  15846. //* Local Auth List Management Profile*/
  15847. #if 0
  15848. //For OCTT Test Case
  15849. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  15851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15852. #endif
  15853. #if 1
  15854. //LocalAuthListEnabled
  15855. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15858. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15859. #endif
  15860. //LocalAuthListMaxLength
  15861. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  15864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15865. //SendLocalListMaxLength
  15866. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  15869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15870. //ReserveConnectorZeroSupported
  15871. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15875. //* Smart Charging Profile */
  15876. //ChargeProfileMaxStackLevel
  15877. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  15880. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15881. // ChargingScheduleAllowedChargingRateUnit
  15882. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  15885. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15886. // ChargingScheduleMaxPeriods
  15887. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15889. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15891. // ConnectorSwitch3to1PhaseSupported
  15892. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  15895. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15896. // MaxChargingProfilesInstalled
  15897. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  15900. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15901. fclose(outfile);
  15902. }
  15903. else
  15904. {
  15905. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  15906. char keystr[60]={0};
  15907. char readonlystr[10]={0};
  15908. char valuestr[256]={0};
  15909. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  15910. if(fp == NULL) {
  15911. DEBUG_INFO("Error opening file");
  15912. return FALSE;
  15913. }
  15914. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  15915. {
  15916. //DEBUG_INFO("Get Configuration \n");
  15917. if(strlen(str) > 0)
  15918. {
  15919. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15920. //*************************key*********************************/
  15921. if(strstr(str, "key") != NULL)
  15922. {
  15923. loc = strstr(str, "key");
  15924. c = 0;
  15925. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15926. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  15927. {
  15928. sstr[c] = loc[strlen("key")+3+c];
  15929. c++;
  15930. }
  15931. sstr[c] = '\0';
  15932. strcpy(keystr,sstr);
  15933. }
  15934. //*************************readonly*********************************/
  15935. if(strstr(str, "readonly") != NULL)
  15936. {
  15937. loc = strstr(str, "readonly");
  15938. c = 0;
  15939. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15940. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  15941. {
  15942. sstr[c] = loc[strlen("readonly")+2+c];
  15943. c++;
  15944. }
  15945. sstr[c] = '\0';
  15946. strcpy(readonlystr,sstr);
  15947. }
  15948. //*************************value*********************************/
  15949. if(strstr(str, "value") != NULL)
  15950. {
  15951. loc = strstr(str, "value");
  15952. c = 0;
  15953. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15954. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  15955. {
  15956. sstr[c] = loc[strlen("value")+3+c];
  15957. c++;
  15958. }
  15959. sstr[c] = '\0';
  15960. strcpy(valuestr,sstr);
  15961. }
  15962. // DEBUG_INFO("keystr=%s\n",keystr);
  15963. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  15964. // DEBUG_INFO("valuestr=%s\n",valuestr);
  15965. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  15966. {
  15967. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15968. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15969. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  15970. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  15971. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  15972. }
  15973. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  15974. {
  15975. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15976. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15977. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  15978. }
  15979. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  15980. {
  15981. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15982. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  15983. }
  15984. if(strcmp(keystr, "BlinkRepeat") == 0)
  15985. {
  15986. //Charger.BlinkRepeat = Integer.parseInt(value);
  15987. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  15989. }
  15990. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  15991. {
  15992. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  15994. }
  15995. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  15996. {
  15997. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15998. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  15999. }
  16000. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  16001. {
  16002. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16003. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  16004. }
  16005. if(strcmp(keystr, "HeartbeatInterval") == 0)
  16006. {
  16007. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  16009. HeartBeatWaitTime = atoi(valuestr);
  16010. }
  16011. if(strcmp(keystr, "LightIntensity") == 0)
  16012. {
  16013. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16014. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  16015. }
  16016. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  16017. {
  16018. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16019. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  16020. }
  16021. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  16022. {
  16023. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16024. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  16025. }
  16026. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  16027. {
  16028. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16029. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  16030. }
  16031. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  16032. {
  16033. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16034. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  16035. }
  16036. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  16037. {
  16038. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16039. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  16040. }
  16041. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  16042. {
  16043. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16044. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  16045. }
  16046. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  16047. {
  16048. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16049. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  16050. }
  16051. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  16052. {
  16053. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16054. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  16055. }
  16056. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  16057. {
  16058. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16059. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  16060. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  16061. }
  16062. if(strcmp(keystr, "NumberOfConnectors") == 0)
  16063. {
  16064. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16065. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  16066. }
  16067. if(strcmp(keystr, "ResetRetries") == 0)
  16068. {
  16069. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  16071. }
  16072. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  16073. {
  16074. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16075. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  16076. }
  16077. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  16078. {
  16079. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16080. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  16081. }
  16082. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  16083. {
  16084. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16085. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  16086. }
  16087. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  16088. {
  16089. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16090. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  16091. }
  16092. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  16093. {
  16094. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16095. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  16096. }
  16097. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  16098. {
  16099. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16100. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16101. }
  16102. if(strcmp(keystr, "StopTxnSampledData") == 0)
  16103. {
  16104. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16105. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  16106. }
  16107. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  16108. {
  16109. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16110. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16111. }
  16112. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  16113. {
  16114. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16115. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  16116. }
  16117. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  16118. {
  16119. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16120. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  16121. }
  16122. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  16123. {
  16124. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16125. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  16126. TransactionMessageAttemptsValue = atoi(valuestr);
  16127. }
  16128. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  16129. {
  16130. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16131. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  16132. TransactionMessageRetryIntervalValue = atoi(valuestr);
  16133. }
  16134. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  16135. {
  16136. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16137. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  16138. }
  16139. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  16140. {
  16141. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16142. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  16143. }
  16144. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  16145. {
  16146. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16147. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  16148. }
  16149. if(strcmp(keystr, "AuthorizationKey") == 0)
  16150. {
  16151. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16152. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  16153. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  16154. }
  16155. if(strcmp(keystr, "SecurityProfile") == 0)
  16156. {
  16157. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16158. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  16159. }
  16160. if(strcmp(keystr, "DefaultPrice") == 0)
  16161. {
  16162. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16163. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  16164. }
  16165. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  16166. {
  16167. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16168. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  16169. }
  16170. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  16171. {
  16172. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16173. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  16174. }
  16175. if(strcmp(keystr, "TimeOffset") == 0)
  16176. {
  16177. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  16179. }
  16180. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  16181. {
  16182. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16183. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  16184. }
  16185. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  16186. {
  16187. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16188. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  16189. }
  16190. if(strcmp(keystr, "SystemUptimeSec") == 0)
  16191. {
  16192. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16193. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  16194. }
  16195. if(strcmp(keystr, "FreeVend") == 0)
  16196. {
  16197. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  16199. }
  16200. if(strcmp(keystr, "FreeVendIdtag") == 0)
  16201. {
  16202. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  16204. }
  16205. if(strcmp(keystr, "OcppServer") == 0)
  16206. {
  16207. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16208. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  16209. }
  16210. if(strcmp(keystr, "MaintainServer") == 0)
  16211. {
  16212. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16213. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  16214. }
  16215. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  16216. {
  16217. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  16219. }
  16220. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  16221. {
  16222. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16223. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  16224. }
  16225. if(strcmp(keystr, "PreAuthAmount") == 0)
  16226. {
  16227. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  16229. }
  16230. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  16231. {
  16232. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16233. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  16234. }
  16235. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  16236. {
  16237. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16238. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  16239. }
  16240. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  16241. {
  16242. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  16244. }
  16245. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  16246. {
  16247. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  16249. }
  16250. if(strcmp(keystr, "ConfigurationVersion") == 0)
  16251. {
  16252. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16253. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  16254. }
  16255. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  16256. {
  16257. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16258. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  16259. }
  16260. if(strcmp(keystr, "CpoName") == 0)
  16261. {
  16262. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16263. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", valuestr);
  16264. }
  16265. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  16266. {
  16267. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16268. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  16269. }
  16270. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  16271. {
  16272. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16273. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  16274. }
  16275. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  16276. {
  16277. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16278. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  16279. }
  16280. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  16281. {
  16282. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16283. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  16284. }
  16285. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  16286. {
  16287. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16288. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  16289. }
  16290. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  16291. {
  16292. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16293. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  16294. }
  16295. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16296. {
  16297. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16298. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  16299. }
  16300. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  16301. {
  16302. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16303. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  16304. }
  16305. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  16306. {
  16307. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16308. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  16309. }
  16310. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  16311. {
  16312. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16313. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  16314. }
  16315. }
  16316. }
  16317. fclose(fp);
  16318. }
  16319. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  16320. {
  16321. return PASS;
  16322. }
  16323. else
  16324. {
  16325. return FAIL;
  16326. }
  16327. }
  16328. void StoreConfigurationTable(void)
  16329. {
  16330. FILE *outfile;
  16331. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  16332. if(outfile == NULL)
  16333. {
  16334. DEBUG_INFO("Error opening file");
  16335. return ;
  16336. }
  16337. /*Core Profile*/
  16338. //AllowOfflineTxForUnknownId
  16339. /*
  16340. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  16341. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  16342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  16343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  16344. */
  16345. //DEBUG_INFO("data=%s\n",data);
  16346. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  16347. //AuthorizationCacheEnabled
  16348. /*
  16349. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  16350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  16351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  16352. */
  16353. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  16354. //AuthorizeRemoteTxRequests
  16355. /*
  16356. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  16357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  16358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  16359. */
  16360. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  16361. //BlinkRepeat
  16362. /*
  16363. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  16364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  16365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  16366. */
  16367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  16368. //ClockAlignedDataInterval
  16369. /*
  16370. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  16371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  16372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  16373. */
  16374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  16375. //ConnectionTimeOut
  16376. /*
  16377. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  16378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  16379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  16380. */
  16381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  16382. //GetConfigurationMaxKeys
  16383. /*
  16384. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  16385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  16386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  16387. */
  16388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  16389. // HeartbeatInterval
  16390. /*
  16391. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  16392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  16393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  16394. */
  16395. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  16396. // LightIntensity
  16397. /*
  16398. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  16399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  16400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  16401. */
  16402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  16403. // LocalAuthorizeOffline
  16404. /*
  16405. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  16406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  16407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  16408. */
  16409. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16410. // LocalPreAuthorize
  16411. /*
  16412. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  16413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  16414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  16415. */
  16416. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  16417. // MaxEnergyOnInvalidId
  16418. /*
  16419. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  16420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  16421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  16422. */
  16423. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  16424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  16425. // MeterValuesAlignedData
  16426. /*
  16427. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  16428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  16429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16430. */
  16431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  16432. // MeterValuesAlignedDataMaxLength
  16433. /*
  16434. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  16435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  16436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  16437. */
  16438. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  16439. // MeterValuesSampledData
  16440. /*
  16441. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  16442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  16443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16444. */
  16445. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  16446. // MeterValuesSampledDataMaxLength
  16447. /*
  16448. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  16449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  16450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  16451. */
  16452. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  16453. // MeterValueSampleInterval
  16454. /*
  16455. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  16456. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  16457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  16458. */
  16459. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  16460. // MinimumStatusDuration
  16461. /*
  16462. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  16463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  16464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  16465. */
  16466. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16467. // NumberOfConnectors
  16468. /*
  16469. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  16470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  16471. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16472. {
  16473. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  16474. }
  16475. else
  16476. {
  16477. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  16478. }
  16479. */
  16480. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  16481. // ResetRetries
  16482. /*
  16483. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  16484. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  16485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  16486. */
  16487. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  16488. // ConnectorPhaseRotation
  16489. /*
  16490. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  16491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  16492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  16493. */
  16494. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  16495. // ConnectorPhaseRotationMaxLength
  16496. /*
  16497. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  16498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  16499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  16500. */
  16501. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  16502. // StopTransactionOnEVSideDisconnect
  16503. /*
  16504. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  16505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  16506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  16507. */
  16508. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  16509. // StopTransactionOnInvalidId
  16510. /*
  16511. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  16512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  16513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  16514. */
  16515. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  16516. // StopTxnAlignedData
  16517. /*
  16518. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  16519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  16520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  16521. */
  16522. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  16523. // StopTxnAlignedDataMaxLength
  16524. /*
  16525. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  16526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  16527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  16528. */
  16529. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  16530. // StopTxnSampledData
  16531. /*
  16532. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  16533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  16534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  16535. */
  16536. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  16537. // StopTxnSampledDataMaxLength
  16538. /*
  16539. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  16540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  16541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  16542. */
  16543. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  16544. // SupportedFeatureProfiles
  16545. /*
  16546. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  16547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  16548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  16549. */
  16550. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  16551. // SupportedFeatureProfilesMaxLength
  16552. /*
  16553. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  16554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  16555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  16556. */
  16557. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  16558. // TransactionMessageAttempts
  16559. /*
  16560. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  16561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  16562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  16563. */
  16564. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16565. // TransactionMessageRetryInterval
  16566. /*
  16567. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  16568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  16569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  16570. */
  16571. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16572. // UnlockConnectorOnEVSideDisconnect
  16573. /*
  16574. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  16575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  16576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  16577. */
  16578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  16579. // WebSocketPingInterval
  16580. /*
  16581. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  16582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  16583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  16584. */
  16585. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16586. // QueueOffLineMeterValues
  16587. /*
  16588. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  16589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  16590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  16591. */
  16592. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  16593. // AuthorizationKey
  16594. /*
  16595. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  16596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  16597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  16598. */
  16599. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16600. // SecurityProfile
  16601. /*
  16602. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  16603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  16604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  16605. */
  16606. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16607. // DefaultPrice
  16608. /*
  16609. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  16610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  16611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  16612. */
  16613. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16614. // CustomDisplayCostAndPrice
  16615. /*
  16616. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  16617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  16618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  16619. */
  16620. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  16621. // CustomIdleFeeAfterStop
  16622. /*
  16623. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  16624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  16625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  16626. */
  16627. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  16628. // TimeOffset
  16629. /*
  16630. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  16631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  16632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  16633. */
  16634. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  16635. // NextTimeOffsetTransitionDateTime
  16636. /*
  16637. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  16638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  16639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  16640. */
  16641. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  16642. // TimeOffsetNextTransition
  16643. /*
  16644. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  16645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  16646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  16647. */
  16648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  16649. // SystemUptimeSec
  16650. /*
  16651. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  16652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  16653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  16654. */
  16655. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  16656. // FreeVend
  16657. /*
  16658. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  16659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  16660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  16661. */
  16662. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  16663. // FreeVendIdtag
  16664. /*
  16665. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  16666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  16667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  16668. */
  16669. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16670. // OcppServer
  16671. /*
  16672. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  16673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  16674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  16675. */
  16676. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16677. // MaintainServer
  16678. /*
  16679. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  16680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  16681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  16682. */
  16683. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16684. // StatusNotificationPeriodically
  16685. /*
  16686. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  16687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  16688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  16689. */
  16690. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  16691. // StatusNotificationInterval
  16692. /*
  16693. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  16694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  16695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  16696. */
  16697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  16698. // PreAuthAmount
  16699. /*
  16700. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  16701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  16702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  16703. */
  16704. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  16705. // isEnableLocalPowerSharing
  16706. /*
  16707. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  16708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  16709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  16710. */
  16711. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  16712. // PowerSharingServerIP
  16713. /*
  16714. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  16715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  16716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  16717. */
  16718. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  16719. // EVCCID_PREFIX
  16720. /*
  16721. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  16722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  16723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  16724. */
  16725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  16726. // OffLineMaxChargingPower
  16727. /*
  16728. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  16729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  16730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  16731. */
  16732. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  16733. // ConfigurationVersion
  16734. /*
  16735. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  16736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  16737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  16738. */
  16739. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  16740. // CharingProfileRefreshInterval
  16741. /*
  16742. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  16743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  16744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  16745. */
  16746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  16747. // CpoName
  16748. /*
  16749. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  16750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  16751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "" );
  16752. */
  16753. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  16754. // OcppSoftwareVersion
  16755. /*
  16756. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  16757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  16758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  16759. */
  16760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  16761. //* Local Auth List Management Profile*/
  16762. //LocalAuthListEnabled
  16763. /*
  16764. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  16765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  16766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  16767. */
  16768. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16769. //LocalAuthListMaxLength
  16770. /*
  16771. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  16772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  16773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  16774. */
  16775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  16776. //SendLocalListMaxLength
  16777. /*
  16778. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  16779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  16780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  16781. */
  16782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  16783. //ReserveConnectorZeroSupported
  16784. /*
  16785. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  16786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  16787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  16788. */
  16789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16790. //* Smart Charging Profile */
  16791. //ChargeProfileMaxStackLevel
  16792. /*
  16793. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  16794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  16795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  16796. */
  16797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16798. // ChargingScheduleAllowedChargingRateUnit
  16799. /*
  16800. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  16801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  16802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  16803. */
  16804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16805. // ChargingScheduleMaxPeriods
  16806. /*
  16807. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  16808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  16809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  16810. */
  16811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16812. // ConnectorSwitch3to1PhaseSupported
  16813. /*
  16814. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  16815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  16816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  16817. */
  16818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16819. // MaxChargingProfilesInstalled
  16820. /*
  16821. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  16822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  16823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  16824. */
  16825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16826. fclose(outfile);
  16827. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16828. }
  16829. void getKeyValue(char *keyReq)
  16830. {
  16831. int isEmpty = FALSE;
  16832. int isKnowKey = FALSE;
  16833. DEBUG_INFO("keyReq = %s\n", keyReq);
  16834. if((keyReq == NULL) || (strlen(keyReq) == 0))
  16835. isEmpty = TRUE;
  16836. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  16837. {
  16838. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  16839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  16840. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16841. {
  16842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  16843. }
  16844. else
  16845. {
  16846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  16847. }
  16848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  16849. isKnowKey = TRUE;
  16850. }
  16851. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  16852. {
  16853. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  16854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  16855. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16856. {
  16857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  16858. }
  16859. else
  16860. {
  16861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  16862. }
  16863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  16864. isKnowKey = TRUE;
  16865. }
  16866. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  16867. {
  16868. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  16869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  16870. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16871. {
  16872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  16873. }
  16874. else
  16875. {
  16876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  16877. }
  16878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  16879. isKnowKey = TRUE;
  16880. }
  16881. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  16882. {
  16883. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  16884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  16885. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16886. {
  16887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  16888. }
  16889. else
  16890. {
  16891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  16892. }
  16893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  16894. isKnowKey = TRUE;
  16895. }
  16896. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  16897. {
  16898. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  16899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  16900. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16901. {
  16902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  16903. }
  16904. else
  16905. {
  16906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  16907. }
  16908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  16909. isKnowKey = TRUE;
  16910. }
  16911. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  16912. {
  16913. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  16914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  16915. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16916. {
  16917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  16918. }
  16919. else
  16920. {
  16921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  16922. }
  16923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  16924. isKnowKey = TRUE;
  16925. }
  16926. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  16927. {
  16928. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  16929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  16930. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16931. {
  16932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  16933. }
  16934. else
  16935. {
  16936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  16937. }
  16938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  16939. isKnowKey = TRUE;
  16940. }
  16941. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  16942. {
  16943. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  16944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  16945. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16946. {
  16947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  16948. }
  16949. else
  16950. {
  16951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  16952. }
  16953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  16954. isKnowKey = TRUE;
  16955. }
  16956. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  16957. {
  16958. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  16959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  16960. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16961. {
  16962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  16963. }
  16964. else
  16965. {
  16966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  16967. }
  16968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  16969. isKnowKey = TRUE;
  16970. }
  16971. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  16972. {
  16973. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  16974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  16975. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16976. {
  16977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  16978. }
  16979. else
  16980. {
  16981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  16982. }
  16983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  16984. isKnowKey = TRUE;
  16985. }
  16986. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  16987. {
  16988. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  16989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  16990. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16991. {
  16992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  16993. }
  16994. else
  16995. {
  16996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  16997. }
  16998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  16999. isKnowKey = TRUE;
  17000. }
  17001. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  17002. {
  17003. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  17004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  17005. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  17006. {
  17007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17008. }
  17009. else
  17010. {
  17011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17012. }
  17013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  17014. isKnowKey = TRUE;
  17015. }
  17016. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  17017. {
  17018. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  17019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  17020. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  17021. {
  17022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17023. }
  17024. else
  17025. {
  17026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17027. }
  17028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  17029. isKnowKey = TRUE;
  17030. }
  17031. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  17032. {
  17033. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  17034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  17035. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  17036. {
  17037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17038. }
  17039. else
  17040. {
  17041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17042. }
  17043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  17044. isKnowKey = TRUE;
  17045. }
  17046. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  17047. {
  17048. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  17049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  17050. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  17051. {
  17052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  17053. }
  17054. else
  17055. {
  17056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  17057. }
  17058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  17059. isKnowKey = TRUE;
  17060. }
  17061. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  17062. {
  17063. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  17064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  17065. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  17066. {
  17067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17068. }
  17069. else
  17070. {
  17071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17072. }
  17073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  17074. isKnowKey = TRUE;
  17075. }
  17076. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  17077. {
  17078. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  17079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  17080. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  17081. {
  17082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  17083. }
  17084. else
  17085. {
  17086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  17087. }
  17088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  17089. isKnowKey = TRUE;
  17090. }
  17091. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  17092. {
  17093. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  17094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  17095. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  17096. {
  17097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  17098. }
  17099. else
  17100. {
  17101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  17102. }
  17103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  17104. isKnowKey = TRUE;
  17105. }
  17106. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  17107. {
  17108. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  17109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  17110. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  17111. {
  17112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  17113. }
  17114. else
  17115. {
  17116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  17117. }
  17118. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  17119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  17120. isKnowKey = TRUE;
  17121. }
  17122. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  17123. {
  17124. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  17125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  17126. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  17127. {
  17128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  17129. }
  17130. else
  17131. {
  17132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  17133. }
  17134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  17135. isKnowKey = TRUE;
  17136. }
  17137. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  17138. {
  17139. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  17140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  17141. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17142. {
  17143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  17144. }
  17145. else
  17146. {
  17147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  17148. }
  17149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  17150. isKnowKey = TRUE;
  17151. }
  17152. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  17153. {
  17154. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  17155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  17156. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  17157. {
  17158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17159. }
  17160. else
  17161. {
  17162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17163. }
  17164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  17165. isKnowKey = TRUE;
  17166. }
  17167. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  17168. {
  17169. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  17170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  17171. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17172. {
  17173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17174. }
  17175. else
  17176. {
  17177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17178. }
  17179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  17180. isKnowKey = TRUE;
  17181. }
  17182. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  17183. {
  17184. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  17185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  17186. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17187. {
  17188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17189. }
  17190. else
  17191. {
  17192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17193. }
  17194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  17195. isKnowKey = TRUE;
  17196. }
  17197. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  17198. {
  17199. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  17200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  17201. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17202. {
  17203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17204. }
  17205. else
  17206. {
  17207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17208. }
  17209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  17210. isKnowKey = TRUE;
  17211. }
  17212. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  17213. {
  17214. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  17215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  17216. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17217. {
  17218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17219. }
  17220. else
  17221. {
  17222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17223. }
  17224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  17225. isKnowKey = TRUE;
  17226. }
  17227. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  17228. {
  17229. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  17230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  17231. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17232. {
  17233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  17234. }
  17235. else
  17236. {
  17237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  17238. }
  17239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  17240. isKnowKey = TRUE;
  17241. }
  17242. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  17243. {
  17244. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  17245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  17246. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17247. {
  17248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17249. }
  17250. else
  17251. {
  17252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17253. }
  17254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  17255. isKnowKey = TRUE;
  17256. }
  17257. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  17258. {
  17259. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  17260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  17261. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17262. {
  17263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  17264. }
  17265. else
  17266. {
  17267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  17268. }
  17269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  17270. isKnowKey = TRUE;
  17271. }
  17272. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  17273. {
  17274. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  17275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  17276. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17277. {
  17278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17279. }
  17280. else
  17281. {
  17282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17283. }
  17284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  17285. isKnowKey = TRUE;
  17286. }
  17287. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  17288. {
  17289. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  17290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  17291. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17292. {
  17293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  17294. }
  17295. else
  17296. {
  17297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  17298. }
  17299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  17300. isKnowKey = TRUE;
  17301. }
  17302. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  17303. {
  17304. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  17305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  17306. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17307. {
  17308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  17309. }
  17310. else
  17311. {
  17312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  17313. }
  17314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  17315. isKnowKey = TRUE;
  17316. }
  17317. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  17318. {
  17319. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  17320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  17321. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17322. {
  17323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17324. }
  17325. else
  17326. {
  17327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17328. }
  17329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  17330. isKnowKey = TRUE;
  17331. }
  17332. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  17333. {
  17334. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  17335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  17336. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17337. {
  17338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  17339. }
  17340. else
  17341. {
  17342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  17343. }
  17344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  17345. isKnowKey = TRUE;
  17346. }
  17347. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  17348. {
  17349. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  17350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  17351. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17352. {
  17353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  17354. }
  17355. else
  17356. {
  17357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  17358. }
  17359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  17360. isKnowKey = TRUE;
  17361. }
  17362. /*
  17363. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  17364. {
  17365. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  17366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  17367. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  17368. {
  17369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  17370. }
  17371. else
  17372. {
  17373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  17374. }
  17375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  17376. isKnowKey = TRUE;
  17377. }*/
  17378. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  17379. {
  17380. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  17381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  17382. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17383. {
  17384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  17385. }
  17386. else
  17387. {
  17388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  17389. }
  17390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  17391. isKnowKey = TRUE;
  17392. }
  17393. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  17394. {
  17395. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  17396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  17397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  17398. {
  17399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  17400. }
  17401. else
  17402. {
  17403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  17404. }
  17405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  17406. isKnowKey = TRUE;
  17407. }
  17408. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  17409. {
  17410. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  17411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  17412. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17413. {
  17414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  17415. }
  17416. else
  17417. {
  17418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  17419. }
  17420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  17421. isKnowKey = TRUE;
  17422. }
  17423. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  17424. {
  17425. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  17426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  17427. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17428. {
  17429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  17430. }
  17431. else
  17432. {
  17433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  17434. }
  17435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  17436. isKnowKey = TRUE;
  17437. }
  17438. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  17439. {
  17440. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  17441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  17442. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17443. {
  17444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  17445. }
  17446. else
  17447. {
  17448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  17449. }
  17450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  17451. isKnowKey = TRUE;
  17452. }
  17453. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  17454. {
  17455. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  17456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  17457. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17458. {
  17459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  17460. }
  17461. else
  17462. {
  17463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  17464. }
  17465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  17466. isKnowKey = TRUE;
  17467. }
  17468. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  17469. {
  17470. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  17471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  17472. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17473. {
  17474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  17475. }
  17476. else
  17477. {
  17478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  17479. }
  17480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  17481. isKnowKey = TRUE;
  17482. }
  17483. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  17484. {
  17485. struct sysinfo s_info;
  17486. int error = sysinfo(&s_info);
  17487. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  17488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  17489. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  17490. {
  17491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  17492. }
  17493. else
  17494. {
  17495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  17496. }
  17497. if(error != 0)
  17498. {
  17499. DEBUG_WARN("System uptime get error: %d\n", error);
  17500. }
  17501. else
  17502. {
  17503. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  17504. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  17505. }
  17506. isKnowKey = TRUE;
  17507. }
  17508. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  17509. {
  17510. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  17511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  17512. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17513. {
  17514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  17515. }
  17516. else
  17517. {
  17518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  17519. }
  17520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  17521. isKnowKey = TRUE;
  17522. }
  17523. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  17524. {
  17525. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  17526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  17527. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17528. {
  17529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  17530. }
  17531. else
  17532. {
  17533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  17534. }
  17535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  17536. isKnowKey = TRUE;
  17537. }
  17538. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  17539. {
  17540. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  17541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  17542. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17543. {
  17544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  17545. }
  17546. else
  17547. {
  17548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  17549. }
  17550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  17551. isKnowKey = TRUE;
  17552. }
  17553. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  17554. {
  17555. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  17556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  17557. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17558. {
  17559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  17560. }
  17561. else
  17562. {
  17563. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  17564. }
  17565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  17566. isKnowKey = TRUE;
  17567. }
  17568. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  17569. {
  17570. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  17571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  17572. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17573. {
  17574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  17575. }
  17576. else
  17577. {
  17578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  17579. }
  17580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  17581. isKnowKey = TRUE;
  17582. }
  17583. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  17584. {
  17585. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  17586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  17587. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17588. {
  17589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  17590. }
  17591. else
  17592. {
  17593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  17594. }
  17595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  17596. isKnowKey = TRUE;
  17597. }
  17598. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  17599. {
  17600. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  17601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  17602. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17603. {
  17604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  17605. }
  17606. else
  17607. {
  17608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  17609. }
  17610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  17611. isKnowKey = TRUE;
  17612. }
  17613. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  17614. {
  17615. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  17616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  17617. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17618. {
  17619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  17620. }
  17621. else
  17622. {
  17623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  17624. }
  17625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  17626. isKnowKey = TRUE;
  17627. }
  17628. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  17629. {
  17630. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  17631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  17632. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17633. {
  17634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  17635. }
  17636. else
  17637. {
  17638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  17639. }
  17640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  17641. isKnowKey = TRUE;
  17642. }
  17643. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  17644. {
  17645. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  17646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  17647. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17648. {
  17649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  17650. }
  17651. else
  17652. {
  17653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  17654. }
  17655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  17656. isKnowKey = TRUE;
  17657. }
  17658. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  17659. {
  17660. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  17661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  17662. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17663. {
  17664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  17665. }
  17666. else
  17667. {
  17668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  17669. }
  17670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  17671. isKnowKey = TRUE;
  17672. }
  17673. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  17674. {
  17675. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  17676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  17677. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  17678. {
  17679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  17680. }
  17681. else
  17682. {
  17683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  17684. }
  17685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  17686. isKnowKey = TRUE;
  17687. }
  17688. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  17689. {
  17690. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  17691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  17692. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  17693. {
  17694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  17695. }
  17696. else
  17697. {
  17698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  17699. }
  17700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  17701. isKnowKey = TRUE;
  17702. }
  17703. if(isEmpty || strcmp(keyReq, "CpoName") == 0 )
  17704. {
  17705. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CpoName].Item, "CpoName");
  17706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Key, "CpoName");
  17707. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  17708. {
  17709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "0"/*"FALSE"*/);
  17710. }
  17711. else
  17712. {
  17713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "1"/*"TRUE"*/);
  17714. }
  17715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData );
  17716. isKnowKey = TRUE;
  17717. }
  17718. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  17719. {
  17720. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  17721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  17722. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  17723. {
  17724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  17725. }
  17726. else
  17727. {
  17728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  17729. }
  17730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  17731. isKnowKey = TRUE;
  17732. }
  17733. #if 1
  17734. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  17735. {
  17736. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  17737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  17738. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17739. {
  17740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  17741. }
  17742. else
  17743. {
  17744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  17745. }
  17746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  17747. isKnowKey = TRUE;
  17748. }
  17749. #endif
  17750. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  17751. {
  17752. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  17753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  17754. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17755. {
  17756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17757. }
  17758. else
  17759. {
  17760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17761. }
  17762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  17763. isKnowKey = TRUE;
  17764. }
  17765. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  17766. {
  17767. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  17768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  17769. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17770. {
  17771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17772. }
  17773. else
  17774. {
  17775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17776. }
  17777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  17778. isKnowKey = TRUE;
  17779. }
  17780. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  17781. {
  17782. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  17783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  17784. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17785. {
  17786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  17787. }
  17788. else
  17789. {
  17790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  17791. }
  17792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  17793. isKnowKey = TRUE;
  17794. }
  17795. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  17796. {
  17797. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  17798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  17799. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17800. {
  17801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  17802. }
  17803. else
  17804. {
  17805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  17806. }
  17807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  17808. isKnowKey = TRUE;
  17809. }
  17810. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  17811. {
  17812. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  17813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  17814. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17815. {
  17816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  17817. }
  17818. else
  17819. {
  17820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  17821. }
  17822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  17823. isKnowKey = TRUE;
  17824. }
  17825. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  17826. {
  17827. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  17828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  17829. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17830. {
  17831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  17832. }
  17833. else
  17834. {
  17835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  17836. }
  17837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  17838. isKnowKey = TRUE;
  17839. }
  17840. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  17841. {
  17842. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  17843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  17844. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17845. {
  17846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  17847. }
  17848. else
  17849. {
  17850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  17851. }
  17852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  17853. isKnowKey = TRUE;
  17854. }
  17855. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  17856. {
  17857. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  17858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  17859. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17860. {
  17861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  17862. }
  17863. else
  17864. {
  17865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  17866. }
  17867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  17868. isKnowKey = TRUE;
  17869. }
  17870. //=========================================================
  17871. if(!isEmpty && !isKnowKey)
  17872. {
  17873. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  17874. strcpy(unknownkey[UnknownKeynum], keyReq);
  17875. UnknownKeynum = UnknownKeynum + 1;
  17876. }
  17877. }
  17878. void processUnkownKey(void)
  17879. {
  17880. DEBUG_INFO("processUnkownKey...\n");
  17881. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  17882. for(int index=0; index < UnknownKeynum; index++)
  17883. {
  17884. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  17885. {
  17886. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  17887. }
  17888. }
  17889. }
  17890. int setKeyValue(char *key, char *value)
  17891. {
  17892. int isSuccess = NotSupported;
  17893. int check_ascii=0;
  17894. char str[501]={0};
  17895. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  17896. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  17897. {
  17898. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  17899. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  17900. {
  17901. strcpy(str, (const char*)value);
  17902. for(int i = 0; str[i]; i++){
  17903. str[i] = tolower(str[i]);
  17904. }
  17905. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17906. isSuccess = ConfigurationStatus_Accepted;
  17907. }
  17908. else
  17909. {
  17910. isSuccess = ConfigurationStatus_Rejected;
  17911. }
  17912. }
  17913. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  17914. {
  17915. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  17916. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  17917. {
  17918. strcpy(str, (const char*)value);
  17919. for(int i = 0; str[i]; i++){
  17920. str[i] = tolower(str[i]);
  17921. }
  17922. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17923. isSuccess = ConfigurationStatus_Accepted;
  17924. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  17925. }
  17926. else
  17927. {
  17928. isSuccess = ConfigurationStatus_Rejected;
  17929. }
  17930. }
  17931. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  17932. {
  17933. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  17934. {
  17935. strcpy(str, (const char*)value);
  17936. for(int i = 0; str[i]; i++)
  17937. {
  17938. str[i] = tolower(str[i]);
  17939. }
  17940. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  17941. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17942. isSuccess = ConfigurationStatus_Accepted;
  17943. }
  17944. else
  17945. {
  17946. isSuccess = ConfigurationStatus_Rejected;
  17947. }
  17948. }
  17949. if(strcmp(key, "BlinkRepeat") == 0)
  17950. {
  17951. //Charger.BlinkRepeat = Integer.parseInt(value);
  17952. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  17953. {
  17954. check_ascii = value[0];
  17955. if( (check_ascii < 48) || (check_ascii > 57) )
  17956. {
  17957. isSuccess = ConfigurationStatus_Rejected;
  17958. }
  17959. else
  17960. {
  17961. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  17962. isSuccess = ConfigurationStatus_Accepted;
  17963. }
  17964. }
  17965. else
  17966. {
  17967. isSuccess = ConfigurationStatus_Rejected;
  17968. }
  17969. }
  17970. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  17971. {
  17972. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  17973. {
  17974. check_ascii = value[0];
  17975. if( (check_ascii < 48) || (check_ascii > 57) )
  17976. {
  17977. isSuccess = ConfigurationStatus_Rejected;
  17978. }
  17979. else
  17980. {
  17981. if((atoi(value) == 0) || (atoi(value) >= 5))
  17982. {
  17983. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  17984. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  17985. isSuccess = ConfigurationStatus_Accepted;
  17986. }
  17987. else
  17988. isSuccess = ConfigurationStatus_Rejected;
  17989. }
  17990. }
  17991. else
  17992. {
  17993. isSuccess = ConfigurationStatus_Rejected;
  17994. }
  17995. }
  17996. if(strcmp(key, "ConnectionTimeOut") == 0 )
  17997. {
  17998. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  17999. {
  18000. check_ascii = value[0];
  18001. if( (check_ascii < 48) || (check_ascii > 57) )
  18002. {
  18003. isSuccess = ConfigurationStatus_Rejected;
  18004. }
  18005. else
  18006. {
  18007. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  18008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  18009. isSuccess = ConfigurationStatus_Accepted;
  18010. }
  18011. }
  18012. else
  18013. {
  18014. isSuccess = ConfigurationStatus_Rejected;
  18015. }
  18016. }
  18017. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  18018. {
  18019. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  18020. {
  18021. check_ascii = value[0];
  18022. if( (check_ascii < 48) || (check_ascii > 57) )
  18023. {
  18024. isSuccess = ConfigurationStatus_Rejected;
  18025. }
  18026. else
  18027. {
  18028. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18029. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  18030. isSuccess = ConfigurationStatus_Accepted;
  18031. }
  18032. }
  18033. else
  18034. {
  18035. isSuccess = ConfigurationStatus_Rejected;
  18036. }
  18037. }
  18038. if(strcmp(key, "HeartbeatInterval") == 0)
  18039. {
  18040. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  18041. {
  18042. check_ascii = value[0];
  18043. if( (check_ascii < 48) || (check_ascii > 57) )
  18044. {
  18045. isSuccess = ConfigurationStatus_Rejected;
  18046. }
  18047. else
  18048. {
  18049. if((atoi(value) == 0) || (atoi(value) >= 10))
  18050. {
  18051. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  18053. HeartBeatWaitTime = atoi(value);
  18054. isSuccess = ConfigurationStatus_Accepted;
  18055. }
  18056. else
  18057. {
  18058. isSuccess = ConfigurationStatus_Rejected;
  18059. }
  18060. }
  18061. }
  18062. else
  18063. {
  18064. isSuccess = ConfigurationStatus_Rejected;
  18065. }
  18066. }
  18067. if(strcmp(key, "LightIntensity") == 0)
  18068. {
  18069. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  18070. {
  18071. check_ascii = value[0];
  18072. if( (check_ascii < 48) || (check_ascii > 57) )
  18073. {
  18074. isSuccess = ConfigurationStatus_Rejected;
  18075. }
  18076. else
  18077. {
  18078. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  18079. isSuccess = ConfigurationStatus_Accepted;
  18080. }
  18081. }
  18082. else
  18083. {
  18084. isSuccess = ConfigurationStatus_Rejected;
  18085. }
  18086. }
  18087. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  18088. {
  18089. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  18090. {
  18091. strcpy(str, (const char*)value);
  18092. for(int i = 0; str[i]; i++)
  18093. {
  18094. str[i] = tolower(str[i]);
  18095. }
  18096. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18097. isSuccess = ConfigurationStatus_Accepted;
  18098. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  18099. }
  18100. else
  18101. {
  18102. isSuccess = ConfigurationStatus_Rejected;
  18103. }
  18104. }
  18105. if(strcmp(key, "LocalPreAuthorize") == 0)
  18106. {
  18107. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  18108. {
  18109. strcpy(str, (const char*)value);
  18110. for(int i = 0; str[i]; i++)
  18111. {
  18112. str[i] = tolower(str[i]);
  18113. }
  18114. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18115. isSuccess = ConfigurationStatus_Accepted;
  18116. }
  18117. else
  18118. {
  18119. isSuccess = ConfigurationStatus_Rejected;
  18120. }
  18121. }
  18122. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  18123. {
  18124. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  18125. {
  18126. check_ascii = value[0];
  18127. if( (check_ascii < 48) || (check_ascii > 57) )
  18128. {
  18129. isSuccess = ConfigurationStatus_Rejected;
  18130. }
  18131. else
  18132. {
  18133. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  18134. isSuccess = ConfigurationStatus_Accepted;
  18135. }
  18136. }
  18137. else
  18138. {
  18139. isSuccess = ConfigurationStatus_Rejected;
  18140. }
  18141. }
  18142. if(strcmp(key, "MeterValuesAlignedData") == 0)
  18143. {
  18144. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  18145. {
  18146. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  18147. isSuccess = ConfigurationStatus_Accepted;
  18148. }
  18149. else
  18150. {
  18151. isSuccess = ConfigurationStatus_Rejected;
  18152. }
  18153. }
  18154. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  18155. {
  18156. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  18157. {
  18158. check_ascii = value[0];
  18159. if( (check_ascii < 48) || (check_ascii > 57) )
  18160. {
  18161. isSuccess = ConfigurationStatus_Rejected;
  18162. }
  18163. else
  18164. {
  18165. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18166. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  18167. isSuccess = ConfigurationStatus_Accepted;
  18168. }
  18169. }
  18170. else
  18171. {
  18172. isSuccess = ConfigurationStatus_Rejected;
  18173. }
  18174. }
  18175. if(strcmp(key, "MeterValuesSampledData") == 0 )
  18176. {
  18177. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  18178. {
  18179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  18180. isSuccess = ConfigurationStatus_Accepted;
  18181. }
  18182. else
  18183. {
  18184. isSuccess = ConfigurationStatus_Rejected;
  18185. }
  18186. }
  18187. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  18188. {
  18189. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  18190. {
  18191. check_ascii = value[0];
  18192. if( (check_ascii < 48) || (check_ascii > 57) )
  18193. {
  18194. isSuccess = ConfigurationStatus_Rejected;
  18195. }
  18196. else
  18197. {
  18198. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18199. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  18200. isSuccess = ConfigurationStatus_Accepted;
  18201. }
  18202. }
  18203. else
  18204. {
  18205. isSuccess = ConfigurationStatus_Rejected;
  18206. }
  18207. }
  18208. if(strcmp(key, "MeterValueSampleInterval") == 0)
  18209. {
  18210. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  18211. {
  18212. check_ascii = value[0];
  18213. if( (check_ascii < 48) || (check_ascii > 57) )
  18214. {
  18215. isSuccess = ConfigurationStatus_Rejected;
  18216. }
  18217. else
  18218. {
  18219. if((atoi(value) == 0) || (atoi(value) >= 3))
  18220. {
  18221. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  18223. isSuccess = ConfigurationStatus_Accepted;
  18224. }
  18225. else
  18226. {
  18227. isSuccess = ConfigurationStatus_Rejected;
  18228. }
  18229. }
  18230. }
  18231. else
  18232. {
  18233. isSuccess = ConfigurationStatus_Rejected;
  18234. }
  18235. }
  18236. if(strcmp(key, "MinimumStatusDuration") == 0)
  18237. {
  18238. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  18239. {
  18240. check_ascii = value[0];
  18241. if( (check_ascii < 48) || (check_ascii > 57) )
  18242. {
  18243. isSuccess = ConfigurationStatus_Rejected;
  18244. }
  18245. else
  18246. {
  18247. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  18248. {
  18249. isSuccess = ConfigurationStatus_Rejected;
  18250. }
  18251. else
  18252. {
  18253. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  18254. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  18255. server_cycle_Status = atoi(value); //StatusNotification Cycle
  18256. isSuccess = ConfigurationStatus_Accepted;
  18257. }
  18258. }
  18259. }
  18260. else
  18261. {
  18262. isSuccess = ConfigurationStatus_Rejected;
  18263. }
  18264. }
  18265. if(strcmp(key, "NumberOfConnectors") == 0)
  18266. {
  18267. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  18268. {
  18269. check_ascii = value[0];
  18270. if( (check_ascii < 48) || (check_ascii > 57) )
  18271. {
  18272. isSuccess = ConfigurationStatus_Rejected;
  18273. }
  18274. else
  18275. {
  18276. //Charger.ResetRetries = Integer.parseInt(value);
  18277. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  18278. isSuccess = ConfigurationStatus_Accepted;
  18279. }
  18280. }
  18281. else
  18282. {
  18283. isSuccess = ConfigurationStatus_Rejected;
  18284. }
  18285. }
  18286. if(strcmp(key, "ResetRetries") == 0)
  18287. {
  18288. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  18289. {
  18290. check_ascii = value[0];
  18291. if( (check_ascii < 48) || (check_ascii > 57) )
  18292. {
  18293. isSuccess = ConfigurationStatus_Rejected;
  18294. }
  18295. else
  18296. {
  18297. //Charger.ResetRetries = Integer.parseInt(value);
  18298. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  18299. isSuccess = ConfigurationStatus_Accepted;
  18300. }
  18301. }
  18302. else
  18303. {
  18304. isSuccess = ConfigurationStatus_Rejected;
  18305. }
  18306. }
  18307. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  18308. {
  18309. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  18310. {
  18311. strcpy(str, (const char*)value);
  18312. for(int i = 0; str[i]; i++)
  18313. {
  18314. str[i] = tolower(str[i]);
  18315. }
  18316. if(strcmp(str, "notapplicable")== 0)
  18317. {
  18318. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  18319. isSuccess = ConfigurationStatus_Accepted;
  18320. }
  18321. else if(strcmp(str, "unknown")== 0)
  18322. {
  18323. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  18324. isSuccess = ConfigurationStatus_Accepted;
  18325. }
  18326. else if(strcmp(str, "rst")== 0)
  18327. {
  18328. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  18329. isSuccess = ConfigurationStatus_Accepted;
  18330. }
  18331. else if(strcmp(str, "rts")== 0)
  18332. {
  18333. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  18334. isSuccess = ConfigurationStatus_Accepted;
  18335. }
  18336. else if(strcmp(str, "srt")== 0)
  18337. {
  18338. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  18339. isSuccess = ConfigurationStatus_Accepted;
  18340. }
  18341. else if(strcmp(str, "str")== 0)
  18342. {
  18343. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  18344. isSuccess = ConfigurationStatus_Accepted;
  18345. }
  18346. else if(strcmp(str, "trs")== 0)
  18347. {
  18348. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  18349. isSuccess = ConfigurationStatus_Accepted;
  18350. }
  18351. else if(strcmp(str, "tsr")== 0)
  18352. {
  18353. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  18354. isSuccess = ConfigurationStatus_Accepted;
  18355. }
  18356. else
  18357. {
  18358. isSuccess = ConfigurationStatus_Rejected;
  18359. }
  18360. }
  18361. else
  18362. {
  18363. isSuccess = ConfigurationStatus_Rejected;
  18364. }
  18365. }
  18366. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  18367. {
  18368. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  18369. {
  18370. check_ascii = value[0];
  18371. if( (check_ascii < 48) || (check_ascii > 57) )
  18372. {
  18373. isSuccess = ConfigurationStatus_Rejected;
  18374. }
  18375. else
  18376. {
  18377. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  18378. isSuccess = ConfigurationStatus_Accepted;
  18379. }
  18380. }
  18381. else
  18382. {
  18383. isSuccess = ConfigurationStatus_Rejected;
  18384. }
  18385. }
  18386. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  18387. {
  18388. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  18389. {
  18390. strcpy(str, (const char*)value);
  18391. for(int i = 0; str[i]; i++)
  18392. {
  18393. str[i] = tolower(str[i]);
  18394. }
  18395. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18396. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18397. isSuccess = ConfigurationStatus_Accepted;
  18398. }
  18399. else
  18400. {
  18401. isSuccess = ConfigurationStatus_Rejected;
  18402. }
  18403. }
  18404. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  18405. {
  18406. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  18407. {
  18408. strcpy(str, (const char*)value);
  18409. for(int i = 0; str[i]; i++)
  18410. {
  18411. str[i] = tolower(str[i]);
  18412. }
  18413. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  18414. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18415. isSuccess = ConfigurationStatus_Accepted;
  18416. }
  18417. else
  18418. {
  18419. isSuccess = ConfigurationStatus_Rejected;
  18420. }
  18421. }
  18422. if(strcmp(key, "StopTxnAlignedData") == 0)
  18423. {
  18424. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  18425. {
  18426. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  18427. isSuccess = ConfigurationStatus_Accepted;
  18428. }
  18429. else
  18430. {
  18431. isSuccess = ConfigurationStatus_Rejected;
  18432. }
  18433. }
  18434. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  18435. {
  18436. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  18437. {
  18438. check_ascii = value[0];
  18439. if( (check_ascii < 48) || (check_ascii > 57) )
  18440. {
  18441. isSuccess = ConfigurationStatus_Rejected;
  18442. }
  18443. else
  18444. {
  18445. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  18446. isSuccess = ConfigurationStatus_Accepted;
  18447. }
  18448. }
  18449. else
  18450. {
  18451. isSuccess = ConfigurationStatus_Rejected;
  18452. }
  18453. }
  18454. if(strcmp(key, "StopTxnSampledData") == 0)
  18455. {
  18456. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  18457. {
  18458. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  18459. isSuccess = ConfigurationStatus_Accepted;
  18460. }
  18461. else
  18462. {
  18463. isSuccess = ConfigurationStatus_Rejected;
  18464. }
  18465. }
  18466. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  18467. {
  18468. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  18469. {
  18470. check_ascii = value[0];
  18471. if( (check_ascii < 48) || (check_ascii > 57) )
  18472. {
  18473. isSuccess = ConfigurationStatus_Rejected;
  18474. }
  18475. else
  18476. {
  18477. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  18478. isSuccess = ConfigurationStatus_Accepted;
  18479. }
  18480. }
  18481. else
  18482. {
  18483. isSuccess = ConfigurationStatus_Rejected;
  18484. }
  18485. }
  18486. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  18487. {
  18488. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  18489. {
  18490. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  18491. isSuccess = ConfigurationStatus_Accepted;
  18492. }
  18493. else
  18494. {
  18495. isSuccess = ConfigurationStatus_Rejected;
  18496. }
  18497. }
  18498. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  18499. {
  18500. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  18501. {
  18502. check_ascii = value[0];
  18503. if( (check_ascii < 48) || (check_ascii > 57) )
  18504. {
  18505. isSuccess = ConfigurationStatus_Rejected;
  18506. }
  18507. else
  18508. {
  18509. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  18510. isSuccess = ConfigurationStatus_Accepted;
  18511. }
  18512. }
  18513. else
  18514. {
  18515. isSuccess = ConfigurationStatus_Rejected;
  18516. }
  18517. }
  18518. if(strcmp(key, "TransactionMessageAttempts") == 0)
  18519. {
  18520. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  18521. {
  18522. check_ascii = value[0];
  18523. if( (check_ascii < 48) || (check_ascii > 57) )
  18524. {
  18525. isSuccess = ConfigurationStatus_Rejected;
  18526. }
  18527. else
  18528. {
  18529. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  18530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  18531. TransactionMessageAttemptsValue = atoi(value);
  18532. isSuccess = ConfigurationStatus_Accepted;
  18533. }
  18534. }
  18535. else
  18536. {
  18537. isSuccess = ConfigurationStatus_Rejected;
  18538. }
  18539. }
  18540. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  18541. {
  18542. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  18543. {
  18544. check_ascii = value[0];
  18545. if( (check_ascii < 48) || (check_ascii > 57) )
  18546. {
  18547. isSuccess = ConfigurationStatus_Rejected;
  18548. }
  18549. else
  18550. {
  18551. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  18552. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  18553. TransactionMessageRetryIntervalValue = atoi(value);
  18554. isSuccess = ConfigurationStatus_Accepted;
  18555. }
  18556. }
  18557. else
  18558. {
  18559. isSuccess = ConfigurationStatus_Rejected;
  18560. }
  18561. }
  18562. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  18563. {
  18564. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  18565. {
  18566. strcpy(str, (const char*)value);
  18567. for(int i = 0; str[i]; i++)
  18568. {
  18569. str[i] = tolower(str[i]);
  18570. }
  18571. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18573. isSuccess = ConfigurationStatus_Accepted;
  18574. }
  18575. else
  18576. {
  18577. isSuccess = ConfigurationStatus_Rejected;
  18578. }
  18579. }
  18580. if(strcmp(key, "WebSocketPingInterval") == 0)
  18581. {
  18582. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  18583. {
  18584. check_ascii = value[0];
  18585. if( (check_ascii < 48) || (check_ascii > 57) )
  18586. {
  18587. isSuccess = ConfigurationStatus_Rejected;
  18588. }
  18589. else
  18590. {
  18591. if((atoi(value) == 0) || (atoi(value) >= 10))
  18592. {
  18593. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  18594. isSuccess = ConfigurationStatus_Accepted;
  18595. }
  18596. else
  18597. isSuccess = ConfigurationStatus_Rejected;
  18598. }
  18599. }
  18600. else
  18601. {
  18602. isSuccess = ConfigurationStatus_Rejected;
  18603. }
  18604. }
  18605. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  18606. {
  18607. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  18608. {
  18609. strcpy(str, (const char*)value);
  18610. for(int i = 0; str[i]; i++)
  18611. {
  18612. str[i] = tolower(str[i]);
  18613. }
  18614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18615. isSuccess = ConfigurationStatus_Accepted;
  18616. }
  18617. else
  18618. {
  18619. isSuccess = ConfigurationStatus_Rejected;
  18620. }
  18621. }
  18622. if(strcmp(key, "AuthorizationKey") == 0)
  18623. {
  18624. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  18625. {
  18626. strcpy(str, (const char*)value);
  18627. int strlength = strlen(str);
  18628. char capture[3];
  18629. char stackItem = 0;
  18630. char password[21] = {0};
  18631. printf("String length: %d\n", strlength);
  18632. for(int idx=0; idx<(strlength/2); idx++)
  18633. {
  18634. capture[0] = str[(idx*2)];
  18635. capture[1] = str[(idx*2)+1];
  18636. capture[2] = 0;
  18637. stackItem = (char)strtol(capture, NULL, 16); // number base 16
  18638. sprintf(password,"%s%c", password, stackItem);
  18639. }
  18640. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", password);
  18641. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18642. isSuccess = ConfigurationStatus_Accepted;
  18643. }
  18644. else
  18645. {
  18646. isSuccess = ConfigurationStatus_Rejected;
  18647. }
  18648. }
  18649. if(strcmp(key, "SecurityProfile") == 0)
  18650. {
  18651. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  18652. {
  18653. check_ascii = value[0];
  18654. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  18655. {
  18656. isSuccess = ConfigurationStatus_Rejected;
  18657. }
  18658. else if(check_ascii == 0x33)
  18659. {
  18660. isSuccess = NotSupported;
  18661. }
  18662. else
  18663. {
  18664. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  18665. {
  18666. if(((check_ascii - 0x30) == 1) ||
  18667. ((check_ascii - 0x30) == 2) ||
  18668. (((check_ascii - 0x30) == 3) && (access(CERTIFICATE_CP,F_OK) != -1)))
  18669. {
  18670. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  18671. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  18672. isSuccess = ConfigurationStatus_Accepted;
  18673. }
  18674. else
  18675. isSuccess = ConfigurationStatus_Rejected;
  18676. }
  18677. else
  18678. isSuccess = ConfigurationStatus_Rejected;
  18679. }
  18680. }
  18681. else
  18682. {
  18683. isSuccess = ConfigurationStatus_Rejected;
  18684. }
  18685. }
  18686. if(strcmp(key, "DefaultPrice") == 0)
  18687. {
  18688. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  18689. {
  18690. strcpy(str, (const char*)value);
  18691. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  18692. isSuccess = ConfigurationStatus_Accepted;
  18693. }
  18694. else
  18695. {
  18696. isSuccess = ConfigurationStatus_Rejected;
  18697. }
  18698. }
  18699. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  18700. {
  18701. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  18702. {
  18703. strcpy(str, (const char*)value);
  18704. for(int i = 0; str[i]; i++)
  18705. {
  18706. str[i] = tolower(str[i]);
  18707. }
  18708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18709. isSuccess = ConfigurationStatus_Accepted;
  18710. }
  18711. else
  18712. {
  18713. isSuccess = ConfigurationStatus_Rejected;
  18714. }
  18715. }
  18716. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  18717. {
  18718. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  18719. {
  18720. strcpy(str, (const char*)value);
  18721. for(int i = 0; str[i]; i++)
  18722. {
  18723. str[i] = tolower(str[i]);
  18724. }
  18725. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18726. isSuccess = ConfigurationStatus_Accepted;
  18727. }
  18728. else
  18729. {
  18730. isSuccess = ConfigurationStatus_Rejected;
  18731. }
  18732. }
  18733. if(strcmp(key, "TimeOffset") == 0)
  18734. {
  18735. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  18736. {
  18737. strcpy(str, (const char*)value);
  18738. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  18739. isSuccess = ConfigurationStatus_Accepted;
  18740. }
  18741. else
  18742. {
  18743. isSuccess = ConfigurationStatus_Rejected;
  18744. }
  18745. }
  18746. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  18747. {
  18748. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  18749. {
  18750. strcpy(str, (const char*)value);
  18751. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  18752. isSuccess = ConfigurationStatus_Accepted;
  18753. }
  18754. else
  18755. {
  18756. isSuccess = ConfigurationStatus_Rejected;
  18757. }
  18758. }
  18759. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  18760. {
  18761. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  18762. {
  18763. strcpy(str, (const char*)value);
  18764. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  18765. isSuccess = ConfigurationStatus_Accepted;
  18766. }
  18767. else
  18768. {
  18769. isSuccess = ConfigurationStatus_Rejected;
  18770. }
  18771. }
  18772. if(strcmp(key, "SystemUptimeSec") == 0)
  18773. {
  18774. isSuccess = NotSupported;
  18775. }
  18776. if(strcmp(key, "FreeVend") == 0)
  18777. {
  18778. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  18779. {
  18780. strcpy(str, (const char*)value);
  18781. for(int i = 0; str[i]; i++)
  18782. {
  18783. str[i] = tolower(str[i]);
  18784. }
  18785. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  18786. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18787. isSuccess = ConfigurationStatus_Accepted;
  18788. }
  18789. else
  18790. {
  18791. isSuccess = ConfigurationStatus_Rejected;
  18792. }
  18793. }
  18794. if(strcmp(key, "FreeVendIdtag") == 0)
  18795. {
  18796. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  18797. {
  18798. strcpy(str, (const char*)value);
  18799. if(strlen(str) <= 20)
  18800. {
  18801. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  18802. isSuccess = ConfigurationStatus_Accepted;
  18803. }
  18804. else
  18805. {
  18806. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  18807. isSuccess = ConfigurationStatus_Rejected;
  18808. }
  18809. }
  18810. else
  18811. {
  18812. isSuccess = ConfigurationStatus_Rejected;
  18813. }
  18814. }
  18815. if(strcmp(key, "OcppServer") == 0)
  18816. {
  18817. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  18818. {
  18819. strcpy(str, (const char*)value);
  18820. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  18821. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  18822. isSuccess = ConfigurationStatus_Accepted;
  18823. }
  18824. else
  18825. {
  18826. isSuccess = ConfigurationStatus_Rejected;
  18827. }
  18828. }
  18829. if(strcmp(key, "MaintainServer") == 0)
  18830. {
  18831. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  18832. {
  18833. strcpy(str, (const char*)value);
  18834. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  18835. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  18836. isSuccess = ConfigurationStatus_Accepted;
  18837. }
  18838. else
  18839. {
  18840. isSuccess = ConfigurationStatus_Rejected;
  18841. }
  18842. }
  18843. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  18844. {
  18845. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  18846. {
  18847. strcpy(str, (const char*)value);
  18848. for(int i = 0; str[i]; i++)
  18849. {
  18850. str[i] = tolower(str[i]);
  18851. }
  18852. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  18853. isSuccess = ConfigurationStatus_Accepted;
  18854. }
  18855. else
  18856. {
  18857. isSuccess = ConfigurationStatus_Rejected;
  18858. }
  18859. }
  18860. if(strcmp(key, "StatusNotificationInterval") == 0)
  18861. {
  18862. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  18863. {
  18864. check_ascii = value[0];
  18865. if( (check_ascii < 48) || (check_ascii > 57) )
  18866. {
  18867. isSuccess = ConfigurationStatus_Rejected;
  18868. }
  18869. else
  18870. {
  18871. if((atoi(value) == 0) || (atoi(value) >= 10))
  18872. {
  18873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  18874. isSuccess = ConfigurationStatus_Accepted;
  18875. }
  18876. else
  18877. isSuccess = ConfigurationStatus_Rejected;
  18878. }
  18879. }
  18880. else
  18881. {
  18882. isSuccess = ConfigurationStatus_Rejected;
  18883. }
  18884. }
  18885. if(strcmp(key, "PreAuthAmount") == 0)
  18886. {
  18887. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  18888. {
  18889. check_ascii = value[0];
  18890. if( (check_ascii < 48) || (check_ascii > 57) )
  18891. {
  18892. isSuccess = ConfigurationStatus_Rejected;
  18893. }
  18894. else
  18895. {
  18896. if(atof(value) >= 0)
  18897. {
  18898. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  18899. isSuccess = ConfigurationStatus_Accepted;
  18900. }
  18901. else
  18902. isSuccess = ConfigurationStatus_Rejected;
  18903. }
  18904. }
  18905. else
  18906. {
  18907. isSuccess = ConfigurationStatus_Rejected;
  18908. }
  18909. }
  18910. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  18911. {
  18912. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  18913. {
  18914. check_ascii = value[0];
  18915. if( (check_ascii < 48) || (check_ascii > 57) )
  18916. {
  18917. isSuccess = ConfigurationStatus_Rejected;
  18918. }
  18919. else
  18920. {
  18921. if(atoi(value) >= 0)
  18922. {
  18923. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  18924. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  18925. isSuccess = ConfigurationStatus_Accepted;
  18926. }
  18927. else
  18928. isSuccess = ConfigurationStatus_Rejected;
  18929. }
  18930. }
  18931. else
  18932. {
  18933. isSuccess = ConfigurationStatus_Rejected;
  18934. }
  18935. }
  18936. if(strcmp(key, "PowerSharingServerIP") == 0)
  18937. {
  18938. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  18939. {
  18940. strcpy(str, (const char*)value);
  18941. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  18942. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  18943. isSuccess = ConfigurationStatus_Accepted;
  18944. }
  18945. else
  18946. {
  18947. isSuccess = ConfigurationStatus_Rejected;
  18948. }
  18949. }
  18950. if(strcmp(key, "EVCCID_PREFIX") == 0)
  18951. {
  18952. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  18953. {
  18954. strcpy(str, (const char*)value);
  18955. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  18956. isSuccess = ConfigurationStatus_Accepted;
  18957. }
  18958. else
  18959. {
  18960. isSuccess = ConfigurationStatus_Rejected;
  18961. }
  18962. }
  18963. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  18964. {
  18965. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  18966. {
  18967. if(atoi(value) > modelnameInfo.ratedPower)
  18968. {
  18969. isSuccess = ConfigurationStatus_Rejected;
  18970. }
  18971. else{
  18972. strcpy(str, (const char*)value);
  18973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  18974. isSuccess = ConfigurationStatus_Accepted;
  18975. }
  18976. }
  18977. else
  18978. {
  18979. isSuccess = ConfigurationStatus_Rejected;
  18980. }
  18981. }
  18982. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  18983. {
  18984. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  18985. {
  18986. if((atoi(value) != 0) && (atoi(value) < 5))
  18987. {
  18988. isSuccess = ConfigurationStatus_Rejected;
  18989. }
  18990. else{
  18991. strcpy(str, (const char*)value);
  18992. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  18993. isSuccess = ConfigurationStatus_Accepted;
  18994. }
  18995. }
  18996. else
  18997. {
  18998. isSuccess = ConfigurationStatus_Rejected;
  18999. }
  19000. }
  19001. if(strcmp(key, "CpoName") == 0)
  19002. {
  19003. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  19004. {
  19005. strcpy(str, (const char*)value);
  19006. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", str );
  19007. isSuccess = ConfigurationStatus_Accepted;
  19008. }
  19009. else
  19010. {
  19011. isSuccess = ConfigurationStatus_Rejected;
  19012. }
  19013. }
  19014. #if 0
  19015. //For OCPP Test Case
  19016. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  19017. {
  19018. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19019. {
  19020. strcpy(str, (const char*)value);
  19021. for(int i = 0; str[i]; i++)
  19022. {
  19023. str[i] = tolower(str[i]);
  19024. }
  19025. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19026. isSuccess = ConfigurationStatus_Accepted;
  19027. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19028. }
  19029. else
  19030. {
  19031. isSuccess = ConfigurationStatus_Rejected;
  19032. }
  19033. }
  19034. #endif
  19035. #if 1
  19036. if(strcmp(key, "LocalAuthListEnabled") == 0)
  19037. {
  19038. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19039. {
  19040. strcpy(str, (const char*)value);
  19041. for(int i = 0; str[i]; i++)
  19042. {
  19043. str[i] = tolower(str[i]);
  19044. }
  19045. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19046. isSuccess = ConfigurationStatus_Accepted;
  19047. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19048. }
  19049. else
  19050. {
  19051. isSuccess = ConfigurationStatus_Rejected;
  19052. }
  19053. }
  19054. #endif
  19055. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  19056. {
  19057. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  19058. {
  19059. check_ascii = value[0];
  19060. if( (check_ascii < 48) || (check_ascii > 57) )
  19061. {
  19062. isSuccess = ConfigurationStatus_Rejected;
  19063. }
  19064. else
  19065. {
  19066. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  19067. isSuccess = ConfigurationStatus_Accepted;
  19068. }
  19069. }
  19070. else
  19071. {
  19072. isSuccess = ConfigurationStatus_Rejected;
  19073. }
  19074. }
  19075. if(strcmp(key, "SendLocalListMaxLength") == 0)
  19076. {
  19077. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  19078. {
  19079. check_ascii = value[0];
  19080. if( (check_ascii < 48) || (check_ascii > 57) )
  19081. {
  19082. isSuccess = ConfigurationStatus_Rejected;
  19083. }
  19084. else
  19085. {
  19086. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  19087. isSuccess = ConfigurationStatus_Accepted;
  19088. }
  19089. }
  19090. else
  19091. {
  19092. isSuccess = ConfigurationStatus_Rejected;
  19093. }
  19094. }
  19095. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  19096. {
  19097. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  19098. {
  19099. strcpy(str, (const char*)value);
  19100. for(int i = 0; str[i]; i++)
  19101. {
  19102. str[i] = tolower(str[i]);
  19103. }
  19104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19105. isSuccess = ConfigurationStatus_Accepted;
  19106. }
  19107. else
  19108. {
  19109. isSuccess = ConfigurationStatus_Rejected;
  19110. }
  19111. }
  19112. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  19113. {
  19114. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  19115. {
  19116. check_ascii = value[0];
  19117. if( (check_ascii < 48) || (check_ascii > 57) )
  19118. {
  19119. isSuccess = ConfigurationStatus_Rejected;
  19120. }
  19121. else
  19122. {
  19123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  19124. isSuccess = ConfigurationStatus_Accepted;
  19125. }
  19126. }
  19127. else
  19128. {
  19129. isSuccess = ConfigurationStatus_Rejected;
  19130. }
  19131. }
  19132. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  19133. {
  19134. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  19135. {
  19136. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  19137. isSuccess = ConfigurationStatus_Accepted;
  19138. }
  19139. else
  19140. {
  19141. isSuccess = ConfigurationStatus_Rejected;
  19142. }
  19143. }
  19144. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  19145. {
  19146. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  19147. {
  19148. check_ascii = value[0];
  19149. if( (check_ascii < 48) || (check_ascii > 57) )
  19150. {
  19151. isSuccess = ConfigurationStatus_Rejected;
  19152. }
  19153. else
  19154. {
  19155. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  19156. isSuccess = ConfigurationStatus_Accepted;
  19157. }
  19158. }
  19159. else
  19160. {
  19161. isSuccess = ConfigurationStatus_Rejected;
  19162. }
  19163. }
  19164. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  19165. {
  19166. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  19167. {
  19168. strcpy(str, (const char*)value);
  19169. for(int i = 0; str[i]; i++)
  19170. {
  19171. str[i] = tolower(str[i]);
  19172. }
  19173. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19174. isSuccess = ConfigurationStatus_Accepted;
  19175. }
  19176. else
  19177. {
  19178. isSuccess = ConfigurationStatus_Rejected;
  19179. }
  19180. }
  19181. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  19182. {
  19183. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  19184. {
  19185. check_ascii = value[0];
  19186. if( (check_ascii < 48) || (check_ascii > 57) )
  19187. {
  19188. isSuccess = ConfigurationStatus_Rejected;
  19189. }
  19190. else
  19191. {
  19192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  19193. isSuccess = ConfigurationStatus_Accepted;
  19194. }
  19195. }
  19196. else
  19197. {
  19198. isSuccess = ConfigurationStatus_Rejected;
  19199. }
  19200. }
  19201. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19202. return isSuccess;
  19203. }
  19204. int TransactionMessageAttemptsGet(void)
  19205. {
  19206. return TransactionMessageAttemptsValue;
  19207. }
  19208. int FirstHeartBeatResponse(void)
  19209. {
  19210. return FirstHeartBeat;
  19211. }
  19212. int TransactionMessageRetryIntervalGet(void)
  19213. {
  19214. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19215. }
  19216. int ReadHttpStatus(int sock)
  19217. {
  19218. //char c;
  19219. char buff[1024]="",*ptr=buff+1;
  19220. int bytes_received, status;
  19221. DEBUG_INFO("Begin Response ..\n");
  19222. while((bytes_received = recv(sock, ptr, 1, 0))){
  19223. if(bytes_received==-1){
  19224. perror("ReadHttpStatus");
  19225. exit(1);
  19226. }
  19227. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  19228. ptr++;
  19229. }
  19230. *ptr=0;
  19231. ptr=buff+1;
  19232. sscanf(ptr,"%*s %d ", &status);
  19233. DEBUG_INFO("%s\n",ptr);
  19234. DEBUG_INFO("status=%d\n",status);
  19235. DEBUG_INFO("End Response ..\n");
  19236. return (bytes_received>0)?status:0;
  19237. }
  19238. //the only filed that it parsed is 'Content-Length'
  19239. int ParseHeader(int sock)
  19240. {
  19241. //char c;
  19242. char buff[1024]="",*ptr=buff+4;
  19243. int bytes_received;
  19244. DEBUG_INFO("Begin HEADER ..\n");
  19245. while((bytes_received = recv(sock, ptr, 1, 0))){
  19246. if(bytes_received==-1){
  19247. perror("Parse Header");
  19248. exit(1);
  19249. }
  19250. if(
  19251. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  19252. (ptr[-1]=='\r') && (*ptr=='\n' )
  19253. ) break;
  19254. ptr++;
  19255. }
  19256. *ptr=0;
  19257. ptr=buff+4;
  19258. //printf("%s",ptr);
  19259. if(bytes_received){
  19260. ptr=strstr(ptr,"Content-Length:");
  19261. if(ptr){
  19262. sscanf(ptr,"%*s %d",&bytes_received);
  19263. }else
  19264. bytes_received=-1; //unknown size
  19265. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  19266. }
  19267. DEBUG_INFO("End HEADER ..\n");
  19268. return bytes_received ;
  19269. }
  19270. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  19271. {
  19272. int result = TRUE;
  19273. char rmFileCmd[100]={0};
  19274. char FilePath[100]={0};
  19275. char ftpbuf[200];
  19276. int systemresult;
  19277. sprintf(FilePath,"/mnt/%s",filename);
  19278. system("ping 8.8.8.8 &");
  19279. if((access(FilePath,F_OK))!=-1)
  19280. {
  19281. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19282. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19283. system(rmFileCmd);
  19284. }
  19285. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19286. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  19287. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19288. systemresult = system(ftpbuf);
  19289. if(systemresult != 0)
  19290. {
  19291. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  19292. result = FALSE;
  19293. }
  19294. system("pkill ping");
  19295. return result;
  19296. }
  19297. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  19298. {
  19299. int result = TRUE;
  19300. char rmFileCmd[100]={0};
  19301. char FilePath[100]={0};
  19302. char ftpbuf[200];
  19303. int systemresult;
  19304. sprintf(FilePath,"/mnt/%s",filename);
  19305. system("ping 8.8.8.8 &");
  19306. if((access(FilePath,F_OK))!=-1)
  19307. {
  19308. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19309. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19310. system(rmFileCmd);
  19311. }
  19312. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19313. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  19314. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19315. systemresult = system(ftpbuf);
  19316. if(systemresult != 0)
  19317. {
  19318. DEBUG_WARN("scp error!\n");
  19319. result = FALSE;
  19320. }
  19321. system("pkill ping");
  19322. return result;
  19323. }
  19324. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  19325. {
  19326. int result = TRUE;
  19327. char rmFileCmd[100]={0};
  19328. char FilePath[100]={0};
  19329. char ftpbuf[200];
  19330. int systemresult;
  19331. sprintf(FilePath,"/mnt/%s",filename);
  19332. system("ping 8.8.8.8 &");
  19333. if((access(FilePath,F_OK))!=-1)
  19334. {
  19335. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19336. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19337. system(rmFileCmd);
  19338. }
  19339. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19340. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  19341. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19342. systemresult = system(ftpbuf);
  19343. if(systemresult != 0)
  19344. {
  19345. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  19346. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19347. systemresult = system(ftpbuf);
  19348. if(systemresult != 0)
  19349. {
  19350. DEBUG_WARN("FTP download fail!\n");
  19351. result = FALSE;
  19352. }
  19353. }
  19354. system("pkill ping");
  19355. return result;
  19356. }
  19357. int httpUploadFile(char *location, char *path, char *filename,char *url)
  19358. {
  19359. char rmFileCmd[100]={0};
  19360. char FilePath[100]={0};
  19361. char buf[512];
  19362. int systemresult = 0;
  19363. //DEBUG_INFO("filename=%s\n",filename);
  19364. //DEBUG_INFO("url=%s\n",url);
  19365. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  19366. if((access(FilePath,F_OK))!=-1)
  19367. {
  19368. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19369. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19370. system(rmFileCmd);
  19371. }
  19372. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  19373. if(fp == NULL)
  19374. {
  19375. DEBUG_INFO("log is NULL\n");
  19376. return FALSE;
  19377. }
  19378. else
  19379. {
  19380. fprintf(fp, "%s\n", url);
  19381. fprintf(fp, "%s\n", filename);
  19382. fclose(fp);
  19383. }
  19384. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  19385. if(phpFP == NULL)
  19386. {
  19387. DEBUG_INFO("PHP upload fail.\n");
  19388. return FALSE;
  19389. }
  19390. else
  19391. {
  19392. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19393. {
  19394. if(strstr(buf, "result") != NULL)
  19395. {
  19396. sscanf(buf, "result: %d", &systemresult);
  19397. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  19398. }
  19399. }
  19400. pclose(phpFP);
  19401. }
  19402. if(systemresult != 1)
  19403. {
  19404. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  19405. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  19406. if(phpFP == NULL)
  19407. {
  19408. DEBUG_WARN("PHP PUT upload fail.\n");
  19409. return FALSE;
  19410. }
  19411. else
  19412. {
  19413. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19414. {
  19415. if(strstr(buf, "result") != NULL)
  19416. {
  19417. sscanf(buf, "result: %d", &systemresult);
  19418. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  19419. }
  19420. }
  19421. pclose(phpFP);
  19422. }
  19423. }
  19424. if(systemresult != 1)
  19425. {
  19426. DEBUG_WARN("PHP PUT upload fail.\n");
  19427. return FALSE;
  19428. }
  19429. return TRUE;
  19430. }
  19431. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  19432. {
  19433. int result = FALSE;
  19434. char ftpbuf[200];
  19435. int systemresult;
  19436. /*
  19437. // Domaind name transfer to IP address
  19438. struct hostent* server;
  19439. char *IPbuffer;
  19440. server = gethostbyname(location);
  19441. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  19442. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19443. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  19444. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  19445. systemresult = system(ftpbuf);
  19446. if(systemresult != 0)
  19447. {
  19448. DEBUG_INFO("ftpput error!\n");
  19449. }
  19450. else
  19451. {
  19452. result = TRUE;
  19453. DEBUG_INFO("ftpput OK!\n");
  19454. }
  19455. return result;
  19456. }
  19457. int GetOcppServerURL()
  19458. {
  19459. int result = FALSE;
  19460. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  19461. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  19462. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  19463. struct yuarel url;
  19464. char urlStr[512];
  19465. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  19466. {
  19467. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  19468. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19469. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19470. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  19471. if(yuarel_parse(&url, urlStr) != -1)
  19472. {
  19473. sprintf(OcppProtocol, "%s", url.scheme);
  19474. sprintf(OcppHost, "%s", url.host);
  19475. if(url.path == NULL)
  19476. OcppTempPath[0] = '\0';
  19477. else
  19478. {
  19479. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  19480. {
  19481. sprintf(OcppTempPath, "%s/", url.path);
  19482. }
  19483. else
  19484. {
  19485. sprintf(OcppTempPath, "%s", url.path);
  19486. }
  19487. }
  19488. if(url.port == 0)
  19489. {
  19490. if(strcmp(OcppProtocol, "wss") == 0)
  19491. OcppPort = 443;
  19492. else
  19493. OcppPort = 80;
  19494. }
  19495. else
  19496. OcppPort = url.port;
  19497. result = TRUE;
  19498. }
  19499. }
  19500. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  19501. {
  19502. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  19503. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19504. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19505. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  19506. if(yuarel_parse(&url, urlStr) != -1)
  19507. {
  19508. sprintf(OcppProtocol, "%s", url.scheme);
  19509. sprintf(OcppHost, "%s", url.host);
  19510. if(url.path == NULL)
  19511. OcppTempPath[0] = '\0';
  19512. else
  19513. sprintf(OcppTempPath, "%s", url.path);
  19514. if(url.port == 0)
  19515. {
  19516. if(strcmp(OcppProtocol, "wss") == 0)
  19517. OcppPort = 443;
  19518. else
  19519. OcppPort = 80;
  19520. }
  19521. else
  19522. OcppPort = url.port;
  19523. result = TRUE;
  19524. }
  19525. }
  19526. else
  19527. {
  19528. strcpy(OcppHost,"");
  19529. }
  19530. return result;
  19531. }
  19532. int GetOcppPath()
  19533. {
  19534. int result = FALSE;
  19535. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  19536. {
  19537. if(OcppTempPath == NULL)
  19538. {
  19539. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19540. }
  19541. else
  19542. {
  19543. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19544. }
  19545. result = TRUE;
  19546. goto End;
  19547. }
  19548. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  19549. {
  19550. if(OcppTempPath == NULL)
  19551. {
  19552. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  19553. }
  19554. else
  19555. {
  19556. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  19557. }
  19558. result = TRUE;
  19559. goto End;
  19560. }
  19561. else
  19562. {
  19563. strcpy(OcppPath,"");
  19564. }
  19565. End:
  19566. return result;
  19567. }
  19568. int GetOcppPort()
  19569. {
  19570. return OcppPort;
  19571. }
  19572. int GetOcppConnStatus(void)
  19573. {
  19574. return ShmOCPP16Data->OcppConnStatus;
  19575. }
  19576. void SetOcppConnStatus(uint8_t status)
  19577. {
  19578. ShmOCPP16Data->OcppConnStatus = status;
  19579. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  19580. }
  19581. int GetHeartBeatWithNOResponse(void)
  19582. {
  19583. return HeartBeatWithNOResponse;
  19584. }
  19585. void SetHeartBeatWithNOResponse(void)
  19586. {
  19587. HeartBeatWithNOResponse = 0;
  19588. }
  19589. void GetStartTransactionIdTag(int gun_index)
  19590. {
  19591. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  19592. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  19593. }
  19594. int GetStartTransactionId(int gun_index)
  19595. {
  19596. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19597. }
  19598. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  19599. {
  19600. char ch;
  19601. FILE *fptr1;
  19602. int temptransactionId;
  19603. char str[100]={0};
  19604. temptransactionId = 0;
  19605. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  19606. {
  19607. DEBUG_INFO("IdTag is empty.\n");
  19608. return temptransactionId;
  19609. }
  19610. /*------ Read the file ----------------*/
  19611. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  19612. if (!fptr1)
  19613. {
  19614. DEBUG_INFO("QueueTransactionId file open error.\n");
  19615. //printf(" File not found or unable to open the input file!!\n");
  19616. return temptransactionId;
  19617. }
  19618. ch=fgetc(fptr1);
  19619. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  19620. rewind(fptr1);
  19621. if(ch!=EOF)
  19622. {
  19623. // printf("%c",ch);
  19624. while (fgets(str, 100, fptr1) != NULL)
  19625. {
  19626. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19627. if(str[0]=='\0')
  19628. {
  19629. break;
  19630. }
  19631. char *revbuf[8] = {0}; // Variable store string split
  19632. int num = 0;// Quantity after string split
  19633. DEBUG_INFO("Transaction queue data= %s\n", str);
  19634. splitstring(str,",",revbuf,&num); // String split
  19635. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  19636. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  19637. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  19638. DEBUG_INFO("------------------------------\n");
  19639. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  19640. {
  19641. if(isStopTransaction)
  19642. {
  19643. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  19644. {
  19645. temptransactionId = atoi(revbuf[2]);
  19646. //break;
  19647. }
  19648. }
  19649. else
  19650. {
  19651. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  19652. {
  19653. temptransactionId = atoi(revbuf[2]);
  19654. //break;
  19655. }
  19656. }
  19657. }
  19658. }
  19659. }
  19660. else
  19661. DEBUG_INFO("EOF\n");
  19662. fclose(fptr1);
  19663. /*------- End of reading ---------------*/
  19664. return temptransactionId;
  19665. }
  19666. void SetTransactionIdZero(int transactionId)
  19667. {
  19668. char ch;
  19669. FILE *fptr1, *fptr2;
  19670. int temptransactionId = 0;
  19671. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  19672. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  19673. if (!fptr1)
  19674. {
  19675. //printf(" File not found or unable to open the input file!!\n");
  19676. return ;
  19677. }
  19678. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  19679. if (!fptr2)
  19680. {
  19681. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  19682. fclose(fptr1);
  19683. return ;
  19684. }
  19685. ch=fgetc(fptr1);
  19686. rewind(fptr1);
  19687. if(ch!=EOF)
  19688. {
  19689. // copy all contents to the temporary file except the specific line
  19690. while (fgets(str, 100, fptr1) != NULL)
  19691. {
  19692. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19693. if(str[0]=='\0')
  19694. {
  19695. break;
  19696. }
  19697. char *revbuf[8] = {0};
  19698. int num = 0;
  19699. strcpy(strtemp, str);
  19700. splitstring(str,",",revbuf,&num);
  19701. if(revbuf[2][0] != '\0')
  19702. {
  19703. temptransactionId = atoi(revbuf[2]);
  19704. if(transactionId != temptransactionId)
  19705. {
  19706. fprintf(fptr2, "%s\n", strtemp);
  19707. }
  19708. }
  19709. }
  19710. }
  19711. fclose(fptr1);
  19712. fclose(fptr2);
  19713. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  19714. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  19715. /*------ Read the file ----------------*/
  19716. }
  19717. int InternetDisconnect(void)
  19718. {
  19719. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  19720. }
  19721. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  19722. void storeTempStopTransaction(int gun_index)
  19723. {
  19724. char guid[37]={0};
  19725. int tempIndex = 0;
  19726. char TempStopTransaction[256];
  19727. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19728. DEBUG_INFO("storeTempStopTransaction...\n");
  19729. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  19730. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  19731. //=========================== Stop Transaction Time ===============================================
  19732. getNowDatetime(ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  19733. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19734. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19735. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19736. {
  19737. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19738. {
  19739. tempIndex = ((gun_index==2) ? 1: 0);
  19740. }
  19741. else
  19742. {
  19743. tempIndex = gun_index;
  19744. }
  19745. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19746. {
  19747. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19748. {
  19749. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  19750. }
  19751. }// END OF CHAdeMO_QUANTITY
  19752. }
  19753. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19754. {
  19755. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19756. {
  19757. tempIndex = ((gun_index==2) ? 1: 0);
  19758. }
  19759. else
  19760. {
  19761. tempIndex = gun_index;
  19762. }
  19763. for (int index = 0; index < CCS_QUANTITY; index++)
  19764. {
  19765. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19766. {
  19767. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  19768. }
  19769. }// END OF CCS_QUANTITY
  19770. }
  19771. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19772. {
  19773. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19774. {
  19775. tempIndex = ((gun_index==2) ? 1: 0);
  19776. }
  19777. else
  19778. {
  19779. tempIndex = gun_index;
  19780. }
  19781. for (int index = 0; index < GB_QUANTITY; index++)
  19782. {
  19783. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19784. {
  19785. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  19786. }
  19787. }// END OF GB_QUANTITY
  19788. }
  19789. else if(gunType[gun_index] == GUN_TYPE_DO)
  19790. {
  19791. tempIndex = gun_index;
  19792. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19793. {
  19794. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19795. {
  19796. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  19797. }
  19798. }
  19799. }
  19800. else
  19801. {
  19802. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19803. {
  19804. tempIndex = 2;
  19805. }
  19806. else
  19807. {
  19808. tempIndex = gun_index;
  19809. }
  19810. for (int index = 0; index < AC_QUANTITY; index++)
  19811. {
  19812. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19813. {
  19814. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  19815. }
  19816. }// END OF AC_QUANTITY
  19817. }
  19818. //======================================== Message create ==============================================
  19819. json_object *StopTransaction = json_object_new_object();
  19820. json_object *transactionDatas = json_object_new_array();
  19821. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  19822. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  19823. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  19824. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  19825. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  19826. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  19827. meterValueBufferQuery(gun_index, transactionDatas);
  19828. if(json_object_array_length(transactionDatas) > 0) json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  19829. random_uuid(guid);
  19830. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  19831. ,MESSAGE_TYPE_CALL
  19832. ,guid
  19833. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  19834. json_object_put(StopTransaction);
  19835. // Check File "TempStopTransaction" Exist
  19836. if((access(TempStopTransaction,F_OK))!=-1)
  19837. {
  19838. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  19839. fclose(fopen(TempStopTransaction, "w"));
  19840. }
  19841. else
  19842. {
  19843. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  19844. FILE *log = fopen(TempStopTransaction, "w+");
  19845. if(log == NULL)
  19846. {
  19847. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  19848. return ;
  19849. }
  19850. else
  19851. {
  19852. fclose(log);
  19853. }
  19854. }
  19855. //Add TempStopTransaction | Update TempStopTransaction
  19856. // open file for writing
  19857. FILE *outfile;
  19858. outfile = fopen (TempStopTransaction, "a");
  19859. //DEBUG_INFO("data = %s\n", queuedata);
  19860. fputs(queuedata, outfile);
  19861. fputs("\n", outfile);
  19862. fclose (outfile);
  19863. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19864. OCPP_updatePeriodEnergy(gun_index);
  19865. }
  19866. void checkTempStopTransaction(int gun_index)
  19867. {
  19868. FILE *fptr1;
  19869. char ch;
  19870. char str[QUEUE_MESSAGE_LENGTH]={0};
  19871. char guid[37]={0};
  19872. char tempdata[65]={0};
  19873. char connectorStr[2]={0};
  19874. char TempStopTransaction[256];
  19875. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19876. fptr1 = fopen(TempStopTransaction, "r");
  19877. //TempStopTransaction格式: 槍號,StopTransaction封包
  19878. if (!fptr1)
  19879. {
  19880. //printf(" File not found or unable to open the input file!!\n");
  19881. return ;
  19882. }
  19883. ch=fgetc(fptr1);
  19884. //printf(" Now the content of the file %s is : \n",fname);
  19885. rewind(fptr1);
  19886. if(ch!=EOF)
  19887. {
  19888. // copy all contents to the temporary file except the specific line
  19889. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  19890. {
  19891. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19892. if(str[0]=='\0')
  19893. {
  19894. break;
  19895. }
  19896. //TempStopTransaction格式: 槍號,StopTransaction封包
  19897. strncpy(connectorStr, str, 1);
  19898. if(atoi(connectorStr) != (gun_index+1))
  19899. {
  19900. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  19901. fclose(fptr1);
  19902. return ;
  19903. }
  19904. //random_uuid(guid);
  19905. strncpy(guid, str+6, 36); //copy guid
  19906. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  19907. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  19908. {
  19909. //DEBUG_INFO("StopTransaction mapitem pass\n");
  19910. }
  19911. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  19912. OCPP_insert_transaction_msg(NO, str);
  19913. memset(str,0,ARRAY_SIZE(str));
  19914. }
  19915. }
  19916. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  19917. fclose(fptr1);
  19918. remove(TempStopTransaction); // remove the original file
  19919. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19920. }
  19921. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  19922. {
  19923. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  19924. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  19925. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  19926. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  19927. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  19928. }
  19929. void FillTransactionId(int ConnectorId, int TransactionId)
  19930. {
  19931. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  19932. ShmOCPP16Data->StartTransaction[ConnectorId-1].ResponseTransactionId = TransactionId;
  19933. }
  19934. int GetWebSocketPingInterval(void)
  19935. {
  19936. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  19937. }
  19938. int GetServerSign(void)
  19939. {
  19940. return server_sign;
  19941. }
  19942. uint8_t GetOcppSecurityProfile()
  19943. {
  19944. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  19945. }
  19946. void MergeCertificates()
  19947. {
  19948. char cmdBuf[2048]={0};
  19949. if(access(ROOTCA_CS,F_OK) != -1)
  19950. {
  19951. sprintf(cmdBuf, "cat /root/cacert.pem %s > /root/certCA.pem", ROOTCA_CS);
  19952. }
  19953. else
  19954. {
  19955. sprintf(cmdBuf, "cat /root/cacert.pem > /root/certCA.pem");
  19956. }
  19957. system(cmdBuf);
  19958. }
  19959. void GetOcppChargerBoxId(uint8_t *data)
  19960. {
  19961. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19962. }
  19963. void GetOcppSecurityPassword(uint8_t *data)
  19964. {
  19965. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  19966. }
  19967. void SetOcppVersion(uint8_t *version)
  19968. {
  19969. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  19970. DEBUG_INFO("ocpp version: %s\n", version);
  19971. if(strstr((char*)version, "ocpp1.6") != NULL)
  19972. {
  19973. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  19974. }
  19975. else if(strstr((char*)version, "ocpp2.0") != NULL)
  19976. {
  19977. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  19978. system("pkill OcppBackend");
  19979. }
  19980. }
  19981. void SetServerSign(int value)
  19982. {
  19983. server_sign = value;
  19984. }
  19985. int GetBootNotificationInterval(void)
  19986. {
  19987. return BootNotificationInterval;
  19988. }
  19989. int GetInternetConn(void)
  19990. {
  19991. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  19992. }
  19993. int GetBackendConnectionTimeout(void)
  19994. {
  19995. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  19996. }
  19997. int isConnectorInitMode(int gun_index)
  19998. {
  19999. int tempIndex = 0;
  20000. int result = TRUE;
  20001. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  20002. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20003. {
  20004. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20005. {
  20006. tempIndex = ((gun_index==2) ? 1: 0);
  20007. }
  20008. else
  20009. {
  20010. tempIndex = gun_index;
  20011. }
  20012. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20013. {
  20014. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  20015. {
  20016. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20017. } //end of the same index
  20018. }//end of for CHAdeMO_QUANTITY
  20019. }
  20020. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20021. {
  20022. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20023. {
  20024. tempIndex = ((gun_index==2) ? 1: 0);
  20025. }
  20026. else
  20027. {
  20028. tempIndex = gun_index;
  20029. }
  20030. for (int index = 0; index < CCS_QUANTITY; index++)
  20031. {
  20032. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20033. {
  20034. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20035. } //end of the same index
  20036. } // end of for CCS_QUANTITY
  20037. }
  20038. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20039. {
  20040. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20041. {
  20042. tempIndex = ((gun_index==2) ? 1: 0);
  20043. }
  20044. else
  20045. {
  20046. tempIndex = gun_index;
  20047. }
  20048. for (int index = 0; index < GB_QUANTITY; index++)
  20049. {
  20050. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20051. {
  20052. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20053. } //end of the same index
  20054. } // end of for GB_QUANTITY
  20055. }
  20056. else if(gunType[gun_index] == GUN_TYPE_DO)
  20057. {
  20058. tempIndex = gun_index;
  20059. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20060. {
  20061. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20062. {
  20063. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20064. } //end of the same index
  20065. }
  20066. }
  20067. else
  20068. {
  20069. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20070. {
  20071. tempIndex = 2;
  20072. }
  20073. else
  20074. {
  20075. tempIndex = gun_index;
  20076. }
  20077. for (int index = 0; index < AC_QUANTITY; index++)
  20078. {
  20079. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20080. {
  20081. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20082. }//end of the same index
  20083. }//end of for AC_QUANTITY
  20084. }
  20085. return result;
  20086. }
  20087. void refreshProcDogTimer()
  20088. {
  20089. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  20090. }
  20091. void InitialSystemValue(void)
  20092. {
  20093. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  20094. locallistVersion=0;
  20095. BootNotificationInterval = 0;
  20096. authorizeRetryTimes = 0;
  20097. GunStatusInterval = 10;
  20098. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  20099. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  20100. //Hear Beat
  20101. HeartBeatWithNOResponse = 0;
  20102. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  20103. FirstHeartBeat = 0;
  20104. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  20105. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  20106. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  20107. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  20108. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  20109. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  20110. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  20111. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  20112. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  20113. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  20114. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  20115. //Status && ConnectorPlugIn Setting
  20116. Connector0PreviousSystemStatus = 99;
  20117. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20118. {
  20119. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  20120. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  20121. }
  20122. for (int index = 0; index < CCS_QUANTITY; index++)
  20123. {
  20124. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  20125. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  20126. }
  20127. for (int index = 0; index < GB_QUANTITY; index++)
  20128. {
  20129. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  20130. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  20131. }
  20132. for (int index = 0; index < AC_QUANTITY; index++)
  20133. {
  20134. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  20135. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  20136. }
  20137. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20138. {
  20139. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  20140. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  20141. }
  20142. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  20143. {
  20144. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  20145. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  20146. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  20147. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  20148. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  20149. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  20150. }
  20151. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  20152. refreshStartTimer(&clientTime.Heartbeat);
  20153. sleep(1);
  20154. }
  20155. void LWS_Send(char *str)
  20156. {
  20157. //=====================================================
  20158. // Check InternetConn 0: disconnected, 1: connected
  20159. //====================================================
  20160. if(GetOcppConnStatus() == 0)
  20161. {
  20162. DEBUG_INFO("offline now !!!\n");
  20163. return;
  20164. }
  20165. // Only disable isWebsocketSendable operation initiated by charger
  20166. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20167. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20168. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20169. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20170. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20171. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20172. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20173. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20174. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20175. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20176. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20177. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20178. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20179. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20180. {
  20181. isWebsocketSendable = 0;
  20182. }
  20183. pthread_mutex_lock(&lock_send);
  20184. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20185. sprintf((char *)SendBuffer, "%s", str);
  20186. SendBufLen = strlen(str);
  20187. pthread_mutex_unlock(&lock_send);
  20188. lws_callback_on_writable(wsi_client);
  20189. //lws_service(context, 0);
  20190. //sleep(1);
  20191. }
  20192. void LWS_SendNow(char *str)
  20193. {
  20194. //=====================================================
  20195. // Check InternetConn 0: disconnected, 1: connected
  20196. //====================================================
  20197. if(GetOcppConnStatus() == 0)
  20198. {
  20199. DEBUG_INFO("offline now !!!\n");
  20200. return;
  20201. }
  20202. // Only disable isWebsocketSendable operation initiated by charger
  20203. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20204. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20205. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20206. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20207. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20208. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20209. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20210. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20211. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20212. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20213. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20214. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20215. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20216. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20217. {
  20218. isWebsocketSendable = 0;
  20219. }
  20220. pthread_mutex_lock(&lock_send);
  20221. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20222. sprintf((char *)SendBuffer, "%s", str);
  20223. SendBufLen = strlen(str);
  20224. pthread_mutex_unlock(&lock_send);
  20225. lws_callback_on_writable(wsi_client);
  20226. lws_service(context, 0);
  20227. //sleep(1);
  20228. }