MessageHandler.c 997 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static ParsingRatedCur modelnameInfo = {0};
  28. static int gunTotalNumber = 0;
  29. static uint8_t gunType[4] = {0};
  30. //===============================
  31. // Local List Version
  32. //===============================
  33. static int locallistVersion=0;
  34. static char idTagAuthorization[32] = {0};
  35. //===============================
  36. // OCPP sign variable
  37. //===============================
  38. static int server_sign = FALSE;
  39. int server_pending = FALSE;
  40. static int BootNotificationInterval = 0;
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = FALSE;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  54. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  55. //========================================
  56. // OCPP status/previous related variables
  57. //========================================
  58. static int GunStatusInterval = 10;
  59. static uint8_t Connector0PreviousSystemStatus;
  60. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  61. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  62. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  63. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  64. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  65. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  66. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  67. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  68. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  69. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  70. static int TransactionMessageAttemptsValue = 0;
  71. static int TransactionMessageRetryIntervalValue = 0;
  72. static int TempMeterValueInterval = 0;
  73. static struct OCPPAuthLocalElemet
  74. {
  75. int listVersionInt;
  76. char idTagstr[21];
  77. char parentIdTag[21];
  78. char expiryDate[36];
  79. char idTagstatus[16];
  80. }idTagQuery;
  81. //============================================
  82. // OCPP MeterValue request flag
  83. //============================================
  84. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  85. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  86. //============================================
  87. // OCPP HeartBeat Response Not Receive Counts
  88. //============================================
  89. static int HeartBeatWithNOResponse = 0;
  90. //============================================
  91. // OCPP California Pricing Requirements
  92. //============================================
  93. static char dmsVersion[21] = {0};
  94. extern sqlite3 *db;
  95. int TransactionMessageAttemptsGet(void);
  96. int TransactionMessageRetryIntervalGet(void);
  97. int GetOcppConnStatus(void);
  98. void SetOcppConnStatus(uint8_t status);
  99. int setKeyValue(char *key, char *value);
  100. void OCPP_get_TableAuthlocalAllData(void);
  101. void processUnkownKey(void);
  102. struct InterLock
  103. {
  104. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  105. unsigned char isGetDiagnosticGoing:1;
  106. unsigned char isUpdateFirmwareGoing:1;
  107. }interLock;
  108. struct ClientTime
  109. {
  110. struct timespec Heartbeat;
  111. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  112. struct timespec StartTransaction;
  113. struct timespec StopTransaction;
  114. struct timespec MeterValues[CONNECTOR_QUANTITY];
  115. struct timespec RemoteStartWait;
  116. struct timespec TcciQueryDeduct;
  117. struct timespec TcciQueryOccupancyDeduct;
  118. struct timespec CharingProfileRefresh[CONNECTOR_QUANTITY];
  119. }clientTime;
  120. typedef union
  121. {
  122. //Operations Initiated by Central System
  123. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  124. struct
  125. {
  126. //CsMsgValue[0]
  127. unsigned char StatusNotificationReq:1; //bit 0,
  128. unsigned char StatusNotificationConf:1; //bit 1,
  129. unsigned char TriggerMeterValue:1; //bit 2,
  130. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  131. unsigned char isOnCharging:1; //bit 4,
  132. unsigned char :3; //bit5~7
  133. }bits[CONNECTOR_QUANTITY];
  134. }CpinitiateMsg;
  135. CpinitiateMsg cpinitateMsg;
  136. //GetConfiguration Array
  137. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  138. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  139. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  140. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  141. static char *ChargePointErrorCodeStr[] = {
  142. MACROSTR(ConnectorLockFailure),
  143. MACROSTR(EVCommunicationError),
  144. MACROSTR(GroundFailure),
  145. MACROSTR(HighTemperature),
  146. MACROSTR(InternalError),
  147. MACROSTR(LocalListConflict),
  148. MACROSTR(NoError),
  149. MACROSTR(OtherError),
  150. MACROSTR(OverCurrentFailure),
  151. MACROSTR(OverVoltage),
  152. MACROSTR(PowerMeterFailure),
  153. MACROSTR(PowerSwitchFailure),
  154. MACROSTR(ReaderFailure),
  155. MACROSTR(ResetFailure),
  156. MACROSTR(UnderVoltage),
  157. MACROSTR(WeakSignal)
  158. };
  159. static char * ChargePointStatusStr[] = {
  160. MACROSTR(Available),
  161. MACROSTR(Preparing),
  162. MACROSTR(Charging),
  163. MACROSTR(SuspendedEVSE),
  164. MACROSTR(SuspendedEV),
  165. MACROSTR(Finishing),
  166. MACROSTR(Reserved),
  167. MACROSTR(Unavailable),
  168. MACROSTR(Faulted)
  169. };
  170. static char *RegistrationStatusStr[] = {
  171. MACROSTR(Accepted),
  172. MACROSTR(Pending),
  173. MACROSTR(Rejected)
  174. };
  175. static char *AvailabilityTypeStr[] = {
  176. MACROSTR(Inoperative),
  177. MACROSTR(Operative)
  178. };
  179. static char *AvailabilityStatusStr[] = {
  180. MACROSTR(Accepted),
  181. MACROSTR(Rejected),
  182. MACROSTR(Scheduled)
  183. };
  184. static char *ConfigurationStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected),
  187. MACROSTR(RebootRequired),
  188. MACROSTR(NotSupported)
  189. };
  190. static char *ClearCacheStatusStr[] = {
  191. MACROSTR(Accepted),
  192. MACROSTR(Rejected)
  193. };
  194. static char *ChargingProfilePurposeTypeStr[] = {
  195. MACROSTR(ChargePointMaxProfile),
  196. MACROSTR(TxDefaultProfile),
  197. MACROSTR(TxProfile)
  198. };
  199. static char *ChargingProfileStatusStr[] = {
  200. MACROSTR(Accepted),
  201. MACROSTR(Rejected),
  202. MACROSTR(NotSupported)
  203. };
  204. static char *ClearChargingProfileStatusStr[] = {
  205. MACROSTR(Accepted),
  206. MACROSTR(Unknown)
  207. };
  208. static char *GetCompositeScheduleStatusStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Rejected)
  211. };
  212. static char *UpdateTypeStr[] = {
  213. MACROSTR(Differential),
  214. MACROSTR(Full)
  215. };
  216. static char *UpdateStatusStr[] = {
  217. MACROSTR(Accepted),
  218. MACROSTR(Failed),
  219. MACROSTR(NotSupported),
  220. MACROSTR(VersionMismatch)
  221. };
  222. static char *RemoteStartStopStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Rejected)
  225. };
  226. static char *ReservationStatusStr[] = {
  227. MACROSTR(Accepted),
  228. MACROSTR(Faulted),
  229. MACROSTR(Occupied),
  230. MACROSTR(Rejected),
  231. MACROSTR(Unavailable)
  232. };
  233. static char *ResetTypeStr[] = {
  234. MACROSTR(Hard),
  235. MACROSTR(Soft)
  236. };
  237. static char *ResetStatusStr[] = {
  238. MACROSTR(Accepted),
  239. MACROSTR(Rejected)
  240. };
  241. static char * DiagnosticsStatusStr[] = {
  242. MACROSTR(Idle),
  243. MACROSTR(Uploaded),
  244. MACROSTR(UploadFailed),
  245. MACROSTR(Uploading)
  246. };
  247. static char * FirmwareStatusStr[] = {
  248. MACROSTR(Downloaded),
  249. MACROSTR(DownloadFailed),
  250. MACROSTR(Downloading),
  251. MACROSTR(Idle),
  252. MACROSTR(InstallationFailed),
  253. MACROSTR(Installing),
  254. MACROSTR(Installed)
  255. };
  256. static char * MessageTriggerStr[] = {
  257. MACROSTR(BootNotification),
  258. MACROSTR(DiagnosticsStatusNotification),
  259. MACROSTR(FirmwareStatusNotification),
  260. MACROSTR(Heartbeat),
  261. MACROSTR(MeterValues),
  262. MACROSTR(StatusNotification)
  263. };
  264. static char * TriggerMessageStatusStr[] = {
  265. MACROSTR(Accepted),
  266. MACROSTR(Rejected),
  267. MACROSTR(NotImplemented)
  268. };
  269. static char * UnlockStatusStr[] = {
  270. MACROSTR(Unlocked),
  271. MACROSTR(UnlockFailed),
  272. MACROSTR(NotSupported)
  273. };
  274. #if 0
  275. static char * StopTransactionReasonStr[] = {
  276. MACROSTR(EmergencyStop),
  277. MACROSTR(EVDisconnected),
  278. MACROSTR(HardReset),
  279. MACROSTR(Local),
  280. MACROSTR(Other),
  281. MACROSTR(PowerLoss),
  282. MACROSTR(Reboot),
  283. MACROSTR(Remote),
  284. MACROSTR(SoftReset),
  285. MACROSTR(UnlockCommand),
  286. MACROSTR(DeAuthorized)
  287. };
  288. #endif
  289. static char * CancelReservationStatusStr[] = {
  290. MACROSTR(Accepted),
  291. MACROSTR(Rejected)
  292. };
  293. static char * ReadingContextStr[] = {
  294. MACROSTR(Interruption.Begin),
  295. MACROSTR(Interruption.End),
  296. MACROSTR(Other),
  297. MACROSTR(Sample.Clock),
  298. MACROSTR(Sample.Periodic),
  299. MACROSTR(Transaction.Begin),
  300. MACROSTR(Transaction.End),
  301. MACROSTR(Trigger)
  302. };
  303. static char * ValueFormatStr[] = {
  304. MACROSTR(Raw),
  305. MACROSTR(SignedData)
  306. };
  307. static char * MeasurandStr[] = {
  308. MACROSTR(Current.Export),
  309. MACROSTR(Current.Import),
  310. MACROSTR(Current.Offered),
  311. MACROSTR(Energy.Active.Export.Register),
  312. MACROSTR(Energy.Active.Import.Register),
  313. MACROSTR(Energy.Reactive.Export.Register),
  314. MACROSTR(Energy.Reactive.Import.Register),
  315. MACROSTR(Energy.Active.Export.Interval),
  316. MACROSTR(Energy.Active.Import.Interval),
  317. MACROSTR(Energy.Reactive.Export.Interval),
  318. MACROSTR(Energy.Reactive.Import.Interval),
  319. MACROSTR(Frequency),
  320. MACROSTR(Power.Active.Export),
  321. MACROSTR(Power.Active.Import),
  322. MACROSTR(Power.Factor),
  323. MACROSTR(Power.Offered),
  324. MACROSTR(Power.Reactive.ExportMACROSTR),
  325. MACROSTR(Power.Reactive.Import),
  326. MACROSTR(RPM),
  327. MACROSTR(SoC),
  328. MACROSTR(Temperature),
  329. MACROSTR(Voltage)
  330. };
  331. static char * LocationStr[] = {
  332. MACROSTR(Body),
  333. MACROSTR(Cable),
  334. MACROSTR(EV),
  335. MACROSTR(Inlet),
  336. MACROSTR(Outlet)
  337. };
  338. static char * PhaseStr[] = {
  339. MACROSTR(L1),
  340. MACROSTR(L2),
  341. MACROSTR(L3),
  342. MACROSTR(N),
  343. MACROSTR(L1-N),
  344. MACROSTR(L2-N),
  345. MACROSTR(L3-N),
  346. MACROSTR(L1-L2),
  347. MACROSTR(L2-L3),
  348. MACROSTR(L3-L1)
  349. };
  350. static char * UnitOfMeasureStr[] = {
  351. MACROSTR(Wh),
  352. MACROSTR(kWh),
  353. MACROSTR(varh),
  354. MACROSTR(kvarh),
  355. MACROSTR(W),
  356. MACROSTR(kW),
  357. MACROSTR(VA),
  358. MACROSTR(kVA),
  359. MACROSTR(var),
  360. MACROSTR(kvar),
  361. MACROSTR(A),
  362. MACROSTR(V),
  363. MACROSTR(Celsius),
  364. MACROSTR(Fahrenheit),
  365. MACROSTR(K),
  366. MACROSTR(Percent)
  367. };
  368. //=========================================
  369. // Meter buffer process
  370. //=========================================
  371. int meterValueBufferDataQuantity(uint8_t gun_index, ReadingContext dataType)
  372. {
  373. uint32_t result = 0;
  374. char sqlCmd[8192];
  375. char zErrMsg[200];
  376. int rows, cols;
  377. char **resultData;
  378. sprintf(sqlCmd, "select count(idx) as dataQuantity from meterValuesBuffer where gun_index='%d' and ReadingContext='%d' order by ReadingContext, idx", gun_index, (dataType==ReadingContext_Sample_Periodic?0:1));
  379. if( sqlite3_get_table(db, sqlCmd, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  380. {
  381. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  382. }
  383. else
  384. {
  385. if(rows >= 1)
  386. {
  387. result = atoi(resultData[1]);
  388. }
  389. }
  390. return result;
  391. }
  392. int meterValueBufferClear(uint8_t gun_index)
  393. {
  394. int result = PASS;
  395. char sqlCmd[512];
  396. char *errMsg = 0;
  397. sprintf(sqlCmd, "delete from meterValuesBuffer where gun_index=%d", gun_index);
  398. if (sqlite3_exec(db, sqlCmd, 0, 0, &errMsg) != SQLITE_OK)
  399. {
  400. DEBUG_INFO("SQL error: %s\n",errMsg);
  401. result = FAIL;
  402. }
  403. return result;
  404. }
  405. int meterValueBufferInsert(uint8_t gun_index, ReadingContext dataType, uint32_t transactionId, char *meterValue)
  406. {
  407. int result = PASS;
  408. char sqlCmd[8192];
  409. char *errMsg = 0;
  410. sprintf(sqlCmd, "insert into meterValuesBuffer(occurDatetime, gun_index, transactionId, ReadingContext, meterValue) values(CURRENT_TIMESTAMP, '%d', '%d','%d','%s')", gun_index
  411. , transactionId
  412. , (dataType==ReadingContext_Sample_Periodic?0:1)
  413. , meterValue);
  414. if (sqlite3_exec(db, sqlCmd, 0, 0, &errMsg) != SQLITE_OK)
  415. {
  416. result = FAIL;
  417. DEBUG_WARN( "Insert meter value record error message: %s\n", errMsg);
  418. }
  419. return result;
  420. }
  421. int meterValueBufferQuery(uint8_t gun_index, json_object *MeterValues)
  422. {
  423. int result = PASS;
  424. char sqlCmd[8192];
  425. char zErrMsg[200];
  426. int rows, cols;
  427. char **resultData;
  428. sprintf(sqlCmd, "select * from meterValuesBuffer where gun_index='%d' order by ReadingContext, idx", gun_index);
  429. if( sqlite3_get_table(db, sqlCmd, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  430. {
  431. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  432. result = FAIL;
  433. }
  434. else
  435. {
  436. for(uint32_t idxRow=1;idxRow<=rows;idxRow++)
  437. {
  438. json_object *MeterValue = json_tokener_parse(resultData[(idxRow*cols)+5]);
  439. json_object_array_add(MeterValues, MeterValue);
  440. }
  441. }
  442. return result;
  443. }
  444. //=========================================
  445. // Certificate related routine
  446. //=========================================
  447. int certVerify(char *privateKey, char *cert)
  448. {
  449. int result = PASS;
  450. SSL_CTX *ctx = SSL_CTX_new(TLS_method());
  451. // Load certificate file
  452. if(SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM) <= 0)
  453. {
  454. DEBUG_ERROR("Load certificate error!\n");
  455. result = FAIL;
  456. }
  457. // Load private key file
  458. if(SSL_CTX_use_PrivateKey_file(ctx, privateKey, SSL_FILETYPE_PEM) <= 0)
  459. {
  460. DEBUG_ERROR("Load private key error!\n");
  461. result = FAIL;
  462. }
  463. if(!SSL_CTX_check_private_key(ctx))
  464. {
  465. result = FAIL;
  466. }
  467. SSL_CTX_free(ctx);
  468. return result;
  469. }
  470. //=========================================
  471. // TTIA routine
  472. //=========================================
  473. int sendTTIAInfo(uint8_t gun_index)
  474. {
  475. static int sn = 0;
  476. int result = FAIL;
  477. struct hostent *server;
  478. int udp_socket_fd;
  479. struct sockaddr_in dest_addr = {0};
  480. uint8_t tx_buf[80] = {0};
  481. uint8_t logBuf[256]= {0};
  482. uint8_t tx_len, tempIndex, socStart, socEnd;
  483. uint16_t PresentChargedEnergy;
  484. struct tm tmStart, tmEnd;
  485. DEBUG_INFO("sendTTIAInfo...\n");
  486. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  487. {
  488. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  489. {
  490. tempIndex = ((gun_index==2) ? 1: 0);
  491. }
  492. else
  493. {
  494. tempIndex = gun_index;
  495. }
  496. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  497. {
  498. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  499. {
  500. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  501. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  502. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  503. }
  504. }
  505. }
  506. else if(gunType[gun_index] == GUN_TYPE_CCS)
  507. {
  508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  509. {
  510. tempIndex = ((gun_index==2) ? 1: 0);
  511. }
  512. else
  513. {
  514. tempIndex = gun_index;
  515. }
  516. for (int index = 0; index < CCS_QUANTITY; index++)
  517. {
  518. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  519. {
  520. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  521. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  522. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  523. }
  524. }
  525. }
  526. else if(gunType[gun_index] == GUN_TYPE_GBT)
  527. {
  528. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  529. {
  530. tempIndex = ((gun_index==2) ? 1: 0);
  531. }
  532. else
  533. {
  534. tempIndex = gun_index;
  535. }
  536. for (int index = 0; index < GB_QUANTITY; index++)
  537. {
  538. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  539. {
  540. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  541. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  542. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  543. }
  544. }
  545. }
  546. else if(gunType[gun_index] == GUN_TYPE_DO)
  547. {
  548. tempIndex = gun_index;
  549. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  550. {
  551. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  552. {
  553. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  554. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  555. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  556. }
  557. }
  558. }
  559. else
  560. {
  561. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  562. {
  563. tempIndex = 2;
  564. }
  565. else
  566. {
  567. tempIndex = gun_index;
  568. }
  569. for (int index = 0; index < AC_QUANTITY; index++)
  570. {
  571. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  572. {
  573. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  574. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  575. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  576. }
  577. }// END
  578. }
  579. // Message assembly
  580. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  581. tx_buf[4] = 0x02; // Protocol Version
  582. tx_buf[5] = 0xb0; // Message ID
  583. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  584. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  585. tx_buf[8] = 0x00; // CarID low byte
  586. tx_buf[9] = 0x00; // CarID high byte
  587. tx_buf[10] = 0x00; // ID Storage
  588. tx_buf[11] = 0x00; // Driver lowest byte
  589. tx_buf[12] = 0x00; // Driver 2nd byte
  590. tx_buf[13] = 0x00; // Driver 3rd byte
  591. tx_buf[14] = 0x00; // Driver highest byte
  592. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  593. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  594. tx_buf[17] = 0x00; // Reserve
  595. tx_buf[18] = 60 & 0xff; // Payload length low byte
  596. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  597. // EVSE provider
  598. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  599. // EVSE provider
  600. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  601. // EVSE id
  602. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  603. // Connector id
  604. tx_buf[37] = gun_index;
  605. // EVSE station
  606. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  607. // Vehicle SN
  608. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  609. // Mileage
  610. tx_buf[61] = 0x00; // lowest byte
  611. tx_buf[62] = 0x00; // 2nd byte
  612. tx_buf[63] = 0x00; // highest byte
  613. // Start date time 6 bytes
  614. if((sscanf((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  615. {
  616. struct tm *tmTarget;
  617. struct timeb tbTarget;
  618. tmStart.tm_year -= 1900;
  619. tmStart.tm_mon -= 1;
  620. tmStart.tm_gmtoff = 0;
  621. tbTarget.time = mktime(&tmStart);
  622. tbTarget.timezone = 0;
  623. tbTarget.time += (8*3600);
  624. tmTarget = gmtime(&tbTarget.time);
  625. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  626. tx_buf[65] = (tmTarget->tm_mon+1);
  627. tx_buf[66] = tmTarget->tm_mday;
  628. tx_buf[67] = tmTarget->tm_hour;
  629. tx_buf[68] = tmTarget->tm_min;
  630. tx_buf[69] = tmTarget->tm_sec;
  631. }
  632. // Stop date time 6 bytes
  633. if((sscanf((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmEnd.tm_year, &tmEnd.tm_mon, &tmEnd.tm_mday, &tmEnd.tm_hour, &tmEnd.tm_min, &tmEnd.tm_sec) == 6))
  634. {
  635. struct tm *tmTarget;
  636. struct timeb tbTarget;
  637. tmEnd.tm_year -= 1900;
  638. tmEnd.tm_mon -= 1;
  639. tmEnd.tm_gmtoff = 0;
  640. tbTarget.time = mktime(&tmEnd);
  641. tbTarget.timezone = 0;
  642. tbTarget.time += (8*3600);
  643. tmTarget = gmtime(&tbTarget.time);
  644. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  645. tx_buf[71] = (tmTarget->tm_mon+1);
  646. tx_buf[72] = tmTarget->tm_mday;
  647. tx_buf[73] = tmTarget->tm_hour;
  648. tx_buf[74] = tmTarget->tm_min;
  649. tx_buf[75] = tmTarget->tm_sec;
  650. }
  651. // Session energy 2 bytes
  652. tx_buf[76] = PresentChargedEnergy & 0xff;
  653. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  654. // Start SOC 1 byte
  655. tx_buf[78] = socStart;
  656. // Stop SOC 1 byte
  657. tx_buf[79] = socEnd;
  658. // Open socket
  659. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  660. if(udp_socket_fd == -1)
  661. {
  662. DEBUG_ERROR("UDP socket create failed!\n");
  663. }
  664. else
  665. {
  666. // Get server DNS entry
  667. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  668. if (server == NULL)
  669. {
  670. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  671. }
  672. else
  673. {
  674. // Build the server's Internet address
  675. bzero((char *) &dest_addr, sizeof(dest_addr));
  676. dest_addr.sin_family = AF_INET;
  677. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  678. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  679. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  680. {
  681. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  682. {
  683. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  684. }
  685. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  686. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  687. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  688. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  689. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  690. DEBUG_TTIA_INFO("---------- Header ----------\n");
  691. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  692. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  693. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  694. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  695. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  696. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  697. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  698. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  699. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  700. DEBUG_TTIA_INFO("Len: 0x3C\n");
  701. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  702. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  703. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  704. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  705. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  706. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  707. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  708. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  709. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  710. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  711. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  712. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  713. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  714. DEBUG_TTIA_INFO("=========================================\n");
  715. sn++;
  716. result = PASS;
  717. }
  718. else
  719. {
  720. DEBUG_ERROR("UDP sent out fail.\n");
  721. }
  722. }
  723. }
  724. return result;
  725. }
  726. //=========================================
  727. // Save configuration
  728. //=========================================
  729. int runShellCmd(const char*cmd)
  730. {
  731. int result = FAIL;
  732. char buf[256];
  733. FILE *fp;
  734. fp = popen(cmd, "r");
  735. if(fp != NULL)
  736. {
  737. while(fgets(buf, sizeof(buf), fp) != NULL)
  738. {
  739. DEBUG_INFO("%s\n", buf);
  740. }
  741. result = PASS;
  742. }
  743. pclose(fp);
  744. return result;
  745. }
  746. int StoreUsrConfigData(struct SysConfigData *UsrData)
  747. {
  748. int result = PASS;
  749. int fd,wrd;
  750. unsigned int i,Chk;
  751. unsigned char *ptr, *BufTmp;
  752. int MtdBlockSize = 0x300000;
  753. Chk=0;
  754. ptr=(unsigned char *)UsrData;
  755. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  756. {
  757. memset(BufTmp,0,MtdBlockSize);
  758. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  759. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  760. Chk+=*(BufTmp+i);
  761. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  762. // Output configuration to file.
  763. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  764. if (fd < 0)
  765. {
  766. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  767. free(BufTmp);
  768. return 0;
  769. }
  770. wrd=write(fd, BufTmp, MtdBlockSize);
  771. close(fd);
  772. if(wrd<MtdBlockSize)
  773. {
  774. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  775. free(BufTmp);
  776. return 0;
  777. }
  778. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  779. DEBUG_INFO("Erase /dev/mtd10.\n");
  780. runShellCmd("flash_erase /dev/mtd10 0 0");
  781. DEBUG_INFO("Write /dev/mtd10.\n");
  782. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  783. DEBUG_INFO("Erase /dev/mtd11.\n");
  784. runShellCmd("flash_erase /dev/mtd11 0 0");
  785. DEBUG_INFO("Write /dev/mtd11.\n");
  786. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  787. system("rm -f /mnt/EvseConfig.bin");
  788. DEBUG_INFO("EvseConfig write to flash OK\n");
  789. }
  790. else
  791. {
  792. DEBUG_ERROR("alloc BlockSize NG\r\n");
  793. result = FAIL;
  794. }
  795. if(BufTmp!=NULL)
  796. free(BufTmp);
  797. return result;
  798. }
  799. //=========================================
  800. // Sqlite3 related function
  801. //=========================================
  802. static int selectSqlCount = 0;
  803. static int callback(void *data, int argc, char **argv, char **azColName){
  804. int i;
  805. //printf("%s: ", (const char*)data);
  806. selectSqlCount = argc;
  807. for(i = 0; i<argc; i++){
  808. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  809. }
  810. //printf("\n");
  811. return 0;
  812. }
  813. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  814. //int i;
  815. //printf("%s:\n", (const char*)data);
  816. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  817. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  818. return 0;
  819. }
  820. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  821. //printf("%s:\n", (const char*)data);
  822. //idTag
  823. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  824. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  825. //parentIdTag
  826. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  827. //expir_date
  828. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  829. //status
  830. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  831. //version
  832. if(columenCount > 5)
  833. idTagQuery.listVersionInt = atoi(columnValue[5]);
  834. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  835. return 0;
  836. }
  837. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  838. {
  839. // localversion = argv[5] ? atoi(argv[5]) : 0;
  840. // printf("localversion=%d\n", localversion);
  841. return 0;
  842. }
  843. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  844. {
  845. for (int i = 0; i < n_columns; i++)
  846. {
  847. DEBUG_INFO("%s\t", col_values[i]);
  848. }
  849. DEBUG_INFO("\n");
  850. return 0;
  851. }
  852. int OCPP_cleanLocalCache()
  853. {
  854. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  855. char *errMsg = 0;
  856. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  857. if (SQLITE_OK != rc)
  858. {
  859. DEBUG_INFO("SQL error: %s\n",errMsg);
  860. return FALSE;
  861. }
  862. return TRUE;
  863. }
  864. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  865. {
  866. int isSuccess = TRUE;
  867. int ret = 0;
  868. //const char* data = "Callback function called";
  869. char sql[300];
  870. char zErrMsg[200];
  871. memset(sql, 0, 300);
  872. memset(zErrMsg, 0, 200);
  873. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  874. //* Execute SQL statement */
  875. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  876. if( ret != SQLITE_OK )
  877. {
  878. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  879. isSuccess = FALSE;
  880. }
  881. return isSuccess;
  882. }
  883. void OCPP_getIdTagFromLocalCache(char idTag[])
  884. {
  885. int rc = 0;
  886. char sql[100];
  887. char zErrMsg[100];
  888. memset(sql, 0, 100);
  889. memset(zErrMsg, 0, 100);
  890. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  891. memset(&idTagQuery, 0, sizeof(idTagQuery));
  892. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  893. /* Execute SQL statement */
  894. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  895. if( rc != SQLITE_OK )
  896. {
  897. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  898. }
  899. }
  900. void OCPP_getListVerion()
  901. {
  902. int rc = 0;
  903. // const char* data = "Callback function called";
  904. char sql[100];
  905. char zErrMsg[100];
  906. memset(sql, 0, 100);
  907. memset(zErrMsg, 0, 100);
  908. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  909. /* Execute SQL statement */
  910. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  911. if( rc != SQLITE_OK )
  912. {
  913. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  914. }
  915. }
  916. void OCPP_get_TableAuthlocalAllData(void)
  917. {
  918. int rc = 0;
  919. char sql[100];
  920. char zErrMsg[100];
  921. memset(sql, 0, 100);
  922. memset(zErrMsg, 0, 100);
  923. sprintf(sql,"select * from ocpp_auth_local ");
  924. /* Execute SQL statement */
  925. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  926. if( rc != SQLITE_OK )
  927. {
  928. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  929. }
  930. //return ver;
  931. }
  932. int OCPP_cleanLocalList()
  933. {
  934. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  935. char *errMsg = 0;
  936. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  937. if (SQLITE_OK != rc)
  938. {
  939. DEBUG_INFO("%s\n",errMsg);
  940. return FALSE;
  941. }
  942. return TRUE;
  943. }
  944. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  945. {
  946. int isSuccess = FALSE;
  947. int ret = 0;
  948. //const char* data = "Callback function called";
  949. char sql[300];
  950. char zErrMsg[200];
  951. memset(sql, 0, 300);
  952. memset(zErrMsg, 0, 200);
  953. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  954. //* Execute SQL statement */
  955. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  956. if( ret != SQLITE_OK )
  957. {
  958. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  959. return isSuccess;
  960. }
  961. memset(sql, 0, 300);
  962. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  963. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  964. if( ret != SQLITE_OK )
  965. {
  966. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  967. return isSuccess;
  968. }
  969. isSuccess = TRUE;
  970. return isSuccess;
  971. }
  972. void OCPP_getIdTagFromLocalList(char idTag[])
  973. {
  974. int rc = 0;
  975. // const char* data = "Callback function called";
  976. char sql[100];
  977. char zErrMsg[100];
  978. memset(sql, 0, 100);
  979. memset(zErrMsg, 0, 100);
  980. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  981. memset(&idTagQuery, 0, sizeof(idTagQuery));
  982. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  983. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  984. /* Execute SQL statement */
  985. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  986. if( rc != SQLITE_OK )
  987. {
  988. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  989. }
  990. //return ver;
  991. }
  992. void OCPP_deleteIdTagFromLocalList(char idTag[])
  993. {
  994. //int ver = 0;
  995. //int isSuccess = FALSE;
  996. int rc = 0;
  997. char sql[100];
  998. char zErrMsg[100];
  999. memset(sql, 0, 100);
  1000. memset(zErrMsg, 0, 100);
  1001. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  1002. //* Execute SQL statement */
  1003. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  1004. if( rc != SQLITE_OK )
  1005. {
  1006. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1007. }
  1008. }
  1009. int getCurrentYear()
  1010. {
  1011. int result = 0;
  1012. time_t CurrentTime;
  1013. struct tm *tm;
  1014. CurrentTime = time(NULL);
  1015. tm=localtime(&CurrentTime);
  1016. result = (tm->tm_year + 1900);
  1017. return result;
  1018. }
  1019. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  1020. {
  1021. int result = PASS;
  1022. char* errMsg = NULL;
  1023. char sqlStr[WEBSOCKET_BUFFER_SIZE];
  1024. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  1025. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1026. {
  1027. result = FAIL;
  1028. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  1029. }
  1030. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-100) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1031. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1032. {
  1033. result = FAIL;
  1034. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  1035. }
  1036. return result;
  1037. }
  1038. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  1039. {
  1040. int isSuccess = TRUE;
  1041. int tempIndex;
  1042. json_object *EnergyDataTransfer = json_object_new_object();
  1043. json_object *periodEnergys = json_object_new_object();
  1044. char sql[1024];
  1045. char zErrMsg[200];
  1046. memset(sql, 0, ARRAY_SIZE(sql));
  1047. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  1048. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  1049. {
  1050. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1051. {
  1052. tempIndex = ((gun_index==2) ? 1: 0);
  1053. }
  1054. else
  1055. {
  1056. tempIndex = gun_index;
  1057. }
  1058. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1059. {
  1060. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  1061. {
  1062. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1063. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1064. {
  1065. uint8_t period[3];
  1066. sprintf((char*)period, "%d", idxPeriod);
  1067. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1068. }
  1069. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1070. } //end of the same index
  1071. }//end of for CHAdeMO_QUANTITY
  1072. }
  1073. else if(gunType[gun_index] == GUN_TYPE_CCS)
  1074. {
  1075. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1076. {
  1077. tempIndex = ((gun_index==2) ? 1: 0);
  1078. }
  1079. else
  1080. {
  1081. tempIndex = gun_index;
  1082. }
  1083. for (int index = 0; index < CCS_QUANTITY; index++)
  1084. {
  1085. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1086. {
  1087. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1088. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1089. {
  1090. uint8_t period[3];
  1091. sprintf((char*)period, "%d", idxPeriod);
  1092. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1093. }
  1094. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1095. } //end of the same index
  1096. } // end of for CCS_QUANTITY
  1097. }
  1098. else if(gunType[gun_index] == GUN_TYPE_GBT)
  1099. {
  1100. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1101. {
  1102. tempIndex = ((gun_index==2) ? 1: 0);
  1103. }
  1104. else
  1105. {
  1106. tempIndex = gun_index;
  1107. }
  1108. for (int index = 0; index < GB_QUANTITY; index++)
  1109. {
  1110. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1111. {
  1112. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1113. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1114. {
  1115. uint8_t period[3];
  1116. sprintf((char*)period, "%d", idxPeriod);
  1117. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1118. }
  1119. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1120. } //end of the same index
  1121. } // end of for GB_QUANTITY
  1122. }
  1123. else if(gunType[gun_index] == GUN_TYPE_DO)
  1124. {
  1125. tempIndex = gun_index;
  1126. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1127. {
  1128. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1129. {
  1130. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1131. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1132. {
  1133. uint8_t period[3];
  1134. sprintf((char*)period, "%d", idxPeriod);
  1135. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1136. }
  1137. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1138. } //end of the same index
  1139. }
  1140. }
  1141. else
  1142. {
  1143. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1144. {
  1145. tempIndex = 2;
  1146. }
  1147. else
  1148. {
  1149. tempIndex = gun_index;
  1150. }
  1151. for (int index = 0; index < AC_QUANTITY; index++)
  1152. {
  1153. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1154. {
  1155. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1156. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1157. {
  1158. uint8_t period[3];
  1159. sprintf((char*)period, "%d", idxPeriod);
  1160. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1161. }
  1162. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1163. }//end of the same index
  1164. }//end of for AC_QUANTITY
  1165. }
  1166. sprintf(sql, "insert or replace into ocpp_period_energy (transactionId, connectorId, occurDatetime, periodEnergy) VALUES ('%d', '%d', CURRENT_TIMESTAMP, '%s');", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, (gun_index+1), json_object_to_json_string_ext(EnergyDataTransfer, JSON_C_TO_STRING_PLAIN));
  1167. json_object_put(EnergyDataTransfer);
  1168. //* Execute SQL statement */
  1169. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1170. {
  1171. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1172. isSuccess = FALSE;
  1173. }
  1174. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1175. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1176. {
  1177. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1178. isSuccess = FALSE;
  1179. }
  1180. return isSuccess;
  1181. }
  1182. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1183. {
  1184. int isSuccess = TRUE;
  1185. char sql[512];
  1186. char zErrMsg[200];
  1187. int rows, cols;
  1188. char **resultData;
  1189. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1190. /* Execute SQL statement */
  1191. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1192. {
  1193. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1194. isSuccess = FALSE;
  1195. }
  1196. else
  1197. {
  1198. if((rows > 0) && (atoi(resultData[4]) > 0))
  1199. {
  1200. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1201. }
  1202. else
  1203. {
  1204. DEBUG_WARN("There is not match transaction data.\n");
  1205. isSuccess = FALSE;
  1206. }
  1207. }
  1208. return isSuccess;
  1209. }
  1210. int OCPP_insert_deduct_info(int txId, char *creditNo, uint8_t deductResult, uint8_t isDonateInvoice, double amount, char *vemData, char *ROC, char *RRN, char *approvalNo, char *storeId)
  1211. {
  1212. int result = PASS;
  1213. char* errMsg = NULL;
  1214. char sqlStr[8192];
  1215. sprintf(sqlStr, "insert or replace into report_deduct_info(txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId, isUploaded) values('%d', '%s', '%d', '%d', '%.2f', '%s', '%s', '%s', '%s', '%s', '0');",
  1216. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1217. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1218. {
  1219. result = FAIL;
  1220. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1221. }
  1222. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1223. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1224. {
  1225. result = FAIL;
  1226. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1227. }
  1228. return result;
  1229. }
  1230. int OCPP_update_deduct_info(int txId, char *creditNo)
  1231. {
  1232. int result = PASS;
  1233. char* errMsg = NULL;
  1234. char sqlStr[8192];
  1235. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1236. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1237. {
  1238. result = FAIL;
  1239. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1240. }
  1241. return result;
  1242. }
  1243. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1244. {
  1245. json_object *dataBuf = json_object_new_object();
  1246. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1247. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1248. json_object_object_add(dataBuf, "txId", json_object_new_int(atoi(columnValue[1])));
  1249. json_object_object_add(dataBuf, "creditNo", json_object_new_string(columnValue[2]));
  1250. json_object_object_add(dataBuf, "deductResult", json_object_new_boolean(atoi(columnValue[3])));
  1251. json_object_object_add(dataBuf, "isDonateInvoice", json_object_new_boolean(atoi(columnValue[4])));
  1252. json_object_object_add(dataBuf, "amount", json_object_new_double(atof(columnValue[5])));
  1253. json_object_object_add(dataBuf, "approvalNo", json_object_new_string(columnValue[9]));
  1254. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1255. json_object_put(dataBuf);
  1256. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1257. return 0;
  1258. }
  1259. void OCPP_query_deduct_info()
  1260. {
  1261. int rc = 0;
  1262. char sql[100];
  1263. char zErrMsg[100];
  1264. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1265. /* Execute SQL statement */
  1266. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1267. if( rc != SQLITE_OK )
  1268. {
  1269. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1270. }
  1271. }
  1272. // Occupancy fee deduct queue process
  1273. int OCPP_insert_occupancyDeduct_info(char *occupancySN, char *creditNo, uint8_t deductResult, double amount, char *approvalNo)
  1274. {
  1275. int result = PASS;
  1276. char* errMsg = NULL;
  1277. char sqlStr[8192];
  1278. sprintf(sqlStr, "insert or replace into report_occupancyDeduct_info(occupancySN, creditNo, deductResult, amount, approvalNo, isUploaded) values('%s', '%s', '%d', '%.2f', '%s', '0');",
  1279. occupancySN, creditNo, deductResult, amount, approvalNo);
  1280. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1281. {
  1282. result = FAIL;
  1283. DEBUG_WARN( "Insert local report_occupancyDeduct_info error message: %s\n", errMsg);
  1284. }
  1285. sprintf(sqlStr, "delete from report_occupancyDeduct_info where (idx < (select idx from report_occupancyDeduct_info order by idx desc limit 1)-5000);");
  1286. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1287. {
  1288. result = FAIL;
  1289. DEBUG_WARN( "delete local report_occupancyDeduct_info error message: %s\n", errMsg);
  1290. }
  1291. return result;
  1292. }
  1293. int OCPP_update_occupancyDeduct_info(char *occupancySN)
  1294. {
  1295. int result = PASS;
  1296. char* errMsg = NULL;
  1297. char sqlStr[8192];
  1298. sprintf(sqlStr, "update report_occupancyDeduct_info set isUploaded='1' where occupancySN='%s';", occupancySN);
  1299. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1300. {
  1301. result = FAIL;
  1302. DEBUG_WARN( "Update local report_occupancyDeduct_info error message: %s\n", errMsg);
  1303. }
  1304. return result;
  1305. }
  1306. int queryOccupancyDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1307. {
  1308. json_object *dataBuf = json_object_new_object();
  1309. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1310. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_OccupancyDeductResult");
  1311. json_object_object_add(dataBuf, "occupancySN", json_object_new_string(columnValue[1]));
  1312. json_object_object_add(dataBuf, "creditNo", json_object_new_string(columnValue[2]));
  1313. json_object_object_add(dataBuf, "deductResult", json_object_new_boolean(atoi(columnValue[3])));
  1314. json_object_object_add(dataBuf, "amount", json_object_new_double(atof(columnValue[4])));
  1315. json_object_object_add(dataBuf, "approvalNo", json_object_new_string(columnValue[5]));
  1316. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1317. json_object_put(dataBuf);
  1318. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1319. return 0;
  1320. }
  1321. void OCPP_query_occupancyDeduct_info()
  1322. {
  1323. int rc = 0;
  1324. char sql[100];
  1325. char zErrMsg[100];
  1326. sprintf(sql,"select * from report_occupancyDeduct_info where isUploaded='0' order by idx limit 1");
  1327. /* Execute SQL statement */
  1328. rc = sqlite3_exec(db, sql, queryOccupancyDeductCallBack, 0, (char **)&zErrMsg);
  1329. if( rc != SQLITE_OK )
  1330. {
  1331. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1332. }
  1333. }
  1334. void reportReaderStatus(int gun_index)
  1335. {
  1336. struct timeval tmnow;
  1337. struct tm *tm;
  1338. char buf[28];//, usec_buf[6];
  1339. gettimeofday(&tmnow, NULL);
  1340. time_t t;
  1341. t = time(NULL);
  1342. /*UTC time and date*/
  1343. tm = gmtime(&t);
  1344. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1345. #if 0 // remove temporally
  1346. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1347. strcat(buf,".");
  1348. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1349. strcat(buf,usec_buf);
  1350. #endif
  1351. json_object *dataBuf = json_object_new_object();
  1352. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1353. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_ReaderStatus");
  1354. json_object_object_add(dataBuf, "ConnectorId", json_object_new_int((gun_index+1)));
  1355. json_object_object_add(dataBuf, "readerStatus", json_object_new_int(ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus));
  1356. json_object_object_add(dataBuf, "timestamp", json_object_new_string(buf));
  1357. json_object_object_add(dataBuf, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  1358. json_object_object_add(dataBuf, "creditNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo));
  1359. json_object_object_add(dataBuf, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  1360. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1361. json_object_put(dataBuf);
  1362. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1363. }
  1364. void occupancyFeeAct(int gun_index)
  1365. {
  1366. struct timeval tmnow;
  1367. struct tm *tm;
  1368. char buf[28];//, usec_buf[6];
  1369. gettimeofday(&tmnow, NULL);
  1370. time_t t;
  1371. t = time(NULL);
  1372. /*UTC time and date*/
  1373. tm = gmtime(&t);
  1374. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1375. #if 0 // remove temporally
  1376. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1377. strcat(buf,".");
  1378. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1379. strcat(buf,usec_buf);
  1380. #endif
  1381. json_object *dataBuf = json_object_new_object();
  1382. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1383. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_OccupancyFeeAct");
  1384. json_object_object_add(dataBuf, "ConnectorId", json_object_new_int((gun_index+1)));
  1385. json_object_object_add(dataBuf, "occupancySN", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].occupancySN));
  1386. json_object_object_add(dataBuf, "action", json_object_new_int(ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].action));
  1387. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1388. json_object_put(dataBuf);
  1389. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1390. }
  1391. //==========================================
  1392. // Check time passed since today
  1393. //==========================================
  1394. long long DiffTimebWithNow(struct timeb ST)
  1395. {
  1396. //return milli-second
  1397. struct timeb ET;
  1398. long long StartTime,StopTime;
  1399. ftime(&ET);
  1400. StartTime=(long long)ST.time;
  1401. StopTime=(long long)ET.time;
  1402. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1403. }
  1404. int getTimePassSinceToday(uint8_t gun_index)
  1405. {
  1406. int result = -1;
  1407. static time_t lastTime[4];
  1408. time_t t;
  1409. struct tm *tmStartToday;
  1410. struct timeb tbStartToday;
  1411. t=time(NULL);
  1412. if(difftime(t, lastTime[gun_index])>0)
  1413. {
  1414. tmStartToday=localtime(&t);
  1415. tmStartToday->tm_hour = 0;
  1416. tmStartToday->tm_min = 0;
  1417. tmStartToday->tm_sec = 0;
  1418. tbStartToday.time = mktime(tmStartToday);
  1419. tbStartToday.millitm = 0;
  1420. result = DiffTimebWithNow(tbStartToday)/1000;
  1421. lastTime[gun_index] = t;
  1422. }
  1423. return result;
  1424. }
  1425. void getNowDatetime(uint8_t *data)
  1426. {
  1427. time_t t = time(NULL);
  1428. struct tm tm = *localtime(&t);
  1429. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  1430. }
  1431. int syncDateTimeRTC(uint8_t *data)
  1432. {
  1433. struct ParsingResult
  1434. {
  1435. int result;
  1436. int scanedElement;
  1437. int year;
  1438. int month;
  1439. int mday;
  1440. int hour;
  1441. int min;
  1442. int sec;
  1443. int tz_hour;
  1444. int tz_min;
  1445. float minSec;
  1446. }result;
  1447. struct tm tmOrg;
  1448. struct tm *tmTarget;
  1449. struct timeb tbTarget;
  1450. char buf[128];
  1451. memset(&result, 0x00, sizeof(struct ParsingResult));
  1452. result.result = PASS;
  1453. if(strstr((char*)data, ".") != NULL)
  1454. {
  1455. // Original data with mini second
  1456. if(strstr((char*)data, "Z") != NULL)
  1457. {
  1458. // Original data with Z
  1459. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1460. &result.year,
  1461. &result.month,
  1462. &result.mday,
  1463. &result.hour,
  1464. &result.min,
  1465. &result.sec,
  1466. &result.minSec);
  1467. }
  1468. else
  1469. {
  1470. // Original data without Z
  1471. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1472. &result.year,
  1473. &result.month,
  1474. &result.mday,
  1475. &result.hour,
  1476. &result.min,
  1477. &result.sec,
  1478. &result.minSec,
  1479. &result.tz_hour,
  1480. &result.tz_min);
  1481. }
  1482. }
  1483. else
  1484. {
  1485. // Original data without mini second
  1486. if(strstr((char*)data, "Z") != NULL)
  1487. {
  1488. // Original data with Z
  1489. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1490. &result.year,
  1491. &result.month,
  1492. &result.mday,
  1493. &result.hour,
  1494. &result.min,
  1495. &result.sec);
  1496. }
  1497. else
  1498. {
  1499. // Original data without Z
  1500. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1501. &result.year,
  1502. &result.month,
  1503. &result.mday,
  1504. &result.hour,
  1505. &result.min,
  1506. &result.sec,
  1507. &result.tz_hour,
  1508. &result.tz_min);
  1509. }
  1510. }
  1511. tmOrg.tm_year = result.year - 1900;
  1512. tmOrg.tm_mon = result.month - 1;
  1513. tmOrg.tm_mday = result.mday;
  1514. tmOrg.tm_hour = result.hour;
  1515. tmOrg.tm_min = result.min;
  1516. tmOrg.tm_sec = result.sec;
  1517. tmOrg.tm_gmtoff = 0;
  1518. tbTarget.time = mktime(&tmOrg);
  1519. tbTarget.timezone = 0;
  1520. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1521. tmTarget = gmtime(&tbTarget.time);
  1522. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  1523. //DEBUG_INFO(" org date time: %s\n", data);
  1524. //DEBUG_INFO("parse date time: %s\n", buf);
  1525. system(buf);
  1526. system("/sbin/hwclock -w --systohc");
  1527. if(result.scanedElement < 6)
  1528. result.result = FAIL;
  1529. return result.result;
  1530. }
  1531. //==========================================
  1532. // Parse certificate content
  1533. //==========================================
  1534. int parseCertInfo(char *certPath, int parseType, char *data)
  1535. {
  1536. int result = FAIL;
  1537. int count = 0;
  1538. int showupLine = 0;
  1539. memset(data, 0, ARRAY_SIZE(data));
  1540. if(access(certPath,F_OK) != -1)
  1541. {
  1542. char temp[512] = {0};
  1543. char capturedData[256] = {0};
  1544. char hashType[10] = "SHA256";
  1545. FILE *fp;
  1546. // Need to get hash type first
  1547. sprintf(temp ,"openssl x509 -noout -text -in %s", certPath);
  1548. fp = popen(temp, "r");
  1549. if(fp)
  1550. {
  1551. while(fgets(temp, sizeof(temp), fp) != NULL)
  1552. {
  1553. if(strstr(temp, "Signature Algorithm:") != NULL)
  1554. {
  1555. result = PASS;
  1556. if(strstr(temp, "sha256") != NULL || strstr(temp, "SHA256") != NULL)
  1557. sprintf((char*)hashType, "SHA256");
  1558. else if(strstr(temp, "sha384") != NULL || strstr(temp, "SHA384") != NULL)
  1559. sprintf((char*)hashType, "SHA384");
  1560. else if(strstr(temp, "sha512") != NULL || strstr(temp, "SHA512") != NULL)
  1561. sprintf((char*)hashType, "SHA512");
  1562. else
  1563. {
  1564. DEBUG_INFO("Error: hashAlgorithm is illegal or missing.\n");
  1565. result = FAIL;
  1566. }
  1567. break;
  1568. }
  1569. }
  1570. }
  1571. switch(parseType)
  1572. {
  1573. case CERT_PARSE_HashAlgorithm:
  1574. sprintf((char*)data, hashType);
  1575. DEBUG_INFO("hashAlgorithm: %s\n", hashType);
  1576. break;
  1577. case CERT_PARSE_SerialNumber:
  1578. sprintf(temp ,"openssl x509 -noout -serial -in %s", certPath);
  1579. fp = popen(temp, "r");
  1580. if(fp)
  1581. {
  1582. while(fgets(temp, sizeof(temp), fp) != NULL)
  1583. {
  1584. if(strstr(temp, "serial=") != NULL)
  1585. {
  1586. sscanf(temp, "%*[^=]=%s", capturedData);
  1587. result = PASS;
  1588. break;
  1589. }
  1590. }
  1591. DEBUG_INFO("serialNumber: %s\n", capturedData);
  1592. sprintf((char*)data, capturedData);
  1593. }
  1594. break;
  1595. case CERT_PARSE_IssuerNameHash:
  1596. sprintf(temp ,"openssl asn1parse -i < %s", certPath);
  1597. fp = popen(temp, "r");
  1598. if(fp)
  1599. {
  1600. while(fgets(temp, sizeof(temp), fp) != NULL)
  1601. {
  1602. if(strstr(temp, "SEQUENCE") != NULL)
  1603. {
  1604. count++;
  1605. if(count==4)
  1606. {
  1607. sscanf(temp, "%[^:]", capturedData);
  1608. showupLine = atoi(capturedData);
  1609. break;
  1610. }
  1611. }
  1612. }
  1613. }
  1614. if(showupLine > 0)
  1615. {
  1616. sprintf(temp ,"openssl asn1parse -i < %s -strparse %d -out /Storage/OCPP/IssuerNameHash", certPath, showupLine);
  1617. system(temp);
  1618. }
  1619. else
  1620. {
  1621. break;
  1622. }
  1623. if(access("/Storage/OCPP/IssuerNameHash",F_OK) != -1)
  1624. {
  1625. sprintf(temp ,"openssl %s < /Storage/OCPP/IssuerNameHash", (char*)hashType);
  1626. fp = popen(temp, "r");
  1627. if(fp)
  1628. {
  1629. while(fgets(temp, sizeof(temp), fp) != NULL)
  1630. {
  1631. if(strstr(temp, "(stdin)=") != NULL)
  1632. {
  1633. sscanf(temp, "%*[^=]=%s", capturedData);
  1634. result = PASS;
  1635. break;
  1636. }
  1637. }
  1638. stringtrimspace(capturedData);
  1639. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1640. sprintf((char*)data, capturedData);
  1641. }
  1642. }
  1643. break;
  1644. case CERT_PARSE_IssuerKeyHash:
  1645. sprintf(temp ,"openssl asn1parse -i < %s", certPath);
  1646. fp = popen(temp, "r");
  1647. if(fp)
  1648. {
  1649. while(fgets(temp, sizeof(temp), fp) != NULL)
  1650. {
  1651. if(strstr(temp, "BIT STRING") != NULL)
  1652. {
  1653. sscanf(temp, "%[^:]", capturedData);
  1654. showupLine = atoi(capturedData);
  1655. break;
  1656. }
  1657. }
  1658. }
  1659. if(showupLine > 0)
  1660. {
  1661. sprintf(temp ,"openssl asn1parse -i < %s -strparse %d -out /Storage/OCPP/IssuerKeyHash", certPath, showupLine);
  1662. system(temp);
  1663. }
  1664. else
  1665. {
  1666. break;
  1667. }
  1668. if(access("/Storage/OCPP/IssuerKeyHash",F_OK) != -1)
  1669. {
  1670. sprintf(temp ,"openssl %s < /Storage/OCPP/IssuerKeyHash", (char*)hashType);
  1671. fp = popen(temp, "r");
  1672. if(fp)
  1673. {
  1674. while(fgets(temp, sizeof(temp), fp) != NULL)
  1675. {
  1676. if(strstr(temp, "(stdin)=") != NULL)
  1677. {
  1678. sscanf(temp, "%*[^=]=%s", capturedData);
  1679. result = PASS;
  1680. break;
  1681. }
  1682. }
  1683. stringtrimspace(capturedData);
  1684. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1685. sprintf((char*)data, capturedData);
  1686. }
  1687. }
  1688. break;
  1689. case CERT_PARSE_OcspUrl:
  1690. //sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", certPath);
  1691. sprintf(temp ,"openssl crl2pkcs7 -nocrl -certfile %s | openssl pkcs7 -print_certs -text -noout", certPath);
  1692. fp = popen(temp, "r");
  1693. if(fp)
  1694. {
  1695. while(fgets(temp, sizeof(temp), fp) != NULL)
  1696. {
  1697. if(strstr(temp, "OCSP - URI:") != NULL)
  1698. {
  1699. //strcpy((char*)data, temp);
  1700. sscanf(temp, "%*[^:]:%s", capturedData);
  1701. sprintf((char*)data, capturedData);
  1702. DEBUG_INFO("OCSP_URI: %s\n", data);
  1703. result = PASS;
  1704. break;
  1705. }
  1706. }
  1707. }
  1708. break;
  1709. default:
  1710. DEBUG_INFO("Parse type is invalid.\n");
  1711. break;
  1712. }
  1713. pclose(fp);
  1714. }
  1715. return result;
  1716. }
  1717. //==========================================
  1718. // GetCompositeSchedule logic related function
  1719. //==========================================
  1720. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1721. {
  1722. //return milli-second
  1723. unsigned int StartTime,StopTime;
  1724. StartTime=(unsigned int)ST.time;
  1725. StopTime=(unsigned int)ET.time;
  1726. return (StopTime-StartTime);
  1727. }
  1728. int DiffTimebWithNowSec(struct timeb ST)
  1729. {
  1730. //return milli-second
  1731. struct timeb ET;
  1732. unsigned int StartTime,StopTime;
  1733. ftime(&ET);
  1734. StartTime=(unsigned int)ST.time;
  1735. StopTime=(unsigned int)ET.time;
  1736. return (StopTime-StartTime);
  1737. }
  1738. int getStartStop(uint8_t *start, uint8_t *stop)
  1739. {
  1740. struct ParsingResult
  1741. {
  1742. int result;
  1743. int scanedElement;
  1744. int year;
  1745. int month;
  1746. int mday;
  1747. int hour;
  1748. int min;
  1749. int sec;
  1750. int tz_hour;
  1751. int tz_min;
  1752. float minSec;
  1753. };
  1754. struct ParsingResult parseStart;
  1755. struct ParsingResult parseStop;
  1756. int result = -1;
  1757. struct tm tmStart;
  1758. struct timeb tbStart;
  1759. struct tm tmStop;
  1760. struct timeb tbStop;
  1761. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1762. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1763. // Scan start & stop date time
  1764. if(strstr((char*)start, ".") != NULL)
  1765. {
  1766. // Original data with mini second
  1767. if(strstr((char*)start, "Z") != NULL)
  1768. {
  1769. // Original data with Z
  1770. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1771. &parseStart.year,
  1772. &parseStart.month,
  1773. &parseStart.mday,
  1774. &parseStart.hour,
  1775. &parseStart.min,
  1776. &parseStart.sec,
  1777. &parseStart.minSec);
  1778. }
  1779. else
  1780. {
  1781. // Original data without Z
  1782. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1783. &parseStart.year,
  1784. &parseStart.month,
  1785. &parseStart.mday,
  1786. &parseStart.hour,
  1787. &parseStart.min,
  1788. &parseStart.sec,
  1789. &parseStart.minSec,
  1790. &parseStart.tz_hour,
  1791. &parseStart.tz_min);
  1792. }
  1793. }
  1794. else
  1795. {
  1796. // Original data without mini second
  1797. if(strstr((char*)start, "Z") != NULL)
  1798. {
  1799. // Original data with Z
  1800. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1801. &parseStart.year,
  1802. &parseStart.month,
  1803. &parseStart.mday,
  1804. &parseStart.hour,
  1805. &parseStart.min,
  1806. &parseStart.sec);
  1807. }
  1808. else
  1809. {
  1810. // Original data without Z
  1811. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1812. &parseStart.year,
  1813. &parseStart.month,
  1814. &parseStart.mday,
  1815. &parseStart.hour,
  1816. &parseStart.min,
  1817. &parseStart.sec,
  1818. &parseStart.tz_hour,
  1819. &parseStart.tz_min);
  1820. }
  1821. }
  1822. if(strstr((char*)stop, ".") != NULL)
  1823. {
  1824. // Original data with mini second
  1825. if(strstr((char*)stop, "Z") != NULL)
  1826. {
  1827. // Original data with Z
  1828. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1829. &parseStop.year,
  1830. &parseStop.month,
  1831. &parseStop.mday,
  1832. &parseStop.hour,
  1833. &parseStop.min,
  1834. &parseStop.sec,
  1835. &parseStop.minSec);
  1836. }
  1837. else
  1838. {
  1839. // Original data without Z
  1840. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1841. &parseStop.year,
  1842. &parseStop.month,
  1843. &parseStop.mday,
  1844. &parseStop.hour,
  1845. &parseStop.min,
  1846. &parseStop.sec,
  1847. &parseStop.minSec,
  1848. &parseStop.tz_hour,
  1849. &parseStop.tz_min);
  1850. }
  1851. }
  1852. else
  1853. {
  1854. // Original data without mini second
  1855. if(strstr((char*)stop, "Z") != NULL)
  1856. {
  1857. // Original data with Z
  1858. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1859. &parseStop.year,
  1860. &parseStop.month,
  1861. &parseStop.mday,
  1862. &parseStop.hour,
  1863. &parseStop.min,
  1864. &parseStop.sec);
  1865. }
  1866. else
  1867. {
  1868. // Original data without Z
  1869. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1870. &parseStop.year,
  1871. &parseStop.month,
  1872. &parseStop.mday,
  1873. &parseStop.hour,
  1874. &parseStop.min,
  1875. &parseStop.sec,
  1876. &parseStop.tz_hour,
  1877. &parseStop.tz_min);
  1878. }
  1879. }
  1880. // Calculate date time difference
  1881. if((parseStart.scanedElement >=6) &&
  1882. (parseStop.scanedElement >=6))
  1883. {
  1884. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  1885. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  1886. tmStart.tm_year = parseStart.year - 1900;
  1887. tmStart.tm_mon = parseStart.month - 1;
  1888. tmStart.tm_mday = parseStart.mday;
  1889. tmStart.tm_hour = parseStart.hour;
  1890. tmStart.tm_min = parseStart.min;
  1891. tmStart.tm_sec = parseStart.sec;
  1892. tmStart.tm_gmtoff = 0;
  1893. tbStart.time = mktime(&tmStart);
  1894. tbStart.timezone = 0;
  1895. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1896. tmStop.tm_year = parseStop.year - 1900;
  1897. tmStop.tm_mon = parseStop.month - 1;
  1898. tmStop.tm_mday = parseStop.mday;
  1899. tmStop.tm_hour = parseStop.hour;
  1900. tmStop.tm_min = parseStop.min;
  1901. tmStop.tm_sec = parseStop.sec;
  1902. tmStop.tm_gmtoff = 0;
  1903. tbStop.time = mktime(&tmStop);
  1904. tbStop.timezone = 0;
  1905. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1906. result = DiffTimebSec(tbStart, tbStop);
  1907. //DEBUG_INFO("getStartStop(): %d\n", result);
  1908. }
  1909. else
  1910. {
  1911. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1912. }
  1913. return result;
  1914. }
  1915. int isOvertNow(uint8_t *start)
  1916. {
  1917. int result = NO;
  1918. struct ParsingResult
  1919. {
  1920. int result;
  1921. int scanedElement;
  1922. int year;
  1923. int month;
  1924. int mday;
  1925. int hour;
  1926. int min;
  1927. int sec;
  1928. int tz_hour;
  1929. int tz_min;
  1930. float minSec;
  1931. }parsingResult;
  1932. struct tm tmStart;
  1933. struct timeb tbStart;
  1934. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1935. if(strstr((char*)start, ".") != NULL)
  1936. {
  1937. // Original data with mini second
  1938. if(strstr((char*)start, "Z") != NULL)
  1939. {
  1940. // Original data with Z
  1941. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1942. &parsingResult.year,
  1943. &parsingResult.month,
  1944. &parsingResult.mday,
  1945. &parsingResult.hour,
  1946. &parsingResult.min,
  1947. &parsingResult.sec,
  1948. &parsingResult.minSec);
  1949. }
  1950. else
  1951. {
  1952. // Original data without Z
  1953. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1954. &parsingResult.year,
  1955. &parsingResult.month,
  1956. &parsingResult.mday,
  1957. &parsingResult.hour,
  1958. &parsingResult.min,
  1959. &parsingResult.sec,
  1960. &parsingResult.minSec,
  1961. &parsingResult.tz_hour,
  1962. &parsingResult.tz_min);
  1963. }
  1964. }
  1965. else
  1966. {
  1967. // Original data without mini second
  1968. if(strstr((char*)start, "Z") != NULL)
  1969. {
  1970. // Original data with Z
  1971. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1972. &parsingResult.year,
  1973. &parsingResult.month,
  1974. &parsingResult.mday,
  1975. &parsingResult.hour,
  1976. &parsingResult.min,
  1977. &parsingResult.sec);
  1978. }
  1979. else
  1980. {
  1981. // Original data without Z
  1982. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1983. &parsingResult.year,
  1984. &parsingResult.month,
  1985. &parsingResult.mday,
  1986. &parsingResult.hour,
  1987. &parsingResult.min,
  1988. &parsingResult.sec,
  1989. &parsingResult.tz_hour,
  1990. &parsingResult.tz_min);
  1991. }
  1992. }
  1993. if(parsingResult.scanedElement >= 6)
  1994. {
  1995. tmStart.tm_year = parsingResult.year - 1900;
  1996. tmStart.tm_mon = parsingResult.month - 1;
  1997. tmStart.tm_mday = parsingResult.mday;
  1998. tmStart.tm_hour = parsingResult.hour;
  1999. tmStart.tm_min = parsingResult.min;
  2000. tmStart.tm_sec = parsingResult.sec;
  2001. tmStart.tm_gmtoff = 0;
  2002. tbStart.time = mktime(&tmStart);
  2003. tbStart.timezone = 0;
  2004. tbStart.millitm = 0;
  2005. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  2006. if(DiffTimebWithNowSec(tbStart) <= 0)
  2007. result = NO;
  2008. else
  2009. result = YES;
  2010. }
  2011. else
  2012. {
  2013. DEBUG_WARN("Start date parsing error.\n");
  2014. }
  2015. return result;
  2016. }
  2017. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  2018. {
  2019. struct ParsingResult
  2020. {
  2021. int result;
  2022. int scanedElement;
  2023. int year;
  2024. int month;
  2025. int mday;
  2026. int hour;
  2027. int min;
  2028. int sec;
  2029. int tz_hour;
  2030. int tz_min;
  2031. float minSec;
  2032. };
  2033. struct ParsingResult parseStart;
  2034. struct ParsingResult parseStop;
  2035. int result = -1;
  2036. struct tm tmStart;
  2037. struct timeb tbStart;
  2038. struct tm tmStop;
  2039. struct timeb tbStop;
  2040. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  2041. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  2042. // Scan start & stop date time
  2043. if(strstr((char*)start, ".") != NULL)
  2044. {
  2045. // Original data with mini second
  2046. if(strstr((char*)start, "Z") != NULL)
  2047. {
  2048. // Original data with Z
  2049. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  2050. &parseStart.year,
  2051. &parseStart.month,
  2052. &parseStart.mday,
  2053. &parseStart.hour,
  2054. &parseStart.min,
  2055. &parseStart.sec,
  2056. &parseStart.minSec);
  2057. }
  2058. else
  2059. {
  2060. // Original data without Z
  2061. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2062. &parseStart.year,
  2063. &parseStart.month,
  2064. &parseStart.mday,
  2065. &parseStart.hour,
  2066. &parseStart.min,
  2067. &parseStart.sec,
  2068. &parseStart.minSec,
  2069. &parseStart.tz_hour,
  2070. &parseStart.tz_min);
  2071. }
  2072. }
  2073. else
  2074. {
  2075. // Original data without mini second
  2076. if(strstr((char*)start, "Z") != NULL)
  2077. {
  2078. // Original data with Z
  2079. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  2080. &parseStart.year,
  2081. &parseStart.month,
  2082. &parseStart.mday,
  2083. &parseStart.hour,
  2084. &parseStart.min,
  2085. &parseStart.sec);
  2086. }
  2087. else
  2088. {
  2089. // Original data without Z
  2090. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  2091. &parseStart.year,
  2092. &parseStart.month,
  2093. &parseStart.mday,
  2094. &parseStart.hour,
  2095. &parseStart.min,
  2096. &parseStart.sec,
  2097. &parseStart.tz_hour,
  2098. &parseStart.tz_min);
  2099. }
  2100. }
  2101. if(strstr((char*)stop, ".") != NULL)
  2102. {
  2103. // Original data with mini second
  2104. if(strstr((char*)stop, "Z") != NULL)
  2105. {
  2106. // Original data with Z
  2107. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  2108. &parseStop.year,
  2109. &parseStop.month,
  2110. &parseStop.mday,
  2111. &parseStop.hour,
  2112. &parseStop.min,
  2113. &parseStop.sec,
  2114. &parseStop.minSec);
  2115. }
  2116. else
  2117. {
  2118. // Original data without Z
  2119. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2120. &parseStop.year,
  2121. &parseStop.month,
  2122. &parseStop.mday,
  2123. &parseStop.hour,
  2124. &parseStop.min,
  2125. &parseStop.sec,
  2126. &parseStop.minSec,
  2127. &parseStop.tz_hour,
  2128. &parseStop.tz_min);
  2129. }
  2130. }
  2131. else
  2132. {
  2133. // Original data without mini second
  2134. if(strstr((char*)stop, "Z") != NULL)
  2135. {
  2136. // Original data with Z
  2137. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  2138. &parseStop.year,
  2139. &parseStop.month,
  2140. &parseStop.mday,
  2141. &parseStop.hour,
  2142. &parseStop.min,
  2143. &parseStop.sec);
  2144. }
  2145. else
  2146. {
  2147. // Original data without Z
  2148. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  2149. &parseStop.year,
  2150. &parseStop.month,
  2151. &parseStop.mday,
  2152. &parseStop.hour,
  2153. &parseStop.min,
  2154. &parseStop.sec,
  2155. &parseStop.tz_hour,
  2156. &parseStop.tz_min);
  2157. }
  2158. }
  2159. // Calculate date time difference
  2160. if((parseStart.scanedElement >=6) &&
  2161. (parseStop.scanedElement >=6))
  2162. {
  2163. //DEBUG_INFO("Start: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStart.year, parseStart.month, parseStart.mday, parseStart.hour, parseStart.min, parseStart.sec, parseStart.tz_hour, parseStart.tz_min);
  2164. //DEBUG_INFO("Stop: %04d-%02d-%02d %02d:%02d:%02d(%02d:%02d)\n", parseStop.year, parseStop.month, parseStop.mday, parseStop.hour, parseStop.min, parseStop.sec, parseStop.tz_hour, parseStop.tz_min);
  2165. tmStart.tm_year = parseStart.year - 1900;
  2166. tmStart.tm_mon = parseStart.month - 1;
  2167. tmStart.tm_mday = parseStart.mday;
  2168. tmStart.tm_hour = parseStart.hour;
  2169. tmStart.tm_min = parseStart.min;
  2170. tmStart.tm_sec = parseStart.sec;
  2171. tmStart.tm_gmtoff = 0;
  2172. tbStart.time = mktime(&tmStart);
  2173. tbStart.timezone = 0;
  2174. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  2175. tmStop.tm_year = parseStop.year - 1900;
  2176. tmStop.tm_mon = parseStop.month - 1;
  2177. tmStop.tm_mday = parseStop.mday;
  2178. tmStop.tm_hour = parseStop.hour;
  2179. tmStop.tm_min = parseStop.min;
  2180. tmStop.tm_sec = parseStop.sec;
  2181. tmStop.tm_gmtoff = 0;
  2182. tbStop.time = mktime(&tmStop);
  2183. tbStop.timezone = 0;
  2184. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  2185. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  2186. //DEBUG_INFO("getStartStop(): %d\n", result);
  2187. }
  2188. else
  2189. {
  2190. DEBUG_WARN("Start or stop date parsing error.\r\n");
  2191. }
  2192. return result;
  2193. }
  2194. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2195. {
  2196. FILE *fp;
  2197. char profileFileName[128];
  2198. char *line = NULL;
  2199. size_t len = 0;
  2200. time_t CurrentTime;
  2201. struct tm *tmComposite;
  2202. struct StructChargingProfile maxProfile;
  2203. struct StructChargingProfile compositeProfile;
  2204. uint8_t limitMax=0;
  2205. int compositePeriodIdx = 0;
  2206. //uint8_t isDurationNull = FALSE;
  2207. CurrentTime = time(NULL);
  2208. tmComposite=localtime(&CurrentTime);
  2209. sprintf((char*)compositeProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  2210. if(isUnitA)
  2211. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2212. else
  2213. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2214. compositeProfile.ChargingSchedule.Duration = durationReq;
  2215. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2216. {
  2217. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2218. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2219. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2220. }
  2221. compositeProfile.ChargingProfileId = 0;
  2222. compositeProfile.StackLevel = 99 ;
  2223. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2224. maxProfile.ChargingProfileId = -1;
  2225. maxProfile.ChargingSchedule.Duration = -1;
  2226. system("rm -f /tmp/*.json");
  2227. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2228. // Search max profile
  2229. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2230. if((access(profileFileName, F_OK))!=-1)
  2231. {
  2232. fp = fopen(profileFileName, "r");
  2233. while(getline(&line, &len, fp) != -1)
  2234. {
  2235. json_object *obj = NULL;
  2236. obj = json_tokener_parse(line);
  2237. if(is_error(obj))
  2238. {
  2239. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2240. }
  2241. else
  2242. {
  2243. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2244. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2245. )
  2246. {
  2247. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2248. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2249. )
  2250. {
  2251. struct tm tmFrom, tmTo;
  2252. struct timeb tbFrom, tbTo;
  2253. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2254. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2255. {
  2256. tmFrom.tm_year -= 1900;
  2257. tmFrom.tm_mon -= 1;
  2258. tbFrom.time = mktime(&tmFrom);
  2259. tmTo.tm_year -= 1900;
  2260. tmTo.tm_mon -= 1;
  2261. tbTo.time = mktime(&tmTo);
  2262. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2263. {
  2264. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2265. {
  2266. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2267. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2268. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2269. }
  2270. if(maxProfile.ChargingProfileId == -1)
  2271. DEBUG_INFO("MaxProfile found.\n");
  2272. else
  2273. DEBUG_INFO("MaxProfile updated.\n");
  2274. // Required item
  2275. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2276. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2277. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2278. if(isUnitA)
  2279. {
  2280. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2281. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2282. {
  2283. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2284. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2285. 3:
  2286. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2287. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2288. }
  2289. }
  2290. else
  2291. {
  2292. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2293. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2294. {
  2295. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2296. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2297. 3:
  2298. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2299. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2300. }
  2301. }
  2302. // Optional item
  2303. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2304. {
  2305. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2306. }
  2307. else
  2308. {
  2309. sprintf((char*)maxProfile.ValidFrom, " ");
  2310. }
  2311. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2312. {
  2313. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2314. }
  2315. else
  2316. {
  2317. sprintf((char*)maxProfile.ValidTo, " ");
  2318. }
  2319. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2320. {
  2321. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2322. }
  2323. else
  2324. {
  2325. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2326. }
  2327. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2328. {
  2329. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2330. }
  2331. else
  2332. {
  2333. maxProfile.TransactionId = -1;
  2334. }
  2335. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2336. {
  2337. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2338. }
  2339. else
  2340. {
  2341. maxProfile.ChargingSchedule.Duration = 86400;
  2342. //isDurationNull = TRUE;
  2343. }
  2344. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2345. {
  2346. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2347. }
  2348. else
  2349. {
  2350. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2351. }
  2352. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2353. {
  2354. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2355. }
  2356. else
  2357. {
  2358. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2359. }
  2360. }
  2361. }
  2362. }
  2363. else
  2364. {
  2365. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2366. {
  2367. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2368. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2369. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2370. }
  2371. if(maxProfile.ChargingProfileId == -1)
  2372. DEBUG_INFO("MaxProfile found.\n");
  2373. else
  2374. DEBUG_INFO("MaxProfile updated.\n");
  2375. // Required item
  2376. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2377. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2378. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2379. if(isUnitA)
  2380. {
  2381. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2382. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2383. {
  2384. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2385. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2386. 3:
  2387. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2388. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2389. }
  2390. }
  2391. else
  2392. {
  2393. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2394. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2395. {
  2396. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2397. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2398. 3:
  2399. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2400. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2401. }
  2402. }
  2403. // Optional item
  2404. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2405. {
  2406. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2407. }
  2408. else
  2409. {
  2410. sprintf((char*)maxProfile.ValidFrom, " ");
  2411. }
  2412. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2413. {
  2414. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2415. }
  2416. else
  2417. {
  2418. sprintf((char*)maxProfile.ValidTo, " ");
  2419. }
  2420. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2421. {
  2422. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2423. }
  2424. else
  2425. {
  2426. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2427. }
  2428. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2429. {
  2430. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2431. }
  2432. else
  2433. {
  2434. maxProfile.TransactionId = -1;
  2435. }
  2436. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2437. {
  2438. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2439. }
  2440. else
  2441. {
  2442. maxProfile.ChargingSchedule.Duration = 86400;
  2443. //isDurationNull = TRUE;
  2444. }
  2445. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2446. {
  2447. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2448. }
  2449. else
  2450. {
  2451. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2452. }
  2453. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2454. {
  2455. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2456. }
  2457. else
  2458. {
  2459. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2460. }
  2461. }
  2462. }
  2463. }
  2464. json_object_put(obj);
  2465. }
  2466. fclose(fp);
  2467. /*
  2468. if(maxProfile.ChargingProfileId !=-1)
  2469. {
  2470. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2471. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2472. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2473. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2474. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2475. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2476. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2477. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2478. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2479. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2480. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2481. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2482. {
  2483. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2484. {
  2485. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2486. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2487. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2488. }
  2489. }
  2490. }
  2491. else
  2492. DEBUG_INFO("MaxProfile not found.\n");
  2493. DEBUG_INFO("------------------------------------\n");*/
  2494. }
  2495. if(maxProfile.ChargingProfileId != -1)
  2496. {
  2497. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2498. {
  2499. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  2500. {
  2501. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2502. 0:
  2503. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2504. }
  2505. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2506. {
  2507. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2508. {
  2509. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2510. 0:
  2511. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2512. if(idxPeriod > 0)
  2513. {
  2514. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2515. {
  2516. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2517. }
  2518. }
  2519. }
  2520. }
  2521. }
  2522. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2523. {
  2524. if(maxProfile.ChargingSchedule.Duration != -1)
  2525. {
  2526. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2527. }
  2528. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2529. {
  2530. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2531. {
  2532. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2533. if(idxPeriod > 0)
  2534. {
  2535. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2536. {
  2537. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2538. }
  2539. }
  2540. }
  2541. }
  2542. }
  2543. else
  2544. {
  2545. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2546. {
  2547. if(maxProfile.ChargingSchedule.Duration != -1)
  2548. {
  2549. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2550. 0:
  2551. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2552. }
  2553. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2554. {
  2555. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2556. {
  2557. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2558. 0:
  2559. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2560. if(idxPeriod > 0)
  2561. {
  2562. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2563. {
  2564. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2565. }
  2566. }
  2567. }
  2568. }
  2569. }
  2570. else
  2571. {
  2572. if(maxProfile.ChargingSchedule.Duration != -1)
  2573. {
  2574. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2575. 0:
  2576. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2577. }
  2578. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2579. {
  2580. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2581. {
  2582. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2583. 0:
  2584. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2585. if(idxPeriod > 0)
  2586. {
  2587. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2588. {
  2589. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2590. }
  2591. }
  2592. }
  2593. }
  2594. }
  2595. }
  2596. /*
  2597. DEBUG_INFO("MaxProfile after align.\n");
  2598. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2599. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2600. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2601. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2602. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2603. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2604. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2605. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2606. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2607. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2608. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2609. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2610. {
  2611. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2612. {
  2613. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2614. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2615. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2616. }
  2617. }
  2618. DEBUG_INFO("------------------------------------\n");*/
  2619. }
  2620. // Find each profile period quantity
  2621. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2622. {
  2623. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2624. limitMax = idx+1;
  2625. }
  2626. if(maxProfile.ChargingProfileId != -1)
  2627. {
  2628. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2629. {
  2630. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2631. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2632. (maxProfile.ChargingSchedule.Duration > 0))
  2633. {
  2634. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2635. {
  2636. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2637. compositePeriodIdx++;
  2638. }
  2639. else
  2640. {
  2641. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2642. }
  2643. }
  2644. }
  2645. }
  2646. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2647. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2648. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2649. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2650. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2651. {
  2652. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2653. {
  2654. compositeProfile.ChargingProfileId = 1;
  2655. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2656. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2657. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2658. }
  2659. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2660. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2661. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2662. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2663. }
  2664. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2665. if(line)
  2666. free(line);
  2667. }
  2668. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2669. {
  2670. FILE *fp;
  2671. char profileFileName[128];
  2672. char *line = NULL;
  2673. size_t len = 0;
  2674. time_t CurrentTime;
  2675. struct tm *tmComposite;
  2676. struct StructChargingProfile maxProfile;
  2677. struct StructChargingProfile defaultTxProfile;
  2678. struct StructChargingProfile txProfile;
  2679. struct StructChargingProfile compositeProfile;
  2680. struct StructChargingSchedulePeriod tmpPeriod;
  2681. uint8_t limitMax=0;
  2682. uint8_t limitDef=0;
  2683. uint8_t limitTx=0;
  2684. int compositePeriodIdx = 0;
  2685. CurrentTime = time(NULL);
  2686. tmComposite=localtime(&CurrentTime);
  2687. sprintf((char*)compositeProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  2688. if(isUnitA)
  2689. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2690. else
  2691. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2692. compositeProfile.ChargingSchedule.Duration = durationReq;
  2693. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2694. {
  2695. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2696. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2697. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2698. }
  2699. compositeProfile.ChargingProfileId = 0;
  2700. compositeProfile.StackLevel = 99 ;
  2701. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2702. maxProfile.ChargingProfileId = -1;
  2703. defaultTxProfile.ChargingProfileId = -1;
  2704. txProfile.ChargingProfileId = -1;
  2705. maxProfile.ChargingSchedule.Duration = -1;
  2706. defaultTxProfile.ChargingSchedule.Duration = -1;
  2707. txProfile.ChargingSchedule.Duration = -1;
  2708. system("rm -f /tmp/*.json");
  2709. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2710. /*
  2711. * Search valid charging profile
  2712. */
  2713. //DEBUG_INFO("====================================\n");
  2714. // Search tx profile
  2715. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2716. if((access(profileFileName, F_OK))!=-1)
  2717. {
  2718. fp = fopen(profileFileName, "r");
  2719. while(getline(&line, &len, fp) != -1)
  2720. {
  2721. json_object *obj = NULL;
  2722. obj = json_tokener_parse(line);
  2723. if(is_error(obj))
  2724. {
  2725. DEBUG_ERROR("Parse txProfile from file error.\n");
  2726. }
  2727. else
  2728. {
  2729. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2730. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2731. )
  2732. {
  2733. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2734. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2735. )
  2736. {
  2737. struct tm tmFrom, tmTo;
  2738. struct timeb tbFrom, tbTo;
  2739. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2740. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2741. {
  2742. tmFrom.tm_year -= 1900;
  2743. tmFrom.tm_mon -= 1;
  2744. tbFrom.time = mktime(&tmFrom);
  2745. tmTo.tm_year -= 1900;
  2746. tmTo.tm_mon -= 1;
  2747. tbTo.time = mktime(&tmTo);
  2748. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2749. {
  2750. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2751. {
  2752. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2753. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2754. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2755. }
  2756. if(txProfile.ChargingProfileId == -1)
  2757. DEBUG_INFO("TxProfile found.\n");
  2758. else
  2759. DEBUG_INFO("TxProfile updated.\n");
  2760. // Required item
  2761. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2762. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2763. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2764. if(isUnitA)
  2765. {
  2766. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2767. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2768. {
  2769. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2770. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2771. 3:
  2772. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2773. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2774. }
  2775. }
  2776. else
  2777. {
  2778. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2779. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2780. {
  2781. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2782. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2783. 3:
  2784. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2785. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2786. }
  2787. }
  2788. // Optional item
  2789. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2790. {
  2791. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2792. }
  2793. else
  2794. {
  2795. sprintf((char*)txProfile.ValidFrom, " ");
  2796. }
  2797. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2798. {
  2799. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2800. }
  2801. else
  2802. {
  2803. sprintf((char*)txProfile.ValidTo, " ");
  2804. }
  2805. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2806. {
  2807. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2808. }
  2809. else
  2810. {
  2811. sprintf((char*)txProfile.RecurrencyKind, " ");
  2812. }
  2813. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2814. {
  2815. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2816. }
  2817. else
  2818. {
  2819. txProfile.TransactionId = -1;
  2820. }
  2821. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2822. {
  2823. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2824. }
  2825. else
  2826. {
  2827. txProfile.ChargingSchedule.Duration = 86400;
  2828. }
  2829. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2830. {
  2831. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2832. }
  2833. else
  2834. {
  2835. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2836. }
  2837. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2838. {
  2839. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2840. }
  2841. else
  2842. {
  2843. txProfile.ChargingSchedule.MinChargingRate = -1;
  2844. }
  2845. }
  2846. }
  2847. }
  2848. else
  2849. {
  2850. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2851. {
  2852. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2853. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2854. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2855. }
  2856. if(txProfile.ChargingProfileId == -1)
  2857. DEBUG_INFO("TxProfile found.\n");
  2858. else
  2859. DEBUG_INFO("TxProfile updated.\n");
  2860. // Required item
  2861. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2862. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2863. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2864. if(isUnitA)
  2865. {
  2866. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2867. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2868. {
  2869. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2870. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2871. 3:
  2872. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2873. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2874. }
  2875. }
  2876. else
  2877. {
  2878. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2879. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2880. {
  2881. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2882. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2883. 3:
  2884. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2885. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  2886. }
  2887. }
  2888. // Optional item
  2889. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2890. {
  2891. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2892. }
  2893. else
  2894. {
  2895. sprintf((char*)txProfile.ValidFrom, " ");
  2896. }
  2897. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2898. {
  2899. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2900. }
  2901. else
  2902. {
  2903. sprintf((char*)txProfile.ValidTo, " ");
  2904. }
  2905. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2906. {
  2907. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2908. }
  2909. else
  2910. {
  2911. sprintf((char*)txProfile.RecurrencyKind, " ");
  2912. }
  2913. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2914. {
  2915. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2916. }
  2917. else
  2918. {
  2919. txProfile.TransactionId = -1;
  2920. }
  2921. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2922. {
  2923. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2924. }
  2925. else
  2926. {
  2927. txProfile.ChargingSchedule.Duration = 86400;
  2928. }
  2929. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2930. {
  2931. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  2932. }
  2933. else
  2934. {
  2935. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2936. }
  2937. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2938. {
  2939. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2940. }
  2941. else
  2942. {
  2943. txProfile.ChargingSchedule.MinChargingRate = -1;
  2944. }
  2945. }
  2946. }
  2947. }
  2948. json_object_put(obj);
  2949. }
  2950. fclose(fp);
  2951. /*
  2952. if(txProfile.ChargingProfileId != -1)
  2953. {
  2954. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2955. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2956. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2957. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2958. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2959. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2960. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2961. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2962. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2963. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2964. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2965. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2966. {
  2967. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2968. {
  2969. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2970. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2971. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2972. }
  2973. }
  2974. }
  2975. else
  2976. DEBUG_INFO("TxProfile not found.\n");*/
  2977. }
  2978. // Search default tx profile
  2979. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2980. if((access(profileFileName, F_OK))==-1)
  2981. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2982. if((access(profileFileName, F_OK))!=-1)
  2983. {
  2984. fp = fopen(profileFileName, "r");
  2985. while(getline(&line, &len, fp) != -1)
  2986. {
  2987. json_object *obj = NULL;
  2988. obj = json_tokener_parse(line);
  2989. if(is_error(obj))
  2990. {
  2991. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2992. }
  2993. else
  2994. {
  2995. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2996. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2997. )
  2998. {
  2999. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3000. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3001. )
  3002. {
  3003. struct tm tmFrom, tmTo;
  3004. struct timeb tbFrom, tbTo;
  3005. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  3006. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  3007. {
  3008. tmFrom.tm_year -= 1900;
  3009. tmFrom.tm_mon -= 1;
  3010. tbFrom.time = mktime(&tmFrom);
  3011. tmTo.tm_year -= 1900;
  3012. tmTo.tm_mon -= 1;
  3013. tbTo.time = mktime(&tmTo);
  3014. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3015. {
  3016. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3017. {
  3018. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3019. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3020. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3021. }
  3022. if(defaultTxProfile.ChargingProfileId == -1)
  3023. DEBUG_INFO("TxDefaultProfile found.\n");
  3024. else
  3025. DEBUG_INFO("TxDefaultProfile updated.\n");
  3026. // Required item
  3027. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3028. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3029. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3030. if(isUnitA)
  3031. {
  3032. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3033. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3034. {
  3035. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3036. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3037. 3:
  3038. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3039. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3040. }
  3041. }
  3042. else
  3043. {
  3044. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3045. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3046. {
  3047. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3048. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3049. 3:
  3050. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3051. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  3052. }
  3053. }
  3054. // Optional item
  3055. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3056. {
  3057. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3058. }
  3059. else
  3060. {
  3061. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  3062. }
  3063. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3064. {
  3065. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3066. }
  3067. else
  3068. {
  3069. sprintf((char*)defaultTxProfile.ValidTo, " ");
  3070. }
  3071. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3072. {
  3073. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3074. }
  3075. else
  3076. {
  3077. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  3078. }
  3079. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3080. {
  3081. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3082. }
  3083. else
  3084. {
  3085. defaultTxProfile.TransactionId = -1;
  3086. }
  3087. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3088. {
  3089. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3090. }
  3091. else
  3092. {
  3093. defaultTxProfile.ChargingSchedule.Duration = 86400;
  3094. }
  3095. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3096. {
  3097. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3098. }
  3099. else
  3100. {
  3101. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  3102. }
  3103. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3104. {
  3105. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3106. }
  3107. else
  3108. {
  3109. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  3110. }
  3111. }
  3112. }
  3113. }
  3114. else
  3115. {
  3116. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3117. {
  3118. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3119. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3120. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3121. }
  3122. if(defaultTxProfile.ChargingProfileId == -1)
  3123. DEBUG_INFO("TxDefaultProfile found.\n");
  3124. else
  3125. DEBUG_INFO("TxDefaultProfile updated.\n");
  3126. // Required item
  3127. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3128. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3129. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3130. if(isUnitA)
  3131. {
  3132. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3133. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3134. {
  3135. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3136. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3137. 3:
  3138. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3139. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3140. }
  3141. }
  3142. else
  3143. {
  3144. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3145. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3146. {
  3147. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3148. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3149. 3:
  3150. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3151. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  3152. }
  3153. }
  3154. // Optional item
  3155. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3156. {
  3157. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3158. }
  3159. else
  3160. {
  3161. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  3162. }
  3163. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3164. {
  3165. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3166. }
  3167. else
  3168. {
  3169. sprintf((char*)defaultTxProfile.ValidTo, " ");
  3170. }
  3171. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3172. {
  3173. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3174. }
  3175. else
  3176. {
  3177. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  3178. }
  3179. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3180. {
  3181. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3182. }
  3183. else
  3184. {
  3185. defaultTxProfile.TransactionId = -1;
  3186. }
  3187. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3188. {
  3189. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3190. }
  3191. else
  3192. {
  3193. defaultTxProfile.ChargingSchedule.Duration = 86400;
  3194. }
  3195. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3196. {
  3197. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3198. }
  3199. else
  3200. {
  3201. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  3202. }
  3203. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3204. {
  3205. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3206. }
  3207. else
  3208. {
  3209. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  3210. }
  3211. }
  3212. }
  3213. }
  3214. json_object_put(obj);
  3215. }
  3216. fclose(fp);
  3217. /*
  3218. if(defaultTxProfile.ChargingProfileId != -1)
  3219. {
  3220. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3221. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3222. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3223. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3224. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3225. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3226. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3227. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  3228. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3229. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3230. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3231. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3232. {
  3233. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3234. {
  3235. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3236. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3237. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3238. }
  3239. }
  3240. }
  3241. else
  3242. DEBUG_INFO("TxDefaultProfile not found.\n");
  3243. DEBUG_INFO("------------------------------------\n");*/
  3244. }
  3245. // Search max profile
  3246. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  3247. if((access(profileFileName, F_OK))!=-1)
  3248. {
  3249. fp = fopen(profileFileName, "r");
  3250. while(getline(&line, &len, fp) != -1)
  3251. {
  3252. json_object *obj = NULL;
  3253. obj = json_tokener_parse(line);
  3254. if(is_error(obj))
  3255. {
  3256. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  3257. }
  3258. else
  3259. {
  3260. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  3261. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  3262. )
  3263. {
  3264. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3265. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3266. )
  3267. {
  3268. struct tm tmFrom, tmTo;
  3269. struct timeb tbFrom, tbTo;
  3270. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  3271. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  3272. {
  3273. tmFrom.tm_year -= 1900;
  3274. tmFrom.tm_mon -= 1;
  3275. tbFrom.time = mktime(&tmFrom);
  3276. tmTo.tm_year -= 1900;
  3277. tmTo.tm_mon -= 1;
  3278. tbTo.time = mktime(&tmTo);
  3279. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3280. {
  3281. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3282. {
  3283. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3284. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3285. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3286. }
  3287. if(maxProfile.ChargingProfileId == -1)
  3288. DEBUG_INFO("MaxProfile found.\n");
  3289. else
  3290. DEBUG_INFO("MaxProfile updated.\n");
  3291. // Required item
  3292. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3293. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3294. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3295. if(isUnitA)
  3296. {
  3297. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3298. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3299. {
  3300. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3301. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3302. 3:
  3303. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3304. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3305. }
  3306. }
  3307. else
  3308. {
  3309. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3310. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3311. {
  3312. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3313. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3314. 3:
  3315. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3316. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  3317. }
  3318. }
  3319. // Optional item
  3320. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3321. {
  3322. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3323. }
  3324. else
  3325. {
  3326. sprintf((char*)maxProfile.ValidFrom, " ");
  3327. }
  3328. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3329. {
  3330. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3331. }
  3332. else
  3333. {
  3334. sprintf((char*)maxProfile.ValidTo, " ");
  3335. }
  3336. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3337. {
  3338. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3339. }
  3340. else
  3341. {
  3342. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3343. }
  3344. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3345. {
  3346. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3347. }
  3348. else
  3349. {
  3350. maxProfile.TransactionId = -1;
  3351. }
  3352. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3353. {
  3354. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3355. }
  3356. else
  3357. {
  3358. maxProfile.ChargingSchedule.Duration = 86400;
  3359. }
  3360. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3361. {
  3362. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3363. }
  3364. else
  3365. {
  3366. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  3367. }
  3368. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3369. {
  3370. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3371. }
  3372. else
  3373. {
  3374. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3375. }
  3376. }
  3377. }
  3378. }
  3379. else
  3380. {
  3381. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3382. {
  3383. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3384. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3385. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3386. }
  3387. if(maxProfile.ChargingProfileId == -1)
  3388. DEBUG_INFO("MaxProfile found.\n");
  3389. else
  3390. DEBUG_INFO("MaxProfile updated.\n");
  3391. // Required item
  3392. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3393. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3394. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3395. if(isUnitA)
  3396. {
  3397. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3398. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3399. {
  3400. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3401. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3402. 3:
  3403. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3404. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3405. }
  3406. }
  3407. else
  3408. {
  3409. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3410. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3411. {
  3412. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3413. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3414. 3:
  3415. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3416. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  3417. }
  3418. }
  3419. // Optional item
  3420. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3421. {
  3422. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3423. }
  3424. else
  3425. {
  3426. sprintf((char*)maxProfile.ValidFrom, " ");
  3427. }
  3428. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3429. {
  3430. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3431. }
  3432. else
  3433. {
  3434. sprintf((char*)maxProfile.ValidTo, " ");
  3435. }
  3436. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3437. {
  3438. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3439. }
  3440. else
  3441. {
  3442. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3443. }
  3444. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3445. {
  3446. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3447. }
  3448. else
  3449. {
  3450. maxProfile.TransactionId = -1;
  3451. }
  3452. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3453. {
  3454. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3455. }
  3456. else
  3457. {
  3458. maxProfile.ChargingSchedule.Duration = 86400;
  3459. }
  3460. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3461. {
  3462. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3463. }
  3464. else
  3465. {
  3466. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile.ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  3467. }
  3468. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3469. {
  3470. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3471. }
  3472. else
  3473. {
  3474. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3475. }
  3476. }
  3477. }
  3478. }
  3479. json_object_put(obj);
  3480. }
  3481. fclose(fp);
  3482. /*
  3483. if(maxProfile.ChargingProfileId !=-1)
  3484. {
  3485. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3486. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3487. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3488. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3489. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3490. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3491. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3492. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3493. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3494. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3495. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3496. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3497. {
  3498. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3499. {
  3500. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3501. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3502. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3503. }
  3504. }
  3505. }
  3506. else
  3507. DEBUG_INFO("MaxProfile not found.\n");
  3508. DEBUG_INFO("------------------------------------\n");*/
  3509. }
  3510. /*
  3511. * Align found profile start schedule & periods
  3512. */
  3513. //DEBUG_INFO("====================================\n");
  3514. /*
  3515. // For local test usage, force modify found profile start schedule info
  3516. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  3517. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  3518. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  3519. */
  3520. if(txProfile.ChargingProfileId != -1)
  3521. {
  3522. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3523. {
  3524. if(txProfile.ChargingSchedule.Duration != -1)
  3525. {
  3526. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3527. 0:
  3528. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3529. }
  3530. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3531. {
  3532. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3533. {
  3534. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3535. 0:
  3536. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3537. if(idxPeriod > 0)
  3538. {
  3539. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3540. {
  3541. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3542. }
  3543. }
  3544. }
  3545. }
  3546. }
  3547. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3548. {
  3549. if(txProfile.ChargingSchedule.Duration != -1)
  3550. {
  3551. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3552. 0:
  3553. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3554. }
  3555. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3556. {
  3557. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3558. {
  3559. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3560. 0:
  3561. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3562. if(idxPeriod > 0)
  3563. {
  3564. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3565. {
  3566. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3567. }
  3568. }
  3569. }
  3570. }
  3571. }
  3572. else
  3573. {
  3574. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3575. {
  3576. if(txProfile.ChargingSchedule.Duration != -1)
  3577. {
  3578. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3579. 0:
  3580. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3581. }
  3582. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3583. {
  3584. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3585. {
  3586. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3587. 0:
  3588. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3589. if(idxPeriod > 0)
  3590. {
  3591. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3592. {
  3593. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3594. }
  3595. }
  3596. }
  3597. }
  3598. }
  3599. else
  3600. {
  3601. if(txProfile.ChargingSchedule.Duration != -1)
  3602. {
  3603. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3604. 0:
  3605. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3606. }
  3607. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3608. {
  3609. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3610. {
  3611. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3612. 0:
  3613. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3614. if(idxPeriod > 0)
  3615. {
  3616. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3617. {
  3618. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3619. }
  3620. }
  3621. }
  3622. }
  3623. }
  3624. }
  3625. /*
  3626. DEBUG_INFO("txProfile after align.\n");
  3627. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3628. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3629. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3630. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3631. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3632. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3633. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3634. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3635. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3636. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3637. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3638. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3639. {
  3640. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3641. {
  3642. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3643. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3644. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3645. }
  3646. }*/
  3647. }
  3648. if(defaultTxProfile.ChargingProfileId != -1)
  3649. {
  3650. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3651. {
  3652. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3653. {
  3654. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3655. 0:
  3656. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3657. }
  3658. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3659. {
  3660. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3661. {
  3662. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3663. 0:
  3664. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3665. if(idxPeriod > 0)
  3666. {
  3667. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3668. {
  3669. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3670. }
  3671. }
  3672. }
  3673. }
  3674. }
  3675. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3676. {
  3677. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3678. {
  3679. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3680. 0:
  3681. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3682. }
  3683. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3684. {
  3685. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3686. {
  3687. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3688. 0:
  3689. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3690. if(idxPeriod > 0)
  3691. {
  3692. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3693. {
  3694. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3695. }
  3696. }
  3697. }
  3698. }
  3699. }
  3700. else
  3701. {
  3702. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3703. {
  3704. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3705. {
  3706. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3707. 0:
  3708. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3709. }
  3710. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3711. {
  3712. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3713. {
  3714. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3715. 0:
  3716. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3717. if(idxPeriod > 0)
  3718. {
  3719. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3720. {
  3721. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3722. }
  3723. }
  3724. }
  3725. }
  3726. }
  3727. else
  3728. {
  3729. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3730. {
  3731. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3732. 0:
  3733. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3734. }
  3735. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3736. {
  3737. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3738. {
  3739. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3740. 0:
  3741. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3742. if(idxPeriod > 0)
  3743. {
  3744. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3745. {
  3746. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3747. }
  3748. }
  3749. }
  3750. }
  3751. }
  3752. }
  3753. /*
  3754. DEBUG_INFO("defaultTxProfile after align.\n");
  3755. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3756. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3757. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3758. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3759. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3760. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3761. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3762. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3763. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3764. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3765. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3766. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3767. {
  3768. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3769. {
  3770. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3771. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3772. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3773. }
  3774. }
  3775. DEBUG_INFO("------------------------------------\n");*/
  3776. }
  3777. if(maxProfile.ChargingProfileId != -1)
  3778. {
  3779. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3780. {
  3781. if(maxProfile.ChargingSchedule.Duration != -1)
  3782. {
  3783. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3784. 0:
  3785. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3786. }
  3787. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3788. {
  3789. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3790. {
  3791. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3792. 0:
  3793. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3794. if(idxPeriod > 0)
  3795. {
  3796. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3797. {
  3798. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3799. }
  3800. }
  3801. }
  3802. }
  3803. }
  3804. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3805. {
  3806. if(maxProfile.ChargingSchedule.Duration != -1)
  3807. {
  3808. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3809. 0:
  3810. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3811. }
  3812. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3813. {
  3814. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3815. {
  3816. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3817. 0:
  3818. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3819. if(idxPeriod > 0)
  3820. {
  3821. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3822. {
  3823. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3824. }
  3825. }
  3826. }
  3827. }
  3828. }
  3829. else
  3830. {
  3831. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3832. {
  3833. if(maxProfile.ChargingSchedule.Duration != -1)
  3834. {
  3835. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3836. 0:
  3837. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3838. }
  3839. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3840. {
  3841. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3842. {
  3843. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3844. 0:
  3845. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3846. if(idxPeriod > 0)
  3847. {
  3848. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3849. {
  3850. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3851. }
  3852. }
  3853. }
  3854. }
  3855. }
  3856. else
  3857. {
  3858. if(maxProfile.ChargingSchedule.Duration != -1)
  3859. {
  3860. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3861. 0:
  3862. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3863. }
  3864. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3865. {
  3866. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3867. {
  3868. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3869. 0:
  3870. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3871. if(idxPeriod > 0)
  3872. {
  3873. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3874. {
  3875. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3876. }
  3877. }
  3878. }
  3879. }
  3880. }
  3881. }
  3882. /*
  3883. DEBUG_INFO("MaxProfile after align.\n");
  3884. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3885. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3886. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3887. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3888. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3889. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3890. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3891. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3892. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3893. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3894. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3895. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3896. {
  3897. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3898. {
  3899. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3900. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3901. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3902. }
  3903. }
  3904. DEBUG_INFO("------------------------------------\n");*/
  3905. }
  3906. /*
  3907. * Merge to composite schedule
  3908. */
  3909. //DEBUG_INFO("====================================\n");
  3910. // Find each profile period quantity
  3911. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3912. {
  3913. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3914. limitMax = idx+1;
  3915. }
  3916. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3917. {
  3918. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3919. limitDef = idx+1;
  3920. }
  3921. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3922. {
  3923. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3924. limitTx = idx+1;
  3925. }
  3926. // TxProfile found, composite schedule based on it
  3927. if(txProfile.ChargingProfileId != -1)
  3928. {
  3929. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3930. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3931. {
  3932. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3933. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3934. (txProfile.ChargingSchedule.Duration > 0))
  3935. {
  3936. if(maxProfile.ChargingProfileId != -1)
  3937. {
  3938. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3939. {
  3940. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3941. {
  3942. if((maxProfile.ChargingSchedule.Duration > 0))
  3943. {
  3944. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3945. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3946. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3947. }
  3948. else
  3949. {
  3950. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3951. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3952. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3953. }
  3954. }
  3955. if(idxMaxPeriod == (limitMax-1))
  3956. {
  3957. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3958. {
  3959. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3960. {
  3961. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3962. compositePeriodIdx++;
  3963. }
  3964. else
  3965. {
  3966. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3967. }
  3968. }
  3969. }
  3970. }
  3971. }
  3972. else
  3973. {
  3974. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3975. {
  3976. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3977. compositePeriodIdx++;
  3978. }
  3979. else
  3980. {
  3981. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3982. }
  3983. }
  3984. }
  3985. if(idxTxPeriod == (limitTx-1))
  3986. {
  3987. if(defaultTxProfile.ChargingProfileId != -1)
  3988. {
  3989. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3990. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3991. {
  3992. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3993. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3994. (defaultTxProfile.ChargingSchedule.Duration>0))
  3995. {
  3996. if(maxProfile.ChargingProfileId != -1)
  3997. {
  3998. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3999. {
  4000. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  4001. {
  4002. if((maxProfile.ChargingSchedule.Duration > 0))
  4003. {
  4004. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  4005. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  4006. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  4007. }
  4008. else
  4009. {
  4010. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  4011. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  4012. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  4013. }
  4014. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  4015. {
  4016. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4017. {
  4018. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4019. compositePeriodIdx++;
  4020. }
  4021. else
  4022. {
  4023. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4024. }
  4025. }
  4026. // Delete duplicate period
  4027. if(compositePeriodIdx > 1)
  4028. {
  4029. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4030. {
  4031. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4032. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4033. compositePeriodIdx -= 1;
  4034. }
  4035. }
  4036. }
  4037. else
  4038. {
  4039. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4040. {
  4041. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4042. compositePeriodIdx++;
  4043. }
  4044. else
  4045. {
  4046. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4047. }
  4048. break;
  4049. }
  4050. }
  4051. }
  4052. else
  4053. {
  4054. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4055. {
  4056. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4057. compositePeriodIdx++;
  4058. }
  4059. else
  4060. {
  4061. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4062. }
  4063. }
  4064. }
  4065. }
  4066. }
  4067. }
  4068. }
  4069. }
  4070. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  4071. else if(defaultTxProfile.ChargingProfileId != -1)
  4072. {
  4073. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  4074. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  4075. {
  4076. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  4077. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  4078. (defaultTxProfile.ChargingSchedule.Duration > 0))
  4079. {
  4080. if(maxProfile.ChargingProfileId != -1)
  4081. {
  4082. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4083. {
  4084. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  4085. {
  4086. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  4087. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  4088. if((maxProfile.ChargingSchedule.Duration > 0))
  4089. {
  4090. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  4091. }
  4092. else
  4093. {
  4094. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  4095. }
  4096. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  4097. {
  4098. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4099. {
  4100. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4101. compositePeriodIdx++;
  4102. }
  4103. else
  4104. {
  4105. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4106. }
  4107. }
  4108. // Delete duplicate period
  4109. if(compositePeriodIdx > 1)
  4110. {
  4111. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4112. {
  4113. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4114. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4115. compositePeriodIdx -= 1;
  4116. }
  4117. }
  4118. }
  4119. else
  4120. {
  4121. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4122. {
  4123. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4124. compositePeriodIdx++;
  4125. }
  4126. else
  4127. {
  4128. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4129. }
  4130. break;
  4131. }
  4132. }
  4133. }
  4134. else
  4135. {
  4136. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4137. {
  4138. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4139. compositePeriodIdx++;
  4140. }
  4141. else
  4142. {
  4143. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4144. }
  4145. }
  4146. }
  4147. }
  4148. }
  4149. // Fill other period by MaxProfile
  4150. if(maxProfile.ChargingProfileId != -1)
  4151. {
  4152. if(compositePeriodIdx==0)
  4153. {
  4154. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  4155. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  4156. {
  4157. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  4158. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  4159. (maxProfile.ChargingSchedule.Duration > 0))
  4160. {
  4161. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4162. {
  4163. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  4164. compositePeriodIdx++;
  4165. }
  4166. else
  4167. {
  4168. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  4169. }
  4170. }
  4171. }
  4172. }
  4173. else
  4174. {
  4175. int lastCompositePeriodIdx = compositePeriodIdx;
  4176. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4177. {
  4178. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  4179. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  4180. (maxProfile.ChargingSchedule.Duration > 0))
  4181. {
  4182. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  4183. {
  4184. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  4185. {
  4186. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  4187. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  4188. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  4189. }
  4190. else
  4191. {
  4192. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  4193. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  4194. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  4195. }
  4196. }
  4197. if(tmpPeriod.Limit != -1)
  4198. {
  4199. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  4200. {
  4201. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  4202. {
  4203. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4204. compositePeriodIdx++;
  4205. }
  4206. else
  4207. {
  4208. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4209. }
  4210. }
  4211. // Delete duplicate period
  4212. if(compositePeriodIdx > 1)
  4213. {
  4214. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4215. {
  4216. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4217. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4218. compositePeriodIdx -= 1;
  4219. }
  4220. }
  4221. }
  4222. }
  4223. }
  4224. }
  4225. }
  4226. if(compositeProfile.ChargingSchedule.Duration < durationReq)
  4227. {
  4228. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  4229. {
  4230. if((idxPeriod > 0) && (compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == 0 || compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1))
  4231. {
  4232. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = compositeProfile.ChargingSchedule.Duration;
  4233. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (isUnitA==TRUE)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:modelnameInfo.ratedPower;
  4234. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].NumberPhases;
  4235. DEBUG_INFO(">>> Adding startPeriod because the duration of the final schedule is shorter than requested duration.\n");
  4236. DEBUG_INFO("Add Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4237. DEBUG_INFO("Add Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  4238. DEBUG_INFO("Add Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4239. DEBUG_INFO("------------------------------------------------\n");
  4240. break;
  4241. }
  4242. }
  4243. }
  4244. compositeProfile.ChargingSchedule.Duration = durationReq;
  4245. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  4246. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  4247. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  4248. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  4249. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  4250. {
  4251. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4252. {
  4253. compositeProfile.ChargingProfileId = 1;
  4254. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4255. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  4256. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4257. }
  4258. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  4259. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  4260. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  4261. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  4262. }
  4263. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  4264. if(line)
  4265. free(line);
  4266. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  4267. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  4268. }
  4269. //==========================================
  4270. // Init all share memory
  4271. //==========================================
  4272. int InitShareMemory()
  4273. {
  4274. int result = PASS;
  4275. int MeterSMId;
  4276. //creat ShmSysConfigAndInfo
  4277. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  4278. {
  4279. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  4280. result = FAIL;
  4281. }
  4282. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4283. {
  4284. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  4285. result = FAIL;
  4286. }
  4287. else
  4288. {}
  4289. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  4290. {
  4291. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  4292. result = FAIL;
  4293. }
  4294. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4295. {
  4296. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  4297. result = FAIL;
  4298. }
  4299. else
  4300. {}
  4301. //creat ShmPsuData
  4302. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  4303. {
  4304. DEBUG_ERROR("shmget ShmPsuData NG\n");
  4305. result = FAIL;
  4306. }
  4307. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4308. {
  4309. DEBUG_ERROR("shmat ShmPsuData NG\n");
  4310. result = FAIL;
  4311. }
  4312. else
  4313. {}
  4314. //creat ShmOCPP16Data
  4315. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  4316. {
  4317. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  4318. result = FAIL;
  4319. }
  4320. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4321. {
  4322. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  4323. result = FAIL;
  4324. }
  4325. else
  4326. {}
  4327. /****************************** For Initial Settings************************************************/
  4328. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  4329. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  4330. // allocate Configuration memory address
  4331. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  4332. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  4333. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  4334. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  4335. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  4336. //offline MeterValue Interval
  4337. TempMeterValueInterval = 0;
  4338. return result;
  4339. }
  4340. int ProcessShareMemory()
  4341. {
  4342. int result = PASS;
  4343. if(InitShareMemory() == FAIL)
  4344. {
  4345. DEBUG_ERROR("InitShareMemory NG\n");
  4346. if(ShmStatusCodeData!=NULL)
  4347. {
  4348. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  4349. }
  4350. result = FAIL;
  4351. }
  4352. // Model name parsing
  4353. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  4354. {
  4355. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  4356. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  4357. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  4358. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  4359. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O') ||
  4360. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='L'))
  4361. ) // 'D' means DC
  4362. {
  4363. // DO series
  4364. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  4365. {
  4366. gunTotalNumber += 1;
  4367. gunType[gun_index] = GUN_TYPE_DO;
  4368. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4369. {
  4370. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  4371. {
  4372. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4373. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4374. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  4375. }
  4376. }
  4377. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4378. {
  4379. case Gun_Type_Chademo:
  4380. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  4381. break;
  4382. case Gun_Type_CCS_2:
  4383. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  4384. break;
  4385. case Gun_Type_GB:
  4386. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  4387. break;
  4388. case Gun_Type_AC:
  4389. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  4390. break;
  4391. default:
  4392. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  4393. break;
  4394. }
  4395. }
  4396. }
  4397. else
  4398. {
  4399. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  4400. {
  4401. gunTotalNumber += 1;
  4402. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4403. {
  4404. case Gun_Type_Chademo:
  4405. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  4406. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  4407. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  4408. {
  4409. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4410. {
  4411. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4412. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4413. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4414. }
  4415. }
  4416. break;
  4417. case Gun_Type_CCS_2:
  4418. gunType[gun_index] = GUN_TYPE_CCS;
  4419. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4420. for (int index = 0; index < CCS_QUANTITY; index++)
  4421. {
  4422. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4423. {
  4424. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4425. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4426. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4427. }
  4428. }
  4429. break;
  4430. case Gun_Type_GB:
  4431. gunType[gun_index] = GUN_TYPE_GBT;
  4432. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4433. for (int index = 0; index < GB_QUANTITY; index++)
  4434. {
  4435. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4436. {
  4437. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4438. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4439. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4440. }
  4441. }
  4442. break;
  4443. case Gun_Type_AC:
  4444. gunType[gun_index] = GUN_TYPE_AC;
  4445. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4446. for (int index = 0; index < AC_QUANTITY; index++)
  4447. {
  4448. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4449. {
  4450. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4451. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4452. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4453. }
  4454. }
  4455. break;
  4456. default:
  4457. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4458. break;
  4459. }
  4460. }
  4461. }
  4462. }
  4463. else
  4464. {
  4465. DEBUG_ERROR("Model name parsing fail.\n");
  4466. result = FAIL;
  4467. }
  4468. if(result != PASS)sleep(5);
  4469. return result;
  4470. }
  4471. void checkRemoteStart(uint8_t connectorIdInt)
  4472. {
  4473. uint8_t tempIndex;
  4474. int result = PASS;
  4475. char cmdBuf[512];
  4476. //check Transaction active
  4477. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4478. {
  4479. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4480. {
  4481. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4482. }
  4483. else
  4484. {
  4485. tempIndex = connectorIdInt -1;
  4486. }
  4487. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4488. {
  4489. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4490. {
  4491. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4492. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4493. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4494. {
  4495. //Reserved
  4496. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4497. }
  4498. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4499. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4500. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4501. {
  4502. //Reserved
  4503. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4504. result = FAIL;
  4505. goto end;
  4506. }
  4507. else
  4508. {
  4509. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4510. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4511. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4512. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4513. {
  4514. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4515. result = FAIL;
  4516. goto end;
  4517. }
  4518. }//END FOR ELSE
  4519. }
  4520. }// END FOR CHAdeMO_QUANTITY
  4521. }
  4522. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4523. {
  4524. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4525. {
  4526. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4527. }
  4528. else
  4529. {
  4530. tempIndex = connectorIdInt -1;
  4531. }
  4532. for (int index = 0; index < CCS_QUANTITY; index++)
  4533. {
  4534. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4535. {
  4536. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4537. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4538. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4539. {
  4540. //Reserved
  4541. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4542. }
  4543. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4544. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4545. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4546. {
  4547. //Reserved
  4548. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4549. result = FAIL;
  4550. goto end;
  4551. }
  4552. else
  4553. {
  4554. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4555. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4556. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4557. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4558. {
  4559. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4560. result = FAIL;
  4561. goto end;
  4562. }
  4563. }// END FOR ELSE
  4564. }
  4565. }// END FOR CCS_QUANTITY
  4566. }
  4567. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4568. {
  4569. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4570. {
  4571. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4572. }
  4573. else
  4574. {
  4575. tempIndex = connectorIdInt -1;
  4576. }
  4577. for (int index = 0; index < GB_QUANTITY; index++)
  4578. {
  4579. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4580. {
  4581. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4582. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4583. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4584. {
  4585. //Reserved
  4586. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4587. }
  4588. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4589. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4590. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4591. {
  4592. //Reserved
  4593. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4594. result = FAIL;
  4595. goto end;
  4596. }
  4597. else
  4598. {
  4599. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4600. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4601. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4602. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4603. {
  4604. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4605. result = FAIL;
  4606. goto end;
  4607. }
  4608. }// END FOR ELSE
  4609. }
  4610. } // END FOR GB_QUANTITY
  4611. }
  4612. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4613. {
  4614. tempIndex = connectorIdInt -1;
  4615. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4616. {
  4617. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4618. {
  4619. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4620. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4621. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4622. {
  4623. //Reserved
  4624. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4625. }
  4626. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4627. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4628. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4629. {
  4630. //Reserved
  4631. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4632. result = FAIL;
  4633. goto end;
  4634. }
  4635. else
  4636. {
  4637. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4638. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4639. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4640. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4641. {
  4642. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4643. result = FAIL;
  4644. goto end;
  4645. }
  4646. }// END FOR ELSE
  4647. }
  4648. } // END FOR GB_QUANTITY
  4649. }
  4650. else
  4651. {
  4652. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4653. {
  4654. tempIndex = 2;
  4655. }
  4656. else
  4657. {
  4658. tempIndex = connectorIdInt -1;
  4659. }
  4660. for (int index = 0; index < AC_QUANTITY; index++)
  4661. {
  4662. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4663. {
  4664. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4665. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4666. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4667. {
  4668. //Reserved
  4669. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4670. }
  4671. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4672. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4673. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4674. {
  4675. //Reserved
  4676. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4677. result = FAIL;
  4678. goto end;
  4679. }
  4680. else
  4681. {
  4682. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4683. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4684. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4685. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4686. {
  4687. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4688. result = FAIL;
  4689. goto end;
  4690. }
  4691. }//END FOR ELSE
  4692. }
  4693. }// END FOR AC_QUANTITY
  4694. }
  4695. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4696. {
  4697. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4698. {
  4699. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4700. {
  4701. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4702. system(cmdBuf);
  4703. }
  4704. }
  4705. else
  4706. {
  4707. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4708. result = FAIL;
  4709. }
  4710. }
  4711. end:
  4712. if(result == PASS)
  4713. {
  4714. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4715. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4716. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4717. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4718. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4719. }
  4720. }
  4721. int isConnector0Unavailable()
  4722. {
  4723. uint8_t result = YES;
  4724. uint8_t tempIndex;
  4725. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4726. {
  4727. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4728. {
  4729. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4730. {
  4731. tempIndex = ((gun_index==2) ? 1: 0);
  4732. }
  4733. else
  4734. {
  4735. tempIndex = gun_index;
  4736. }
  4737. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4738. {
  4739. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4740. {
  4741. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_BOOTING) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_MAINTAIN) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_DEBUG) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_UPDATE))
  4742. {
  4743. result = NO;
  4744. }
  4745. }
  4746. }
  4747. }
  4748. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4749. {
  4750. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4751. {
  4752. tempIndex = ((gun_index==2) ? 1: 0);
  4753. }
  4754. else
  4755. {
  4756. tempIndex = gun_index;
  4757. }
  4758. for (int index = 0; index < CCS_QUANTITY; index++)
  4759. {
  4760. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4761. {
  4762. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_BOOTING) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_MAINTAIN) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_DEBUG) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_UPDATE))
  4763. {
  4764. result = NO;
  4765. }
  4766. }
  4767. }
  4768. }
  4769. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4770. {
  4771. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4772. {
  4773. tempIndex = ((gun_index==2) ? 1: 0);
  4774. }
  4775. else
  4776. {
  4777. tempIndex = gun_index;
  4778. }
  4779. for (int index = 0; index < GB_QUANTITY; index++)
  4780. {
  4781. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4782. {
  4783. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_BOOTING) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_MAINTAIN) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_DEBUG) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_UPDATE))
  4784. {
  4785. result = NO;
  4786. }
  4787. }
  4788. }
  4789. }
  4790. else if(gunType[gun_index] == GUN_TYPE_DO)
  4791. {
  4792. tempIndex = gun_index;
  4793. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4794. {
  4795. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4796. {
  4797. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_BOOTING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_MAINTAIN) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_DEBUG) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_UPDATE))
  4798. {
  4799. result = NO;
  4800. }
  4801. }
  4802. }
  4803. }
  4804. else
  4805. {
  4806. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4807. {
  4808. tempIndex = 2;
  4809. }
  4810. else
  4811. {
  4812. tempIndex = gun_index;
  4813. }
  4814. for (int index = 0; index < AC_QUANTITY; index++)
  4815. {
  4816. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4817. {
  4818. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_BOOTING) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_MAINTAIN) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_DEBUG) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_UPDATE))
  4819. {
  4820. result = NO;
  4821. }
  4822. }
  4823. }// END
  4824. }
  4825. }
  4826. return result;
  4827. }
  4828. void CheckSystemValue(void)
  4829. {
  4830. char filenmae[100]={0};
  4831. char str[100]={0};
  4832. int tempIndex = 0;
  4833. //===============================
  4834. // send Heartbeat
  4835. //===============================
  4836. if((server_sign == TRUE) && (HeartBeatWaitTime > 0) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4837. {
  4838. //parameter for test
  4839. sendHeartbeatRequest(0);
  4840. //===========================
  4841. // Reset Waiting Time
  4842. //===========================
  4843. HeartBeatWithNOResponse += 1;
  4844. }
  4845. //===============================
  4846. // Tcci credit deduct report
  4847. //===============================
  4848. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4849. {
  4850. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4851. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4852. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4853. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4854. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4855. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4856. }
  4857. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[0].DataTransferReq != TRUE) && getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4858. {
  4859. OCPP_query_deduct_info();
  4860. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4861. }
  4862. if(ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq)
  4863. {
  4864. OCPP_insert_occupancyDeduct_info((char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.occupancySN, (char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.creditNo,
  4865. ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.deductResult, ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.amount,
  4866. (char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.approvalNo);
  4867. ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq = FALSE;
  4868. }
  4869. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[0].DataTransferReq != TRUE) && getDiffSecNow(clientTime.TcciQueryOccupancyDeduct) > 5)
  4870. {
  4871. OCPP_query_occupancyDeduct_info();
  4872. refreshStartTimer(&clientTime.TcciQueryOccupancyDeduct);
  4873. }
  4874. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4875. {
  4876. // ClockAlign MeterValue
  4877. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4878. {
  4879. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4880. {
  4881. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4882. {
  4883. tempIndex = ((gun_index==2) ? 1: 0);
  4884. }
  4885. else
  4886. {
  4887. tempIndex = gun_index;
  4888. }
  4889. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4890. {
  4891. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4892. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4893. {
  4894. reqClockAlignMeter[gun_index] = 1;
  4895. }
  4896. }// End for CHAdeMO
  4897. }
  4898. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4899. {
  4900. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4901. {
  4902. tempIndex = ((gun_index==2) ? 1: 0);
  4903. }
  4904. else
  4905. {
  4906. tempIndex = gun_index;
  4907. }
  4908. for (int index = 0; index < CCS_QUANTITY; index++)
  4909. {
  4910. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4911. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4912. {
  4913. reqClockAlignMeter[gun_index] = 1;
  4914. }
  4915. } // End for CCS
  4916. }
  4917. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4918. {
  4919. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4920. {
  4921. tempIndex = ((gun_index==2) ? 1: 0);
  4922. }
  4923. else
  4924. {
  4925. tempIndex = gun_index;
  4926. }
  4927. for (int index = 0; index < GB_QUANTITY; index++)
  4928. {
  4929. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4930. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4931. {
  4932. reqClockAlignMeter[gun_index] = 1;
  4933. }
  4934. }// End for GB
  4935. }
  4936. else if(gunType[gun_index] == GUN_TYPE_DO)
  4937. {
  4938. tempIndex = gun_index;
  4939. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4940. {
  4941. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4942. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4943. {
  4944. reqClockAlignMeter[gun_index] = 1;
  4945. }
  4946. }
  4947. }
  4948. else
  4949. {
  4950. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4951. {
  4952. tempIndex = 2;
  4953. }
  4954. else
  4955. {
  4956. tempIndex = gun_index;
  4957. }
  4958. for (int index = 0; index < AC_QUANTITY; index++)
  4959. {
  4960. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4961. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4962. {
  4963. reqClockAlignMeter[gun_index] = 1;
  4964. }
  4965. }//End for AC
  4966. }
  4967. }
  4968. }
  4969. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4970. {
  4971. //==========================================
  4972. // Check remote start without connector id
  4973. //==========================================
  4974. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4975. {
  4976. int connectorIdInt = -1;
  4977. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4978. {
  4979. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4980. {
  4981. connectorIdInt = (gun_index+1);
  4982. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4983. checkRemoteStart(connectorIdInt);
  4984. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4985. break;
  4986. }
  4987. }
  4988. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4989. {
  4990. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4991. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4992. }
  4993. }
  4994. //==========================================
  4995. // csu trigger DataTransferReq
  4996. //==========================================
  4997. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4998. {
  4999. sendDataTransferRequest(gun_index);
  5000. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  5001. }
  5002. //==========================================
  5003. // CSU Trigger Authorize Request
  5004. //==========================================
  5005. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  5006. {
  5007. sendAuthorizeRequest(0);
  5008. authorizeRetryTimes = authorizeRetryTimes + 1;
  5009. if(authorizeRetryTimes < 3)
  5010. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5011. }
  5012. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  5013. {
  5014. authorizeRetryTimes = 0;
  5015. SetOcppConnStatus(FALSE);
  5016. server_sign = FALSE;
  5017. }
  5018. else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  5019. {
  5020. sendAuthorizeRequest(0);
  5021. }
  5022. //==========================================
  5023. // Charger start transaction
  5024. //==========================================
  5025. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  5026. {
  5027. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  5028. meterValueBufferClear(gun_index);
  5029. sendStartTransactionRequest(gun_index);
  5030. refreshStartTimer(&clientTime.StartTransaction);
  5031. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5032. storeTempStopTransaction(gun_index);
  5033. }
  5034. //==========================================
  5035. // Charger stop transaction
  5036. //==========================================
  5037. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  5038. {
  5039. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5040. sendStopTransactionRequest(gun_index);
  5041. OCPP_updatePeriodEnergy(gun_index);
  5042. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  5043. refreshStartTimer(&clientTime.StopTransaction);
  5044. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  5045. }
  5046. //==========================================
  5047. // Charger OCMF message
  5048. //==========================================
  5049. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq == 1)))
  5050. {
  5051. sendOcmfByDataTransferRequest(gun_index);
  5052. ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq = 0;
  5053. }
  5054. //==========================================
  5055. // Charger status report
  5056. //==========================================
  5057. //--- Check Mode Change ---//
  5058. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5059. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5060. {
  5061. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5062. {
  5063. tempIndex = ((gun_index==2) ? 1: 0);
  5064. }
  5065. else
  5066. {
  5067. tempIndex = gun_index;
  5068. }
  5069. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5070. {
  5071. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5072. {
  5073. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  5074. {
  5075. // Sent unplug message for California pricing logic
  5076. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "TRUE") == 0) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  5077. {
  5078. uint8_t ts[36];
  5079. getNowDatetime(ts);
  5080. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5081. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5082. if(strcmp((char*)dmsVersion, "2.0")==0)
  5083. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5084. else
  5085. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5086. sendUnplugByDataTransferRequest(gun_index);
  5087. interLock.isSentUnplug[gun_index] = 1;
  5088. }
  5089. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5090. {
  5091. interLock.isSentUnplug[gun_index] = 0;
  5092. }
  5093. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  5094. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  5095. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5096. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5097. {
  5098. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5099. if((access(filenmae,F_OK))!=-1)
  5100. {
  5101. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5102. sprintf(str,"rm -f %s",filenmae);
  5103. system(str);
  5104. }
  5105. }
  5106. }
  5107. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5108. #if 1 // for TempStopTransaction
  5109. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5110. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5111. {
  5112. checkTempStopTransaction(gun_index);
  5113. }
  5114. #endif
  5115. }
  5116. }
  5117. }
  5118. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5119. {
  5120. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5121. {
  5122. tempIndex = ((gun_index==2) ? 1: 0);
  5123. }
  5124. else
  5125. {
  5126. tempIndex = gun_index;
  5127. }
  5128. for (int index = 0; index < CCS_QUANTITY; index++)
  5129. {
  5130. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5131. {
  5132. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  5133. {
  5134. // Sent unplug message for California pricing logic
  5135. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "TRUE") == 0) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  5136. {
  5137. uint8_t ts[36];
  5138. getNowDatetime(ts);
  5139. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5140. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5141. if(strcmp((char*)dmsVersion, "2.0")==0)
  5142. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5143. else
  5144. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5145. sendUnplugByDataTransferRequest(gun_index);
  5146. interLock.isSentUnplug[gun_index] = 1;
  5147. }
  5148. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5149. {
  5150. interLock.isSentUnplug[gun_index] = 0;
  5151. }
  5152. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  5153. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  5154. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5155. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5156. {
  5157. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5158. if((access(filenmae,F_OK))!=-1)
  5159. {
  5160. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5161. sprintf(str,"rm -f %s",filenmae);
  5162. system(str);
  5163. }
  5164. }
  5165. }
  5166. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5167. #if 1 // for TempStopTransaction
  5168. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5169. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5170. {
  5171. checkTempStopTransaction(gun_index);
  5172. }
  5173. #endif
  5174. }
  5175. }
  5176. }
  5177. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5178. {
  5179. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5180. {
  5181. tempIndex = ((gun_index==2) ? 1: 0);
  5182. }
  5183. else
  5184. {
  5185. tempIndex = gun_index;
  5186. }
  5187. for (int index = 0; index < GB_QUANTITY; index++)
  5188. {
  5189. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5190. {
  5191. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  5192. {
  5193. // Sent unplug message for California pricing logic
  5194. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "TRUE") == 0) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  5195. {
  5196. uint8_t ts[36];
  5197. getNowDatetime(ts);
  5198. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5199. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5200. if(strcmp((char*)dmsVersion, "2.0")==0)
  5201. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5202. else
  5203. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5204. sendUnplugByDataTransferRequest(gun_index);
  5205. interLock.isSentUnplug[gun_index] = 1;
  5206. }
  5207. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5208. {
  5209. interLock.isSentUnplug[gun_index] = 0;
  5210. }
  5211. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  5212. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  5213. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5214. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5215. {
  5216. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5217. if((access(filenmae,F_OK))!=-1)
  5218. {
  5219. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5220. sprintf(str,"rm -f %s",filenmae);
  5221. system(str);
  5222. }
  5223. }
  5224. }
  5225. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5226. #if 1 // for TempStopTransaction
  5227. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5228. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5229. {
  5230. checkTempStopTransaction(gun_index);
  5231. }
  5232. #endif
  5233. }
  5234. }
  5235. }
  5236. else if(gunType[gun_index] == GUN_TYPE_DO)
  5237. {
  5238. tempIndex = gun_index;
  5239. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5240. {
  5241. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5242. {
  5243. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  5244. {
  5245. // Sent unplug message for California pricing logic
  5246. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "TRUE") == 0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0) && !interLock.isSentUnplug[gun_index])
  5247. {
  5248. uint8_t ts[36];
  5249. getNowDatetime(ts);
  5250. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5251. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5252. if(strcmp((char*)dmsVersion, "2.0")==0)
  5253. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5254. else
  5255. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5256. sendUnplugByDataTransferRequest(gun_index);
  5257. interLock.isSentUnplug[gun_index] = 1;
  5258. }
  5259. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  5260. {
  5261. interLock.isSentUnplug[gun_index] = 0;
  5262. }
  5263. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  5264. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  5265. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5266. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_IDLE))) // complete
  5267. {
  5268. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5269. if((access(filenmae,F_OK))!=-1)
  5270. {
  5271. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5272. sprintf(str,"rm -f %s",filenmae);
  5273. system(str);
  5274. }
  5275. }
  5276. }
  5277. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5278. #if 1 // for TempStopTransaction
  5279. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  5280. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5281. {
  5282. checkTempStopTransaction(gun_index);
  5283. }
  5284. #endif
  5285. }
  5286. }
  5287. }
  5288. else
  5289. {
  5290. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5291. {
  5292. tempIndex = 2;
  5293. }
  5294. else
  5295. {
  5296. tempIndex = gun_index;
  5297. }
  5298. for (int index = 0; index < AC_QUANTITY; index++)
  5299. {
  5300. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5301. {
  5302. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  5303. {
  5304. // Sent unplug message for California pricing logic
  5305. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "TRUE") == 0) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A) && !interLock.isSentUnplug[gun_index])
  5306. {
  5307. uint8_t ts[36];
  5308. getNowDatetime(ts);
  5309. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5310. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5311. if(strcmp((char*)dmsVersion, "2.0")==0)
  5312. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5313. else
  5314. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5315. sendUnplugByDataTransferRequest(gun_index);
  5316. interLock.isSentUnplug[gun_index] = 1;
  5317. }
  5318. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5319. {
  5320. interLock.isSentUnplug[gun_index] = 0;
  5321. }
  5322. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  5323. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  5324. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5325. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5326. {
  5327. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5328. if((access(filenmae,F_OK))!=-1)
  5329. {
  5330. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5331. sprintf(str,"rm -f %s",filenmae);
  5332. system(str);
  5333. }
  5334. }
  5335. }
  5336. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5337. #if 1 // for TempStopTransaction
  5338. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5339. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5340. {
  5341. checkTempStopTransaction(gun_index);
  5342. }
  5343. #endif
  5344. }
  5345. }// END
  5346. }
  5347. if(isWebsocketSendable && (server_sign == TRUE) && (isConnector0Unavailable() != Connector0PreviousSystemStatus))
  5348. {
  5349. sendConnector0StatusNotificationRequest();
  5350. Connector0PreviousSystemStatus = isConnector0Unavailable();
  5351. }
  5352. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf != 1) &&
  5353. (
  5354. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  5355. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  5356. )
  5357. )
  5358. {
  5359. sendStatusNotificationRequest(gun_index);
  5360. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  5361. }
  5362. //==============================================
  5363. // TCCI related DataTransfer messages
  5364. //==============================================
  5365. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  5366. {
  5367. reportReaderStatus(gun_index);
  5368. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  5369. }
  5370. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].OccupancyFeeActReq == 1))
  5371. {
  5372. occupancyFeeAct(gun_index);
  5373. }
  5374. //==============================================
  5375. // CSU Trigger or timer timeout refresh Smart Charging Profile
  5376. //==============================================
  5377. if((ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  5378. ((cpinitateMsg.bits[gun_index].isOnCharging) && (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData) > 0) && (getDiffSecNow(clientTime.CharingProfileRefresh[gun_index]) > atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData))))
  5379. {
  5380. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  5381. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  5382. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  5383. }
  5384. //==============================================
  5385. // Meter report
  5386. //==============================================
  5387. // Trigger MeterValue
  5388. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  5389. {
  5390. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  5391. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  5392. }
  5393. // Clock-aligned Meter value
  5394. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  5395. {
  5396. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  5397. reqClockAlignMeter[gun_index] = 0;
  5398. }
  5399. // Sample period MeterValue
  5400. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>3?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):3))))
  5401. {
  5402. //check Transaction active
  5403. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5404. {
  5405. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5406. {
  5407. tempIndex = ((gun_index==2) ? 1: 0);
  5408. }
  5409. else
  5410. {
  5411. tempIndex = gun_index;
  5412. }
  5413. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5414. {
  5415. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5416. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5417. {
  5418. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5419. {
  5420. reqSampleMeter[gun_index] = 1;
  5421. }
  5422. }
  5423. }// End for CHAdeMO
  5424. }
  5425. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5426. {
  5427. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5428. {
  5429. tempIndex = ((gun_index==2) ? 1: 0);
  5430. }
  5431. else
  5432. {
  5433. tempIndex = gun_index;
  5434. }
  5435. for (int index = 0; index < CCS_QUANTITY; index++)
  5436. {
  5437. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5438. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5439. {
  5440. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5441. {
  5442. reqSampleMeter[gun_index] = 1;
  5443. }
  5444. }
  5445. } // End for CCS
  5446. }
  5447. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5448. {
  5449. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5450. {
  5451. tempIndex = ((gun_index==2) ? 1: 0);
  5452. }
  5453. else
  5454. {
  5455. tempIndex = gun_index;
  5456. }
  5457. for (int index = 0; index < GB_QUANTITY; index++)
  5458. {
  5459. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5460. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5461. {
  5462. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5463. {
  5464. reqSampleMeter[gun_index] = 1;
  5465. }
  5466. }
  5467. }// End for GB
  5468. }
  5469. else if(gunType[gun_index] == GUN_TYPE_DO)
  5470. {
  5471. tempIndex = gun_index;
  5472. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5473. {
  5474. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5475. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5476. {
  5477. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  5478. {
  5479. reqSampleMeter[gun_index] = 1;
  5480. }
  5481. }
  5482. }
  5483. }
  5484. else
  5485. {
  5486. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5487. {
  5488. tempIndex = 2;
  5489. }
  5490. else
  5491. {
  5492. tempIndex = gun_index;
  5493. }
  5494. for (int index = 0; index < AC_QUANTITY; index++)
  5495. {
  5496. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5497. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5498. {
  5499. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  5500. {
  5501. reqSampleMeter[gun_index] = 1;
  5502. }
  5503. }
  5504. }//End for AC
  5505. }
  5506. if(reqSampleMeter[gun_index] == 1)
  5507. {
  5508. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  5509. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  5510. storeTempStopTransaction(gun_index);
  5511. reqSampleMeter[gun_index] = 0;
  5512. }
  5513. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5514. }
  5515. //==============================================
  5516. // Check Connector reserved
  5517. //==============================================
  5518. //===============================
  5519. // Check if Reserve is expired
  5520. //===============================
  5521. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  5522. {
  5523. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  5524. {
  5525. DEBUG_INFO("reserve expired.\n");
  5526. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  5527. }
  5528. }//END OF Check if Reserve is expired
  5529. //==========================================
  5530. // csu trigger FirmwareStatusNotificationReq
  5531. //==========================================
  5532. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  5533. {
  5534. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  5535. }
  5536. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq == 1))
  5537. {
  5538. sendSignedFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status);
  5539. }
  5540. //==========================================
  5541. // csu trigger DiagnosticsStatusNotificationReq
  5542. //==========================================
  5543. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  5544. {
  5545. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  5546. }
  5547. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq == 1))
  5548. {
  5549. sendLogStatusNotificationRequest((char *)ShmOCPP16Data->LogStatusNotification.status);
  5550. }
  5551. //==========================================
  5552. // csu trigger CancelReservationConf
  5553. //==========================================
  5554. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  5555. {
  5556. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  5557. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  5558. }
  5559. //==========================================
  5560. // csu trigger ChangeAvailabilityConf
  5561. //==========================================
  5562. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  5563. {
  5564. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  5565. }
  5566. //==========================================
  5567. // csu trigger UnlockConnectorConf
  5568. //==========================================
  5569. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  5570. {
  5571. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5572. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5573. }
  5574. //==========================================
  5575. // csu trigger ReserveNowConf
  5576. //==========================================
  5577. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5578. {
  5579. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5580. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5581. }
  5582. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access(CSR_CP,F_OK) != -1))
  5583. {
  5584. sendSignCertificateRequest();
  5585. }
  5586. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq == 1))
  5587. {
  5588. sendSecurityEventNotificationRequest();
  5589. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5590. }
  5591. // Support 15118
  5592. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.SignCertificateReq == 1) && (access(CSR_V2G,F_OK) != -1))
  5593. {
  5594. json_object *data = json_object_new_object();
  5595. // Read csr file content
  5596. memset(ShmOCPP16Data->v2g_extend.SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5597. FILE *fp=fopen(CSR_V2G,"r");
  5598. char *line = NULL;
  5599. size_t len = 0;
  5600. while(getline(&line, &len, fp) != -1)
  5601. {
  5602. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5603. {
  5604. memcpy(&ShmOCPP16Data->v2g_extend.SignCertificate.csr[strlen((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr)], line, (strlen(line)-1));
  5605. }
  5606. }
  5607. fclose(fp);
  5608. json_object_object_add(data, "csr", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5609. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5610. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"SignCertificate");
  5611. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5612. json_object_put(data);
  5613. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5614. ShmOCPP16Data->v2g_extend.SignCertificateReq = 0;
  5615. }
  5616. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.AuthorizeReq == 1))
  5617. {
  5618. memset(&ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo,0,sizeof(struct IdTokenInfoType));
  5619. int parseCertResult = FAIL;
  5620. json_object *data = json_object_new_object();
  5621. json_object *idToken = json_object_new_object();
  5622. json_object *iso15118CertificateHashData = json_object_new_array();
  5623. // Read CERTIFICATE_PnCAuth file content
  5624. if(access(CERTIFICATE_PnCAuth,F_OK) != -1)
  5625. {
  5626. memset(ShmOCPP16Data->v2g_extend.Authorize.certificate, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5627. FILE *fp=fopen(CERTIFICATE_PnCAuth,"r");
  5628. char *line = NULL;
  5629. size_t len = 0;
  5630. while(getline(&line, &len, fp) != -1)
  5631. {
  5632. //memcpy(&ShmOCPP16Data->v2g_extend.Authorize.certificate[strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate)], line, (strlen(line)-1));
  5633. strcat((char *)ShmOCPP16Data->v2g_extend.Authorize.certificate, line);
  5634. }
  5635. fclose(fp);
  5636. }
  5637. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate) > 0)
  5638. json_object_object_add(data, "certificate", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5639. //strcpy((char *)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5640. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken));
  5641. json_object_object_add(data, "idToken", idToken);
  5642. char parseData[512] = {0};
  5643. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  5644. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].hashAlgorithm, parseData);
  5645. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_SerialNumber, parseData) == PASS)
  5646. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].serialNumber, parseData);
  5647. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  5648. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerNameHash, parseData);
  5649. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  5650. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerKeyHash, parseData);
  5651. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_OcspUrl, parseData) == PASS && strlen((char*)parseData) >= 7)
  5652. strcpy((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].responderURL, parseData);
  5653. for(int idx=0; idx < 4; idx++)
  5654. {
  5655. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm) > 0)
  5656. {
  5657. json_object *OCSPRequestDataType = json_object_new_object();
  5658. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm));
  5659. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerNameHash));
  5660. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerKeyHash));
  5661. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].serialNumber));
  5662. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].responderURL));
  5663. json_object_array_add(iso15118CertificateHashData, OCSPRequestDataType);
  5664. parseCertResult = PASS;
  5665. }
  5666. }
  5667. if(parseCertResult == PASS)
  5668. {
  5669. json_object_object_add(data, "iso15118CertificateHashData", iso15118CertificateHashData);
  5670. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5671. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Authorize");
  5672. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5673. json_object_put(data);
  5674. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5675. ShmOCPP16Data->v2g_extend.AuthorizeReq = 0;
  5676. }
  5677. else
  5678. {
  5679. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "NoCertificateAvailable");
  5680. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.status, "Invalid");
  5681. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  5682. }
  5683. }
  5684. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq == 1))
  5685. {
  5686. json_object *data = json_object_new_object();
  5687. json_object_object_add(data, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.iso15118SchemaVersion));
  5688. json_object_object_add(data, "action", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.action));
  5689. json_object_object_add(data, "exiRequest", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.exiRequest));
  5690. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5691. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Get15118EVCertificate");
  5692. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5693. json_object_put(data);
  5694. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5695. ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq = 0;
  5696. }
  5697. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.GetCertificateStatusReq == 1))
  5698. {
  5699. json_object *data = json_object_new_object();
  5700. json_object *OCSPRequestDataType = json_object_new_object();
  5701. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.hashAlgorithm));
  5702. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerNameHash));
  5703. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerKeyHash));
  5704. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.serialNumber));
  5705. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.responderURL));
  5706. json_object_object_add(data, "ocspRequestData", OCSPRequestDataType);
  5707. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5708. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"GetInstalledCertificateIds");
  5709. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5710. json_object_put(data);
  5711. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5712. ShmOCPP16Data->v2g_extend.GetCertificateStatusReq = 0;
  5713. }
  5714. }
  5715. }
  5716. //==========================================
  5717. // send request routine
  5718. //==========================================
  5719. int sendAuthorizeRequest(int gun_index)
  5720. {
  5721. mtrace();
  5722. int result = FAIL;
  5723. char message[100]={0};
  5724. char guid[37];
  5725. char tempdata[65]={0};
  5726. DEBUG_INFO("sendAuthorizeRequest...\n");
  5727. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5728. //Local Authorize
  5729. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5730. {
  5731. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5732. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5733. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5734. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5735. result = PASS;
  5736. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5737. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5738. authorizeRetryTimes = 0;
  5739. return result;
  5740. }
  5741. else if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||
  5742. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5743. {
  5744. // Query from cache
  5745. DEBUG_INFO("Authorize from cache.\n");
  5746. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5747. // Query from list
  5748. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strstr(idTagQuery.idTagstatus,"Accepted") == NULL) )
  5749. {
  5750. DEBUG_INFO("Authorize from list.\n");
  5751. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5752. }
  5753. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strstr(idTagQuery.idTagstatus,"Accepted") == NULL) )
  5754. {
  5755. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5756. {
  5757. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5758. }
  5759. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5760. {
  5761. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5762. }
  5763. if(!GetOcppConnStatus())
  5764. {
  5765. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5766. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5767. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5768. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5769. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5770. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5771. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5772. authorizeRetryTimes = 0;
  5773. return result;
  5774. }
  5775. }
  5776. else
  5777. {
  5778. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5779. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5780. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5781. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5782. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5783. else
  5784. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5785. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5786. result = PASS;
  5787. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5788. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5789. authorizeRetryTimes = 0;
  5790. return result;
  5791. }
  5792. }
  5793. //initialize struct Authorize
  5794. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5795. //get data from shared memory
  5796. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5797. random_uuid(guid);
  5798. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5799. LWS_Send(message);
  5800. sprintf(tempdata, "Authorize,%d", gun_index);
  5801. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5802. {
  5803. result = PASS;
  5804. DEBUG_INFO("Authorize mapItem pass\n");
  5805. }
  5806. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5807. return result;
  5808. }
  5809. int sendBootNotificationRequest(void)
  5810. {
  5811. mtrace();
  5812. int result = FAIL;
  5813. char message[500]={0}, payload[700]={0};
  5814. char guid[37]={0};
  5815. char tempdata[65]={0};
  5816. // Fill BootNotification fields
  5817. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5818. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5819. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5820. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5821. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5822. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5823. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5824. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5825. ShmOCPP16Data->ChargeBoxId
  5826. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5827. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5828. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5829. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5830. ,ShmOCPP16Data->BootNotification.CpIccid
  5831. ,ShmOCPP16Data->BootNotification.CpImsi);
  5832. random_uuid(guid);
  5833. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5834. LWS_Send(message);
  5835. sprintf(tempdata, "BootNotification,0");
  5836. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid,mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  5837. {
  5838. result = PASS;
  5839. }
  5840. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5841. strcpy(queuedata,message);
  5842. return result;
  5843. }
  5844. int sendDataTransferRequest(int gun_index)
  5845. {
  5846. mtrace();
  5847. char message[10240]={0};
  5848. char guid[37]={0};
  5849. char tempdata[65]={0};
  5850. int result = FAIL;
  5851. json_object *DataTransfer = json_object_new_object();
  5852. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5853. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5854. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].Data));
  5855. random_uuid(guid);
  5856. sprintf(message,"[%d,\"%s\",\"DataTransfer\",%s]", MESSAGE_TYPE_CALL,
  5857. guid,
  5858. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5859. json_object_put(DataTransfer);
  5860. LWS_Send(message);
  5861. sprintf(tempdata, "DataTransfer,%d", gun_index);
  5862. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5863. {
  5864. result = PASS;
  5865. DEBUG_INFO("DataTransfer mapItem pass\n");
  5866. }
  5867. return result;
  5868. }
  5869. int sendUnplugByDataTransferRequest(int gun_index)
  5870. {
  5871. mtrace();
  5872. char message[10752]={0};
  5873. char guid[37]={0};
  5874. char tempdata[65]={0};
  5875. int result = FAIL;
  5876. random_uuid(guid);
  5877. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5878. (gun_index+1),
  5879. MESSAGE_TYPE_CALL,
  5880. guid,
  5881. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5882. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5883. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5884. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5885. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5886. {
  5887. result = PASS;
  5888. DEBUG_INFO("DataTransfer mapItem pass\n");
  5889. }
  5890. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5891. return result;
  5892. }
  5893. int sendOcmfByDataTransferRequest(int gun_index)
  5894. {
  5895. mtrace();
  5896. json_object *DataTransfer = json_object_new_object();
  5897. json_object *data = json_object_new_object();
  5898. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5899. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ID_OCMF");
  5900. json_object_object_add(data, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  5901. json_object_object_add(data, "dataString", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].DataString));
  5902. json_object_object_add(data, "publicKey", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].PublicKey));
  5903. json_object_object_add(DataTransfer, "data", data);
  5904. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5905. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5906. char message[3000]={0};
  5907. char guid[37]={0};
  5908. char tempdata[65]={0};
  5909. int result = FAIL;
  5910. random_uuid(guid);
  5911. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",%s]",
  5912. (gun_index+1),
  5913. MESSAGE_TYPE_CALL,
  5914. guid,
  5915. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5916. json_object_put(DataTransfer);
  5917. sprintf(tempdata, "DataTransfer,%d", gun_index );
  5918. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5919. {
  5920. result = PASS;
  5921. DEBUG_INFO("DataTransfer mapItem pass\n");
  5922. }
  5923. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5924. return result;
  5925. }
  5926. int sendDiagnosticsStatusNotificationRequest(char *status)
  5927. {
  5928. mtrace();
  5929. int result = FAIL;
  5930. char message[110]={0};
  5931. char guid[37]={0};
  5932. char tempdata[65]={0};
  5933. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5934. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5935. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5936. random_uuid(guid);
  5937. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5938. LWS_SendNow(message);
  5939. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5940. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5941. {
  5942. result = PASS;
  5943. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5944. }
  5945. //#ifdef SystemLogMessage
  5946. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5947. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5948. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5949. //#endif
  5950. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5951. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5952. //record status
  5953. if(strcmp(status,"Idle")==0)
  5954. {
  5955. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5956. }
  5957. else if(strcmp(status,"Uploaded")==0)
  5958. {
  5959. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5960. }
  5961. else if(strcmp(status,"UploadFailed")==0)
  5962. {
  5963. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5964. }
  5965. else if(strcmp(status,"Uploading")==0)
  5966. {
  5967. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5968. }
  5969. return result;
  5970. }
  5971. int sendFirmwareStatusNotificationRequest(char *status)
  5972. {
  5973. mtrace();
  5974. int result = FAIL;
  5975. char message[110]={0};
  5976. char guid[37]={0};
  5977. char tempdata[65]={0};
  5978. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5979. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5980. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5981. random_uuid(guid);
  5982. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5983. LWS_SendNow(message);
  5984. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5985. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  5986. {
  5987. result = PASS;
  5988. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5989. }
  5990. //#ifdef SystemLogMessage
  5991. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5992. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5993. //#endif
  5994. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5995. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5996. //record status
  5997. if(strcmp(status,"Downloaded")==0)
  5998. {
  5999. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  6000. }
  6001. else if(strcmp(status,"DownloadFailed")==0)
  6002. {
  6003. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  6004. }
  6005. else if(strcmp(status,"Downloading")==0)
  6006. {
  6007. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  6008. }
  6009. else if(strcmp(status,"Idle")==0)
  6010. {
  6011. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  6012. }
  6013. else if(strcmp(status,"InstallationFailed")==0)
  6014. {
  6015. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  6016. }
  6017. else if(strcmp(status,"Installing")==0)
  6018. {
  6019. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  6020. }
  6021. else if(strcmp(status,"Installed")==0)
  6022. {
  6023. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  6024. }
  6025. return result;
  6026. }
  6027. int sendHeartbeatRequest(int gun_index)
  6028. {
  6029. mtrace();
  6030. int result = FAIL;
  6031. char message[80]={0};
  6032. char guid[37]={0};
  6033. char tempdata[65]={0};
  6034. random_uuid(guid);
  6035. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  6036. , MESSAGE_TYPE_CALL
  6037. , guid );
  6038. LWS_Send(message);
  6039. sprintf(tempdata, "Heartbeat,%d", 0);
  6040. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  6041. {
  6042. result = PASS;
  6043. }
  6044. return result;
  6045. }
  6046. int sendStartTransactionRequest(int gun_index)
  6047. {
  6048. mtrace();
  6049. int result = FAIL;
  6050. char message[250]={0};
  6051. char guid[37]={0};
  6052. struct timeval tmnow;
  6053. struct tm *tm;
  6054. char buf[28];//, usec_buf[6];
  6055. char tempdata[65]={0};
  6056. int tempIndex = 0;
  6057. DEBUG_INFO("sendStartTransactionRequest...\n");
  6058. gettimeofday(&tmnow, NULL);
  6059. time_t t;
  6060. t = time(NULL);
  6061. /*UTC time and date*/
  6062. tm = gmtime(&t);
  6063. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6064. #if 0 // remove temporally
  6065. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  6066. strcat(buf,".");
  6067. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  6068. strcat(buf,usec_buf);
  6069. #endif
  6070. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  6071. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  6072. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  6073. // clear StartTransaction Response
  6074. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  6075. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  6076. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  6077. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  6078. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  6079. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6080. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6081. {
  6082. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6083. {
  6084. tempIndex = ((gun_index==2) ? 1: 0);
  6085. }
  6086. else
  6087. {
  6088. tempIndex = gun_index;
  6089. }
  6090. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6091. {
  6092. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6093. {
  6094. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6095. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  6096. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6097. }
  6098. }
  6099. }
  6100. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6101. {
  6102. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6103. {
  6104. tempIndex = ((gun_index==2) ? 1: 0);
  6105. }
  6106. else
  6107. {
  6108. tempIndex = gun_index;
  6109. }
  6110. for (int index = 0; index < CCS_QUANTITY; index++)
  6111. {
  6112. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6113. {
  6114. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6115. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  6116. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6117. }
  6118. }
  6119. }
  6120. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6121. {
  6122. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6123. {
  6124. tempIndex = ((gun_index==2) ? 1: 0);
  6125. }
  6126. else
  6127. {
  6128. tempIndex = gun_index;
  6129. }
  6130. for (int index = 0; index < GB_QUANTITY; index++)
  6131. {
  6132. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6133. {
  6134. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6135. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  6136. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6137. }
  6138. }
  6139. }
  6140. else if(gunType[gun_index] == GUN_TYPE_DO)
  6141. {
  6142. tempIndex = gun_index;
  6143. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6144. {
  6145. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6146. {
  6147. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6148. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  6149. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6150. }
  6151. }
  6152. }
  6153. else
  6154. {
  6155. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6156. {
  6157. tempIndex = 2;
  6158. }
  6159. else
  6160. {
  6161. tempIndex = gun_index;
  6162. }
  6163. for (int index = 0; index < AC_QUANTITY; index++)
  6164. {
  6165. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6166. {
  6167. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6168. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  6169. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6170. }
  6171. }
  6172. }
  6173. random_uuid(guid);
  6174. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  6175. {
  6176. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  6177. , gun_index +1
  6178. , MESSAGE_TYPE_CALL
  6179. , guid
  6180. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  6181. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  6182. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  6183. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  6184. }
  6185. else
  6186. {
  6187. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  6188. , gun_index +1
  6189. , MESSAGE_TYPE_CALL
  6190. , guid
  6191. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  6192. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  6193. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  6194. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  6195. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  6196. }
  6197. #if 1
  6198. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  6199. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  6200. {
  6201. result = PASS;
  6202. }
  6203. #endif
  6204. strcpy(queuedata, message);
  6205. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6206. OCPP_insert_transaction_msg(YES, queuedata);
  6207. return result;
  6208. }
  6209. int sendConnector0StatusNotificationRequest()
  6210. {
  6211. mtrace();
  6212. int result = FAIL;
  6213. char message[600]={0};
  6214. char guid[37];
  6215. struct timeval tmnow;
  6216. struct tm *tm;
  6217. char buf[28];//, usec_buf[6];
  6218. char tempdata[65]={0};
  6219. DEBUG_INFO("sendConnector0StatusNotificationRequest...\n");
  6220. gettimeofday(&tmnow, NULL);
  6221. time_t t;
  6222. t = time(NULL);
  6223. /*UTC time and date*/
  6224. tm = gmtime(&t);
  6225. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6226. random_uuid(guid);
  6227. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":0,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6228. , MESSAGE_TYPE_CALL
  6229. , guid
  6230. , "NoError"
  6231. , ""
  6232. , (isConnector0Unavailable()==YES?"Unavailable":"Available")
  6233. , buf
  6234. , ShmSysConfigAndInfo->SysConfig.chargePointVendor
  6235. , "");
  6236. LWS_Send(message);
  6237. sprintf(tempdata, "StatusNotification,%d", 99);
  6238. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  6239. {
  6240. //DEBUG_ERROR("statusNotification mapitem pass");
  6241. result = PASS;
  6242. }
  6243. return result;
  6244. }
  6245. int sendStatusNotificationRequest(int gun_index)
  6246. {
  6247. mtrace();
  6248. int result = FAIL;
  6249. char message[600]={0};
  6250. char guid[37];
  6251. int currentStatus = 0;
  6252. struct timeval tmnow;
  6253. struct tm *tm;
  6254. char buf[28];//, usec_buf[6];
  6255. char tempdata[65]={0};
  6256. int tempIndex = 0;
  6257. uint8_t isStateChanged = TRUE;
  6258. uint8_t isContentIllegal = TRUE;
  6259. DEBUG_INFO("sendStatusNotificationRequest...\n");
  6260. gettimeofday(&tmnow, NULL);
  6261. time_t t;
  6262. t = time(NULL);
  6263. /*UTC time and date*/
  6264. tm = gmtime(&t);
  6265. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6266. #if 0 // remove temporally
  6267. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  6268. strcat(buf,".");
  6269. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  6270. strcat(buf,usec_buf);
  6271. #endif
  6272. //printf("%s",buf);
  6273. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  6274. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  6275. // it's option
  6276. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  6277. /*
  6278. enum _SYSTEM_STATUS
  6279. {
  6280. S_BOOTING = 0,
  6281. S_IDLE, = 1
  6282. S_AUTHORIZING, =2
  6283. S_REASSIGN_CHECK, =3
  6284. S_REASSIGN, =4
  6285. S_PRECHARGE, =5
  6286. S_PREPARING_FOR_EV, =6
  6287. S_PREPARING_FOR_EVSE, =7
  6288. S_CHARGING, =8
  6289. S_TERMINATING, =9
  6290. S_COMPLETE, =10
  6291. S_ALARM, =11
  6292. S_FAULT =12
  6293. }
  6294. */
  6295. //check Transaction active
  6296. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6297. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6298. {
  6299. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6300. {
  6301. tempIndex = ((gun_index==2) ? 1: 0);
  6302. }
  6303. else
  6304. {
  6305. tempIndex = gun_index;
  6306. }
  6307. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6308. {
  6309. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  6310. {
  6311. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  6312. {
  6313. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6314. {
  6315. currentStatus = Preparing; //OCPP Status: Preparing
  6316. }
  6317. else
  6318. {
  6319. currentStatus = Available; //OCPP Status: Available
  6320. }
  6321. }
  6322. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6323. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6324. ) //S_PRECHARGE
  6325. {
  6326. currentStatus = Preparing; //OCPP Status: Preparing
  6327. }
  6328. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6329. {
  6330. currentStatus = Charging; //OCPP Status: Charging
  6331. }
  6332. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6333. {
  6334. currentStatus = Finishing; //OCPP Status: Finishing
  6335. }
  6336. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6337. {
  6338. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6339. }
  6340. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  6341. {
  6342. currentStatus = Unavailable; //OCPP Status: Unavailable
  6343. }
  6344. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6345. {
  6346. currentStatus = Faulted; //OCPP Status: Faulted
  6347. }
  6348. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6349. {
  6350. currentStatus = Reserved; //OCPP Status: Reserved
  6351. }
  6352. } //end of the same index
  6353. }//end of for CHAdeMO_QUANTITY
  6354. }
  6355. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6356. {
  6357. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6358. {
  6359. tempIndex = ((gun_index==2) ? 1: 0);
  6360. }
  6361. else
  6362. {
  6363. tempIndex = gun_index;
  6364. }
  6365. for (int index = 0; index < CCS_QUANTITY; index++)
  6366. {
  6367. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6368. {
  6369. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6370. {
  6371. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  6372. {
  6373. currentStatus = Preparing; //OCPP Status: Preparing
  6374. }
  6375. else
  6376. {
  6377. currentStatus = Available; //OCPP Status: Available
  6378. }
  6379. }
  6380. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6381. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6382. ) //S_PRECHARGE
  6383. {
  6384. currentStatus = Preparing; //OCPP Status: Preparing
  6385. }
  6386. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6387. {
  6388. currentStatus = Charging; //OCPP Status: Charging
  6389. }
  6390. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6391. {
  6392. currentStatus = Finishing; //OCPP Status: Finishing
  6393. }
  6394. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  6395. {
  6396. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6397. }
  6398. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  6399. {
  6400. currentStatus = Unavailable; //OCPP Status : Unavailable
  6401. }
  6402. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6403. {
  6404. currentStatus = Faulted; //OCPP Status: Faulted
  6405. }
  6406. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6407. {
  6408. currentStatus = Reserved; //OCPP Status: Reserved
  6409. }
  6410. } //end of the same index
  6411. } // end of for CCS_QUANTITY
  6412. }
  6413. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6414. {
  6415. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6416. {
  6417. tempIndex = ((gun_index==2) ? 1: 0);
  6418. }
  6419. else
  6420. {
  6421. tempIndex = gun_index;
  6422. }
  6423. for (int index = 0; index < GB_QUANTITY; index++)
  6424. {
  6425. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6426. {
  6427. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6428. {
  6429. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6430. {
  6431. currentStatus = Preparing; //OCPP Status: Preparing
  6432. }
  6433. else
  6434. {
  6435. currentStatus = Available; //OCPP Status: Available
  6436. }
  6437. }
  6438. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6439. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6440. ) //S_PRECHARGE
  6441. {
  6442. currentStatus = Preparing; //OCPP Status: Preparing
  6443. }
  6444. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6445. {
  6446. currentStatus = Charging; //OCPP Status: Charging
  6447. }
  6448. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6449. {
  6450. currentStatus = Finishing; //OCPP Status: Finishing
  6451. }
  6452. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6453. {
  6454. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6455. }
  6456. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  6457. {
  6458. currentStatus = Unavailable; //OCPP Status: Unavailable
  6459. }
  6460. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6461. {
  6462. currentStatus = Faulted; //OCPP Status: Faulted
  6463. }
  6464. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6465. {
  6466. currentStatus = Reserved; //OCPP Status: Reserved
  6467. }
  6468. } //end of the same index
  6469. } // end of for GB_QUANTITY
  6470. }
  6471. else if(gunType[gun_index] == GUN_TYPE_DO)
  6472. {
  6473. tempIndex = gun_index;
  6474. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6475. {
  6476. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6477. {
  6478. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6479. {
  6480. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6481. {
  6482. currentStatus = Preparing; //OCPP Status: Preparing
  6483. }
  6484. else
  6485. {
  6486. currentStatus = Available; //OCPP Status: Available
  6487. }
  6488. }
  6489. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6490. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6491. ) //S_PRECHARGE
  6492. {
  6493. currentStatus = Preparing; //OCPP Status: Preparing
  6494. }
  6495. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6496. {
  6497. currentStatus = Charging; //OCPP Status: Charging
  6498. }
  6499. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6500. {
  6501. currentStatus = Finishing; //OCPP Status: Finishing
  6502. }
  6503. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6504. {
  6505. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6506. }
  6507. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  6508. {
  6509. currentStatus = Unavailable; //OCPP Status: Unavailable
  6510. }
  6511. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6512. {
  6513. currentStatus = Faulted; //OCPP Status: Faulted
  6514. }
  6515. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6516. {
  6517. currentStatus = Reserved; //OCPP Status: Reserved
  6518. }
  6519. } //end of the same index
  6520. }
  6521. }
  6522. else
  6523. {
  6524. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6525. {
  6526. tempIndex = 2;
  6527. }
  6528. else
  6529. {
  6530. tempIndex = gun_index;
  6531. }
  6532. for (int index = 0; index < AC_QUANTITY; index++)
  6533. {
  6534. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6535. {
  6536. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  6537. {
  6538. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  6539. {
  6540. currentStatus = Preparing; //OCPP Status: Preparing
  6541. }
  6542. else
  6543. {
  6544. currentStatus = Available; //OCPP Status: Available
  6545. }
  6546. }
  6547. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  6548. {
  6549. currentStatus = Preparing; //OCPP Status: Preparing
  6550. }
  6551. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  6552. {
  6553. currentStatus = Charging; //OCPP Status: Charging
  6554. }
  6555. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  6556. {
  6557. currentStatus = Finishing; //OCPP Status: Finishing
  6558. }
  6559. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6560. {
  6561. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  6562. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6563. else
  6564. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  6565. }
  6566. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  6567. {
  6568. currentStatus = Unavailable; //OCPP Status: Unavailable
  6569. }
  6570. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6571. {
  6572. currentStatus = Faulted; //OCPP Status: Faulted
  6573. }
  6574. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6575. {
  6576. currentStatus = Reserved; //OCPP Status: Reserved
  6577. }
  6578. }//end of the same index
  6579. }//end of for AC_QUANTITY
  6580. }
  6581. //it's option
  6582. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  6583. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  6584. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  6585. {
  6586. isStateChanged = FALSE;
  6587. }
  6588. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6589. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  6590. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6591. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  6592. isContentIllegal = TRUE;
  6593. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  6594. {
  6595. if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  6596. {
  6597. isContentIllegal = FALSE;
  6598. break;
  6599. }
  6600. }
  6601. if(isContentIllegal)
  6602. {
  6603. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  6604. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  6605. }
  6606. random_uuid(guid);
  6607. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6608. , MESSAGE_TYPE_CALL
  6609. , guid
  6610. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  6611. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  6612. , ShmOCPP16Data->StatusNotification[gun_index].Info
  6613. , ShmOCPP16Data->StatusNotification[gun_index].Status
  6614. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  6615. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  6616. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  6617. if((server_sign == TRUE) && isStateChanged)
  6618. {
  6619. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6620. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6621. LWS_Send(message);
  6622. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  6623. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  6624. {
  6625. //DEBUG_ERROR("statusNotification mapitem pass");
  6626. result = PASS;
  6627. }
  6628. }
  6629. else
  6630. {
  6631. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6632. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6633. result = PASS;
  6634. }
  6635. return result;
  6636. }
  6637. int sendStopTransactionRequest(int gun_index)
  6638. {
  6639. mtrace();
  6640. int result = FAIL;
  6641. //char message[1500]={0};
  6642. char guid[37]={0};
  6643. char tempdata[65]={0};
  6644. int tempIndex = 0;
  6645. char TempStopTransaction[256];
  6646. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  6647. DEBUG_INFO("sendStopTransactionRequest \n");
  6648. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6649. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  6650. //=========================== Stop Transaction Time ===============================================
  6651. getNowDatetime(ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  6652. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  6653. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  6654. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6655. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6656. {
  6657. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6658. {
  6659. tempIndex = ((gun_index==2) ? 1: 0);
  6660. }
  6661. else
  6662. {
  6663. tempIndex = gun_index;
  6664. }
  6665. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6666. {
  6667. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6668. {
  6669. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6670. }
  6671. }// END OF CHAdeMO_QUANTITY
  6672. }
  6673. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6674. {
  6675. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6676. {
  6677. tempIndex = ((gun_index==2) ? 1: 0);
  6678. }
  6679. else
  6680. {
  6681. tempIndex = gun_index;
  6682. }
  6683. for (int index = 0; index < CCS_QUANTITY; index++)
  6684. {
  6685. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6686. {
  6687. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6688. }
  6689. }// END OF CCS_QUANTITY
  6690. }
  6691. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6692. {
  6693. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6694. {
  6695. tempIndex = ((gun_index==2) ? 1: 0);
  6696. }
  6697. else
  6698. {
  6699. tempIndex = gun_index;
  6700. }
  6701. for (int index = 0; index < GB_QUANTITY; index++)
  6702. {
  6703. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6704. {
  6705. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6706. }
  6707. }// END OF GB_QUANTITY
  6708. }
  6709. else if(gunType[gun_index] == GUN_TYPE_DO)
  6710. {
  6711. tempIndex = gun_index;
  6712. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6713. {
  6714. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6715. {
  6716. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6717. }
  6718. }// END OF GB_QUANTITY
  6719. }
  6720. else
  6721. {
  6722. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6723. {
  6724. tempIndex = 2;
  6725. }
  6726. else
  6727. {
  6728. tempIndex = gun_index;
  6729. }
  6730. for (int index = 0; index < AC_QUANTITY; index++)
  6731. {
  6732. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6733. {
  6734. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6735. }
  6736. }// END OF AC_QUANTITY
  6737. }
  6738. //================================================ Message create ====================================================
  6739. json_object *StopTransaction = json_object_new_object();
  6740. json_object *transactionDatas = json_object_new_array();
  6741. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6742. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6743. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6744. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6745. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6746. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6747. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6748. meterValueBufferQuery(gun_index, transactionDatas);
  6749. if(json_object_array_length(transactionDatas) > 0) json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6750. random_uuid(guid);
  6751. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6752. ,MESSAGE_TYPE_CALL
  6753. ,guid
  6754. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6755. json_object_put(StopTransaction);
  6756. #if 1 // for TempStopTransaction
  6757. //Delete TempStopTransaction
  6758. if((access(TempStopTransaction,F_OK))!=-1)
  6759. {
  6760. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6761. }
  6762. #endif
  6763. #if 1
  6764. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6765. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6766. {
  6767. result = PASS;
  6768. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6769. }
  6770. #endif
  6771. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6772. OCPP_insert_transaction_msg(NO, queuedata);
  6773. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6774. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6775. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6776. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6777. {
  6778. //SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6779. }
  6780. //for test
  6781. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6782. return result;
  6783. }
  6784. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6785. {
  6786. mtrace();
  6787. int result = FAIL;
  6788. char guid[37]={0};
  6789. char tempdata[65]={0};
  6790. int tempIndex = 0;
  6791. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6792. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6793. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6794. //set value
  6795. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6796. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6797. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6798. -1);
  6799. random_uuid(guid);
  6800. //UTC Date time
  6801. struct timeval tmnow;
  6802. struct tm *tm;
  6803. char buf[28];//, usec_buf[6];
  6804. gettimeofday(&tmnow, NULL);
  6805. time_t t;
  6806. t = time(NULL);
  6807. /*UTC time and date*/
  6808. tm = gmtime(&t);
  6809. if(dataType == ReadingContext_Sample_Clock)
  6810. {
  6811. struct tm *tmTarget;
  6812. struct timeb tbTarget;
  6813. tbTarget.time = mktime(tm);
  6814. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6815. tmTarget = gmtime(&tbTarget.time);
  6816. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6817. }
  6818. else
  6819. {
  6820. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6821. }
  6822. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6823. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6824. //********************************(1)Current.Import L1************************************************/
  6825. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6826. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6827. (dataType == ReadingContext_Trigger))
  6828. {
  6829. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6830. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6831. {
  6832. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6833. {
  6834. tempIndex = ((gun_index==2) ? 1: 0);
  6835. }
  6836. else
  6837. {
  6838. tempIndex = gun_index;
  6839. }
  6840. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6841. {
  6842. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6843. {
  6844. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6845. }
  6846. }
  6847. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6848. }
  6849. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6850. {
  6851. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6852. {
  6853. tempIndex = ((gun_index==2) ? 1: 0);
  6854. }
  6855. else
  6856. {
  6857. tempIndex = gun_index;
  6858. }
  6859. for (int index = 0; index < CCS_QUANTITY; index++)
  6860. {
  6861. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6862. {
  6863. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6864. }
  6865. }
  6866. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6867. }
  6868. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6869. {
  6870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6871. {
  6872. tempIndex = ((gun_index==2) ? 1: 0);
  6873. }
  6874. else
  6875. {
  6876. tempIndex = gun_index;
  6877. }
  6878. for (int index = 0; index < GB_QUANTITY; index++)
  6879. {
  6880. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6881. {
  6882. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6883. }
  6884. }
  6885. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6886. }
  6887. else if(gunType[gun_index] == GUN_TYPE_DO)
  6888. {
  6889. tempIndex = gun_index;
  6890. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6891. {
  6892. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6893. {
  6894. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6895. }
  6896. }
  6897. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6898. }
  6899. else
  6900. {
  6901. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6902. {
  6903. tempIndex = 2;
  6904. }
  6905. else
  6906. {
  6907. tempIndex = gun_index;
  6908. }
  6909. for (int index = 0; index < AC_QUANTITY; index++)
  6910. {
  6911. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6912. {
  6913. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6914. }
  6915. }
  6916. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6917. }
  6918. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6919. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6920. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6921. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6922. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6923. }
  6924. //********************************(2)Energy.Active.Import.Register ************************************************/
  6925. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6926. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6927. (dataType == ReadingContext_Trigger))
  6928. {
  6929. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6930. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6931. {
  6932. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6933. {
  6934. tempIndex = ((gun_index==2) ? 1: 0);
  6935. }
  6936. else
  6937. {
  6938. tempIndex = gun_index;
  6939. }
  6940. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6941. {
  6942. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6943. {
  6944. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6945. }
  6946. }
  6947. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6948. }
  6949. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6950. {
  6951. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6952. {
  6953. tempIndex = ((gun_index==2) ? 1: 0);
  6954. }
  6955. else
  6956. {
  6957. tempIndex = gun_index;
  6958. }
  6959. for (int index = 0; index < CCS_QUANTITY; index++)
  6960. {
  6961. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6962. {
  6963. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6964. }
  6965. }
  6966. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6967. }
  6968. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6969. {
  6970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6971. {
  6972. tempIndex = ((gun_index==2) ? 1: 0);
  6973. }
  6974. else
  6975. {
  6976. tempIndex = gun_index;
  6977. }
  6978. for (int index = 0; index < GB_QUANTITY; index++)
  6979. {
  6980. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6981. {
  6982. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6983. }
  6984. }
  6985. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6986. }
  6987. else if(gunType[gun_index] == GUN_TYPE_DO)
  6988. {
  6989. tempIndex = gun_index;
  6990. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6991. {
  6992. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6993. {
  6994. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6995. }
  6996. }
  6997. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6998. }
  6999. else
  7000. {
  7001. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7002. {
  7003. tempIndex = 2;
  7004. }
  7005. else
  7006. {
  7007. tempIndex = gun_index;
  7008. }
  7009. for (int index = 0; index < AC_QUANTITY; index++)
  7010. {
  7011. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7012. {
  7013. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  7014. }
  7015. }
  7016. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  7017. }
  7018. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  7019. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  7020. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  7021. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  7022. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7023. }
  7024. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  7025. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7026. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7027. (dataType == ReadingContext_Trigger))
  7028. {
  7029. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7030. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7031. {
  7032. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7033. {
  7034. tempIndex = ((gun_index==2) ? 1: 0);
  7035. }
  7036. else
  7037. {
  7038. tempIndex = gun_index;
  7039. }
  7040. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7041. {
  7042. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7043. {
  7044. if(dataType == ReadingContext_Sample_Clock)
  7045. {
  7046. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7047. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7048. }
  7049. else if(dataType == ReadingContext_Sample_Periodic)
  7050. {
  7051. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7052. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7053. }
  7054. else
  7055. {
  7056. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7057. }
  7058. }
  7059. } // END OF FOR CHAdeMO_QUANTITY
  7060. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7061. }
  7062. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7063. {
  7064. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7065. {
  7066. tempIndex = ((gun_index==2) ? 1: 0);
  7067. }
  7068. else
  7069. {
  7070. tempIndex = gun_index;
  7071. }
  7072. for (int index = 0; index < CCS_QUANTITY; index++)
  7073. {
  7074. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7075. {
  7076. if(dataType == ReadingContext_Sample_Clock)
  7077. {
  7078. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7079. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7080. }
  7081. else if(dataType == ReadingContext_Sample_Periodic)
  7082. {
  7083. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7084. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7085. }
  7086. else
  7087. {
  7088. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7089. }
  7090. }
  7091. } // END OF CCS_QUANTITY
  7092. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7093. }
  7094. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7095. {
  7096. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7097. {
  7098. tempIndex = ((gun_index==2) ? 1: 0);
  7099. }
  7100. else
  7101. {
  7102. tempIndex = gun_index;
  7103. }
  7104. for (int index = 0; index < GB_QUANTITY; index++)
  7105. {
  7106. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7107. {
  7108. if(dataType == ReadingContext_Sample_Clock)
  7109. {
  7110. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7111. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7112. }
  7113. else if(dataType == ReadingContext_Sample_Periodic)
  7114. {
  7115. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7116. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7117. }
  7118. else
  7119. {
  7120. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7121. }
  7122. }
  7123. } // END OF GB_QUANTITY
  7124. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7125. }
  7126. else if(gunType[gun_index] == GUN_TYPE_DO)
  7127. {
  7128. tempIndex = gun_index;
  7129. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7130. {
  7131. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7132. {
  7133. if(dataType == ReadingContext_Sample_Clock)
  7134. {
  7135. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7136. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7137. }
  7138. else if(dataType == ReadingContext_Sample_Periodic)
  7139. {
  7140. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7141. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7142. }
  7143. else
  7144. {
  7145. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7146. }
  7147. }
  7148. }
  7149. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7150. }
  7151. else
  7152. {
  7153. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7154. {
  7155. tempIndex = 2;
  7156. }
  7157. else
  7158. {
  7159. tempIndex = gun_index;
  7160. }
  7161. for (int index = 0; index < AC_QUANTITY; index++)
  7162. {
  7163. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7164. {
  7165. if(dataType == ReadingContext_Sample_Clock)
  7166. {
  7167. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7168. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7169. }
  7170. else if(dataType == ReadingContext_Sample_Periodic)
  7171. {
  7172. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7173. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7174. }
  7175. else
  7176. {
  7177. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7178. }
  7179. }
  7180. }
  7181. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7182. }
  7183. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7184. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7185. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7186. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7187. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7188. }
  7189. //********************************(4)Power.Active.Import************************************************/
  7190. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7191. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7192. (dataType == ReadingContext_Trigger))
  7193. {
  7194. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7195. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7196. {
  7197. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7198. {
  7199. tempIndex = ((gun_index==2) ? 1: 0);
  7200. }
  7201. else
  7202. {
  7203. tempIndex = gun_index;
  7204. }
  7205. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7206. {
  7207. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7208. {
  7209. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7210. }
  7211. } // END OF FOR
  7212. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7213. }
  7214. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7215. {
  7216. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7217. {
  7218. tempIndex = ((gun_index==2) ? 1: 0);
  7219. }
  7220. else
  7221. {
  7222. tempIndex = gun_index;
  7223. }
  7224. for (int index = 0; index < CCS_QUANTITY; index++)
  7225. {
  7226. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7227. {
  7228. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7229. }
  7230. }
  7231. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7232. }
  7233. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7234. {
  7235. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7236. {
  7237. tempIndex = ((gun_index==2) ? 1: 0);
  7238. }
  7239. else
  7240. {
  7241. tempIndex = gun_index;
  7242. }
  7243. for (int index = 0; index < GB_QUANTITY; index++)
  7244. {
  7245. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7246. {
  7247. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7248. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7249. }
  7250. }
  7251. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7252. }
  7253. else if(gunType[gun_index] == GUN_TYPE_DO)
  7254. {
  7255. tempIndex = gun_index;
  7256. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7257. {
  7258. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7259. {
  7260. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7261. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7262. }
  7263. }
  7264. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7265. }
  7266. else
  7267. {
  7268. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7269. {
  7270. tempIndex = 2;
  7271. }
  7272. else
  7273. {
  7274. tempIndex = gun_index;
  7275. }
  7276. for (int index = 0; index < AC_QUANTITY; index++)
  7277. {
  7278. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7279. {
  7280. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7281. }
  7282. }
  7283. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7284. }
  7285. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7286. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7287. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7288. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7289. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7290. }
  7291. //***********************************************(5)VOLTAGE L1******************************************************/
  7292. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7293. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7294. (dataType == ReadingContext_Trigger))
  7295. {
  7296. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7297. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7298. {
  7299. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7300. {
  7301. tempIndex = ((gun_index==2) ? 1: 0);
  7302. }
  7303. else
  7304. {
  7305. tempIndex = gun_index;
  7306. }
  7307. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7308. {
  7309. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7310. {
  7311. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7312. }
  7313. }
  7314. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7315. }
  7316. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7317. {
  7318. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7319. {
  7320. tempIndex = ((gun_index==2) ? 1: 0);
  7321. }
  7322. else
  7323. {
  7324. tempIndex = gun_index;
  7325. }
  7326. for (int index = 0; index < CCS_QUANTITY; index++)
  7327. {
  7328. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7329. {
  7330. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7331. }
  7332. }
  7333. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7334. }
  7335. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7336. {
  7337. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7338. {
  7339. tempIndex = ((gun_index==2) ? 1: 0);
  7340. }
  7341. else
  7342. {
  7343. tempIndex = gun_index;
  7344. }
  7345. for (int index = 0; index < GB_QUANTITY; index++)
  7346. {
  7347. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7348. {
  7349. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7350. }
  7351. }
  7352. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7353. }
  7354. else if(gunType[gun_index] == GUN_TYPE_DO)
  7355. {
  7356. tempIndex = gun_index;
  7357. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7358. {
  7359. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7360. {
  7361. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7362. }
  7363. }
  7364. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7365. }
  7366. else
  7367. {
  7368. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7369. {
  7370. tempIndex = 2;
  7371. }
  7372. else
  7373. {
  7374. tempIndex = gun_index;
  7375. }
  7376. for (int index = 0; index < AC_QUANTITY; index++)
  7377. {
  7378. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7379. {
  7380. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7381. }
  7382. }
  7383. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7384. }
  7385. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7386. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7387. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7388. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7389. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7390. }
  7391. //***********************************************(6)SOC******************************************************/
  7392. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7393. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7394. (dataType == ReadingContext_Trigger))
  7395. {
  7396. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  7397. {
  7398. //idx_sample=5;
  7399. //sampledValue = NULL;
  7400. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7401. {
  7402. tempIndex = ((gun_index==2) ? 1: 0);
  7403. }
  7404. else
  7405. {
  7406. tempIndex = gun_index;
  7407. }
  7408. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7409. {
  7410. //tempIndex = ((gun_index==2) ? 1: 0);
  7411. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7412. {
  7413. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7414. {
  7415. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7416. }
  7417. }
  7418. }
  7419. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7420. {
  7421. //tempIndex = ((gun_index==2) ? 1: 0);
  7422. for (int index = 0; index < CCS_QUANTITY; index++)
  7423. {
  7424. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7425. {
  7426. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7427. }
  7428. }
  7429. }
  7430. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7431. {
  7432. //tempIndex = ((gun_index==2) ? 1: 0);
  7433. for (int index = 0; index < GB_QUANTITY; index++)
  7434. {
  7435. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7436. {
  7437. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7438. }
  7439. }
  7440. }
  7441. else if(gunType[gun_index] == GUN_TYPE_DO)
  7442. {
  7443. //tempIndex = ((gun_index==2) ? 1: 0);
  7444. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7445. {
  7446. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7447. {
  7448. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7449. }
  7450. }
  7451. }
  7452. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7453. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7454. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7455. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7456. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7457. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7458. }
  7459. }
  7460. //********************************(7)Current.Import L2************************************************/
  7461. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7462. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7463. (dataType == ReadingContext_Trigger))
  7464. {
  7465. // Only for AC 3 phase
  7466. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7467. {
  7468. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7469. {
  7470. tempIndex = 2;
  7471. }
  7472. else
  7473. {
  7474. tempIndex = gun_index;
  7475. }
  7476. for (int index = 0; index < AC_QUANTITY; index++)
  7477. {
  7478. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7479. {
  7480. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7481. }
  7482. }
  7483. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7484. }
  7485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7486. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7487. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7488. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7489. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7490. }
  7491. //********************************(8)Current.Import L3************************************************/
  7492. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7493. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7494. (dataType == ReadingContext_Trigger))
  7495. {
  7496. // Only for AC 3 phase
  7497. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7498. {
  7499. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7500. {
  7501. tempIndex = 2;
  7502. }
  7503. else
  7504. {
  7505. tempIndex = gun_index;
  7506. }
  7507. for (int index = 0; index < AC_QUANTITY; index++)
  7508. {
  7509. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7510. {
  7511. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7512. }
  7513. }
  7514. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7515. }
  7516. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7517. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7518. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7519. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7520. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7521. }
  7522. //***********************************************(9)VOLTAGE L2******************************************************/
  7523. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7524. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7525. (dataType == ReadingContext_Trigger))
  7526. {
  7527. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7528. {
  7529. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7530. {
  7531. tempIndex = 2;
  7532. }
  7533. else
  7534. {
  7535. tempIndex = gun_index;
  7536. }
  7537. for (int index = 0; index < AC_QUANTITY; index++)
  7538. {
  7539. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7540. {
  7541. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7542. }
  7543. }
  7544. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7545. }
  7546. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7547. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7548. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7551. }
  7552. //***********************************************(10)VOLTAGE L3******************************************************/
  7553. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7554. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7555. (dataType == ReadingContext_Trigger))
  7556. {
  7557. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7558. {
  7559. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7560. {
  7561. tempIndex = 2;
  7562. }
  7563. else
  7564. {
  7565. tempIndex = gun_index;
  7566. }
  7567. for (int index = 0; index < AC_QUANTITY; index++)
  7568. {
  7569. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7570. {
  7571. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7572. }
  7573. }
  7574. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7575. }
  7576. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7577. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7579. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7581. }
  7582. //***********************************************(11)Current.Offered******************************************************/
  7583. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7584. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7585. (dataType == ReadingContext_Trigger))
  7586. {
  7587. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7588. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7589. {
  7590. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7591. {
  7592. tempIndex = ((gun_index==2) ? 1: 0);
  7593. }
  7594. else
  7595. {
  7596. tempIndex = gun_index;
  7597. }
  7598. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7599. {
  7600. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7601. {
  7602. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7603. }
  7604. } // END OF FOR CHAdeMO_QUANTITY
  7605. }
  7606. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7607. {
  7608. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7609. {
  7610. tempIndex = ((gun_index==2) ? 1: 0);
  7611. }
  7612. else
  7613. {
  7614. tempIndex = gun_index;
  7615. }
  7616. for (int index = 0; index < CCS_QUANTITY; index++)
  7617. {
  7618. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7619. {
  7620. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7621. }
  7622. } // END OF CCS_QUANTITY
  7623. }
  7624. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7625. {
  7626. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7627. {
  7628. tempIndex = ((gun_index==2) ? 1: 0);
  7629. }
  7630. else
  7631. {
  7632. tempIndex = gun_index;
  7633. }
  7634. for (int index = 0; index < GB_QUANTITY; index++)
  7635. {
  7636. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7637. {
  7638. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7639. }
  7640. } // END OF GB_QUANTITY
  7641. }
  7642. else if(gunType[gun_index] == GUN_TYPE_DO)
  7643. {
  7644. tempIndex = gun_index;
  7645. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7646. {
  7647. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7648. {
  7649. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7650. }
  7651. }
  7652. }
  7653. else
  7654. {
  7655. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7656. {
  7657. tempIndex = 2;
  7658. }
  7659. else
  7660. {
  7661. tempIndex = gun_index;
  7662. }
  7663. for (int index = 0; index < AC_QUANTITY; index++)
  7664. {
  7665. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7666. {
  7667. uint16_t currentOffer;
  7668. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7669. {
  7670. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7671. }
  7672. else
  7673. {
  7674. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7675. }
  7676. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7677. }
  7678. }
  7679. }
  7680. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7681. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7682. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7683. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7684. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7685. }
  7686. //***********************************************(12)Power.Offered******************************************************/
  7687. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7688. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7689. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7690. {
  7691. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7692. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7693. {
  7694. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7695. {
  7696. tempIndex = ((gun_index==2) ? 1: 0);
  7697. }
  7698. else
  7699. {
  7700. tempIndex = gun_index;
  7701. }
  7702. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7703. {
  7704. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7705. {
  7706. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7707. }
  7708. } // END OF FOR CHAdeMO_QUANTITY
  7709. }
  7710. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7711. {
  7712. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7713. {
  7714. tempIndex = ((gun_index==2) ? 1: 0);
  7715. }
  7716. else
  7717. {
  7718. tempIndex = gun_index;
  7719. }
  7720. for (int index = 0; index < CCS_QUANTITY; index++)
  7721. {
  7722. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7723. {
  7724. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7725. }
  7726. } // END OF CCS_QUANTITY
  7727. }
  7728. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7729. {
  7730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7731. {
  7732. tempIndex = ((gun_index==2) ? 1: 0);
  7733. }
  7734. else
  7735. {
  7736. tempIndex = gun_index;
  7737. }
  7738. for (int index = 0; index < GB_QUANTITY; index++)
  7739. {
  7740. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7741. {
  7742. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7743. }
  7744. } // END OF GB_QUANTITY
  7745. }
  7746. else if(gunType[gun_index] == GUN_TYPE_DO)
  7747. {
  7748. tempIndex = gun_index;
  7749. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7750. {
  7751. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7752. {
  7753. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7754. }
  7755. }
  7756. }
  7757. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7758. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7759. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7760. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7761. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7762. }
  7763. // Message create ====================================================================================================
  7764. if(TRUE)
  7765. {
  7766. json_object *MeterValueReq = json_object_new_object();
  7767. json_object *MeterValues = json_object_new_array();
  7768. json_object *sampledValues = json_object_new_array();
  7769. json_object *sampledValuesBuffer = json_object_new_array();
  7770. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7771. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7772. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7773. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7774. {
  7775. json_object *MeterValue = json_object_new_object();
  7776. json_object *MeterValueBuffer = json_object_new_object();
  7777. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7778. {
  7779. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7780. {
  7781. json_object *sampledValue = json_object_new_object();
  7782. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7783. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7784. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7785. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7786. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7787. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7788. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7789. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7790. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7791. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7792. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7793. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7794. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7795. json_object_array_add(sampledValues, sampledValue);
  7796. // For StopTxn data
  7797. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, (char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand ) != NULL) && (strlen((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData) > 0)) ||
  7798. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, (char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) != NULL) && (strlen((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData) > 0)))
  7799. {
  7800. json_object *sampledValue = json_object_new_object();
  7801. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7802. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7803. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7804. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7805. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7806. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7807. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7808. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7809. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7810. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7811. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7812. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7813. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7814. json_object_array_add(sampledValuesBuffer, sampledValue);
  7815. }
  7816. }
  7817. }
  7818. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7819. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7820. json_object_array_add(MeterValues, MeterValue);
  7821. // For StopTxn data
  7822. if((dataType != ReadingContext_Trigger) &&
  7823. (json_object_array_length(sampledValuesBuffer) > 0))
  7824. {
  7825. json_object_object_add(MeterValueBuffer, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7826. json_object_object_add(MeterValueBuffer, "sampledValue", sampledValuesBuffer);
  7827. if(meterValueBufferDataQuantity(gun_index, dataType) < 200) meterValueBufferInsert(gun_index, dataType, ShmOCPP16Data->MeterValues[gun_index].TransactionId, (char*)json_object_to_json_string_ext(MeterValueBuffer, JSON_C_TO_STRING_PLAIN));
  7828. json_object_put(MeterValueBuffer);
  7829. }
  7830. else
  7831. {
  7832. json_object_put(sampledValuesBuffer);
  7833. json_object_put(MeterValueBuffer);
  7834. }
  7835. }
  7836. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7837. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7838. ,gun_index + 1
  7839. ,MESSAGE_TYPE_CALL
  7840. ,guid
  7841. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7842. json_object_put(MeterValueReq);
  7843. }
  7844. // Put request guid to hash map
  7845. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7846. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  7847. {
  7848. result = PASS;
  7849. //DEBUG_INFO("MeterValues mapitem pass\n");
  7850. }
  7851. if((dataType != ReadingContext_Trigger) &&
  7852. (dataType != ReadingContext_Sample_Clock) &&
  7853. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7854. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7855. else
  7856. {
  7857. if(FirstHeartBeat)
  7858. LWS_Send(queuedata +2);
  7859. }
  7860. return result;
  7861. }
  7862. int sendLogStatusNotificationRequest(char *status)
  7863. {
  7864. mtrace();
  7865. int result = PASS;
  7866. char message[4096]={0};
  7867. char guid[37]={0};
  7868. char tempdata[128]={0};
  7869. json_object *LogStatusNotification = json_object_new_object();
  7870. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7871. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7872. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7873. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7874. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7875. random_uuid(guid);
  7876. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7877. json_object_put(LogStatusNotification);
  7878. LWS_Send(message);
  7879. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7880. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7881. {
  7882. result = PASS;
  7883. }
  7884. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7885. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7886. return result;
  7887. }
  7888. int sendSecurityEventNotificationRequest()
  7889. {
  7890. mtrace();
  7891. int result = PASS;
  7892. char message[4096]={0};
  7893. char guid[37]={0};
  7894. char tempdata[128]={0};
  7895. json_object *SecurityEventNotification = json_object_new_object();
  7896. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7897. //Stop Transaction Time
  7898. struct timeval tmnow;
  7899. struct tm *tm;
  7900. gettimeofday(&tmnow, NULL);
  7901. time_t t;
  7902. t = time(NULL);
  7903. /*UTC time and date*/
  7904. tm = gmtime(&t);
  7905. strftime((char *)ShmOCPP16Data->SecurityEventNotification.timestamp, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.timestamp), "%Y-%m-%dT%H:%M:%SZ", tm);
  7906. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7907. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7908. if(strlen((char*)ShmOCPP16Data->SecurityEventNotification.techInfo) > 0)
  7909. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7910. random_uuid(guid);
  7911. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7912. json_object_put(SecurityEventNotification);
  7913. LWS_Send(message);
  7914. sprintf(tempdata, "SecurityEventNotification,0");
  7915. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7916. {
  7917. result = PASS;
  7918. }
  7919. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7920. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7921. return result;
  7922. }
  7923. int sendSignCertificateRequest()
  7924. {
  7925. mtrace();
  7926. int result = PASS;
  7927. char message[4096]={0};
  7928. char guid[37]={0};
  7929. char tempdata[128]={0};
  7930. json_object *SignCertificate = json_object_new_object();
  7931. DEBUG_INFO("sendSignCertificateRequest...\n");
  7932. // Read csr file content
  7933. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7934. FILE *fp=fopen(CSR_CP,"r");
  7935. char *line = NULL;
  7936. size_t len = 0;
  7937. while(getline(&line, &len, fp) != -1)
  7938. {
  7939. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7940. {
  7941. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7942. }
  7943. }
  7944. fclose(fp);
  7945. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7946. random_uuid(guid);
  7947. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7948. json_object_put(SignCertificate);
  7949. LWS_Send(message);
  7950. sprintf(tempdata, "SignCertificate,0");
  7951. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7952. {
  7953. result = PASS;
  7954. }
  7955. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7956. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7957. return result;
  7958. }
  7959. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7960. {
  7961. mtrace();
  7962. int result = PASS;
  7963. char message[4096]={0};
  7964. char guid[37]={0};
  7965. char tempdata[128]={0};
  7966. json_object *SignedFirmwareStatusNotification = json_object_new_object();
  7967. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7968. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7969. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7970. json_object_object_add(SignedFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7971. json_object_object_add(SignedFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7972. random_uuid(guid);
  7973. sprintf(message,"[%d,\"%s\",\"SignedFirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(SignedFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7974. json_object_put(SignedFirmwareStatusNotification);
  7975. LWS_Send(message);
  7976. sprintf(tempdata, "SignedFirmwareStatusNotification,%d", 0);
  7977. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7978. {
  7979. result = PASS;
  7980. }
  7981. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7982. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7983. return result;
  7984. }
  7985. //==========================================
  7986. // send confirm routine
  7987. //==========================================
  7988. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7989. {
  7990. mtrace();
  7991. int result = FAIL;
  7992. char message[100]={0};
  7993. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7994. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7995. LWS_Send(message);
  7996. result = TRUE;
  7997. return result;
  7998. }
  7999. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  8000. {
  8001. mtrace();
  8002. int result = FAIL;
  8003. char message[100]={0};
  8004. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  8005. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8006. LWS_Send(message);
  8007. result = TRUE;
  8008. return result;
  8009. }
  8010. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  8011. {
  8012. mtrace();
  8013. int result = FAIL;
  8014. char message[100]={0};
  8015. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  8016. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8017. LWS_Send(message);
  8018. result = TRUE;
  8019. return result;
  8020. }
  8021. int sendClearCacheConfirmation(char *uuid,char *payload)
  8022. {
  8023. mtrace();
  8024. int result = FAIL;
  8025. char message[500]={0};
  8026. DEBUG_INFO("sendClearCacheConfirmation...\n");
  8027. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8028. LWS_Send(message);
  8029. return result;
  8030. }
  8031. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  8032. {
  8033. mtrace();
  8034. int result = FAIL;
  8035. char message[500]={0};
  8036. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  8037. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8038. LWS_Send(message);
  8039. return result;
  8040. }
  8041. int sendDataTransferConfirmation(char *uuid,char *payload)
  8042. {
  8043. mtrace();
  8044. char statusStr[20]={0};
  8045. char dataStr[10]={0};
  8046. char sstr[20]={0};
  8047. int c = 0;
  8048. char *loc;
  8049. int result = FAIL;
  8050. DEBUG_INFO("sendDataTransferConfirmation...\n");
  8051. /**********************status**************************/
  8052. loc = strstr(payload, "status");
  8053. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8054. c = 0;
  8055. while (loc[3+strlen("status")+c] != '\"')
  8056. {
  8057. sstr[c] = loc[3+strlen("status")+c];
  8058. c++;
  8059. }
  8060. sstr[c] = '\0';
  8061. strcpy(statusStr, sstr);
  8062. /**********************data**************************/
  8063. loc = strstr(payload, "data");
  8064. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8065. c = 0;
  8066. while (loc[3+strlen("data")+c] != '\"')
  8067. {
  8068. sstr[c] = loc[3+strlen("data")+c];
  8069. c++;
  8070. }
  8071. sstr[c] = '\0';
  8072. strcpy(dataStr, sstr);
  8073. return result;
  8074. }
  8075. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  8076. {
  8077. mtrace();
  8078. int result = FAIL;
  8079. char message[1000]={0};
  8080. int CompositeScheduleIndex = 0;
  8081. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  8082. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  8083. if(nPeriod == 0)
  8084. {
  8085. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  8086. {
  8087. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  8088. ,MESSAGE_TYPE_CALLRESULT
  8089. ,uuid
  8090. ,payload
  8091. ,connectorIdInt);
  8092. }
  8093. else
  8094. {
  8095. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  8096. ,MESSAGE_TYPE_CALLRESULT
  8097. ,uuid
  8098. ,payload
  8099. ,connectorIdInt
  8100. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8101. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8102. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8103. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  8104. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  8105. }
  8106. }
  8107. else
  8108. {
  8109. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  8110. ,MESSAGE_TYPE_CALLRESULT
  8111. ,uuid
  8112. ,payload
  8113. ,connectorIdInt
  8114. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8115. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8116. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8117. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  8118. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  8119. {
  8120. if (idx_sample == 0)
  8121. {
  8122. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8123. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8124. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8125. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8126. }
  8127. else
  8128. {
  8129. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8130. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8131. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8132. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8133. }
  8134. }
  8135. sprintf(message + strlen(message), "]}}]");
  8136. }
  8137. LWS_Send(message);
  8138. result = TRUE;
  8139. return result;
  8140. }
  8141. int sendGetConfigurationConfirmation(char *uuid)
  8142. {
  8143. mtrace();
  8144. int result = FAIL;
  8145. int MaxKeySupported = 0;
  8146. int sentConfigurationNumber= 0;
  8147. int sentunConfigurationNumber= 0;
  8148. char message[1024*10]={0};
  8149. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  8150. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8151. //configuration key
  8152. json_object *GetConfiguration = json_object_new_object();
  8153. json_object *configurationKey = json_object_new_array();
  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. json_object *keyValue = json_object_new_object();
  8159. json_object_object_add(keyValue, "key", json_object_new_string((char*)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key));
  8160. json_object_object_add(keyValue, "readonly", atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1?json_object_new_boolean(1):json_object_new_boolean(0));
  8161. json_object_object_add(keyValue, "value", json_object_new_string((char*)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value));
  8162. json_object_array_add(configurationKey, keyValue);
  8163. sentConfigurationNumber = sentConfigurationNumber + 1;
  8164. }
  8165. }
  8166. json_object *unknownKey = json_object_new_array();
  8167. if(UnknownKeynum != 0)
  8168. {
  8169. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8170. {
  8171. DEBUG_INFO("unknown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8172. json_object_array_add(unknownKey, json_object_new_string((char*)ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item));
  8173. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8174. }
  8175. }
  8176. if((sentConfigurationNumber>0) && (sentunConfigurationNumber>0))
  8177. {
  8178. json_object_object_add(GetConfiguration, "configurationKey", configurationKey);
  8179. json_object_object_add(GetConfiguration, "unknownKey", unknownKey);
  8180. }
  8181. else if(sentConfigurationNumber>0)
  8182. {
  8183. json_object_object_add(GetConfiguration, "configurationKey", configurationKey);
  8184. json_object_put(unknownKey);
  8185. }
  8186. else
  8187. {
  8188. json_object_object_add(GetConfiguration, "unknownKey", unknownKey);
  8189. json_object_put(configurationKey);
  8190. }
  8191. sprintf(message,"[%d,\"%s\",%s]"
  8192. ,MESSAGE_TYPE_CALLRESULT
  8193. ,uuid
  8194. ,json_object_to_json_string_ext(GetConfiguration, JSON_C_TO_STRING_PLAIN));
  8195. json_object_put(GetConfiguration);
  8196. LWS_Send(message);
  8197. return result;
  8198. }
  8199. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8200. {
  8201. mtrace();
  8202. int result = FAIL;
  8203. char message[400]={0};
  8204. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8205. if(strcmp(payload,"")==0)
  8206. {
  8207. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8208. }
  8209. else
  8210. {
  8211. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8212. }
  8213. LWS_Send(message);
  8214. result = TRUE;
  8215. return result;
  8216. }
  8217. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8218. {
  8219. mtrace();
  8220. int result = FAIL;
  8221. char message[80]={0};
  8222. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8223. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8224. LWS_Send(message);
  8225. result = TRUE;
  8226. return result;
  8227. }
  8228. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8229. {
  8230. mtrace();
  8231. int result = FAIL;
  8232. char message[80]={0};
  8233. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8234. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8235. LWS_Send(message);
  8236. result = TRUE;
  8237. return result;
  8238. }
  8239. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8240. {
  8241. mtrace();
  8242. int result = FAIL;
  8243. char message[80]={0};
  8244. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8245. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8246. LWS_Send(message);
  8247. result = TRUE;
  8248. return result;
  8249. }
  8250. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8251. {
  8252. mtrace();
  8253. int result = FAIL;
  8254. char message[80]={0};
  8255. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8256. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8257. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8258. LWS_Send(message);
  8259. result = TRUE;
  8260. return result;
  8261. }
  8262. int sendResetConfirmation(char *uuid,char *payload)
  8263. {
  8264. mtrace();
  8265. int result = FAIL;
  8266. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8267. char message[80]={0};
  8268. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8269. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8270. LWS_Send(message);
  8271. result = TRUE;
  8272. return result;
  8273. }
  8274. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8275. {
  8276. mtrace();
  8277. int result = FAIL;
  8278. char message[500]={0};
  8279. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8280. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8281. LWS_Send(message);
  8282. result = TRUE;
  8283. return result;
  8284. }
  8285. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8286. {
  8287. mtrace();
  8288. int result = FAIL;
  8289. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8290. char message[80]={0};
  8291. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8292. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8293. LWS_Send(message);
  8294. result = TRUE;
  8295. return result;
  8296. }
  8297. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8298. {
  8299. mtrace();
  8300. int result = FAIL;
  8301. char message[80]={0};
  8302. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8303. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8304. LWS_Send(message);
  8305. result = TRUE;
  8306. return result;
  8307. }
  8308. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8309. {
  8310. mtrace();
  8311. int result = FAIL;
  8312. char message[80]={0};
  8313. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8314. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8315. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8316. LWS_Send(message);
  8317. result = TRUE;
  8318. return result;
  8319. }
  8320. int sendUpdateFirmwareConfirmation(char *uuid)
  8321. {
  8322. mtrace();
  8323. int result = FAIL;
  8324. char message[60]={0};
  8325. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8326. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8327. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8328. LWS_Send(message);
  8329. result = TRUE;
  8330. return result;
  8331. }
  8332. int sendCertificateSignedConfirmation(char *uuid)
  8333. {
  8334. mtrace();
  8335. int result = PASS;
  8336. char message[4096]={0};
  8337. json_object *CertificateSigned = json_object_new_object();
  8338. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8339. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8340. sprintf(message,"[%d,\"%s\",%s]"
  8341. ,MESSAGE_TYPE_CALLRESULT
  8342. ,uuid
  8343. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8344. json_object_put(CertificateSigned);
  8345. LWS_Send(message);
  8346. return result;
  8347. }
  8348. int sendDeleteCertificateConfirmation(char *uuid)
  8349. {
  8350. mtrace();
  8351. int result = PASS;
  8352. char message[4096]={0};
  8353. json_object *DeleteCertificate = json_object_new_object();
  8354. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8355. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8356. sprintf(message,"[%d,\"%s\",%s]"
  8357. ,MESSAGE_TYPE_CALLRESULT
  8358. ,uuid
  8359. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8360. json_object_put(DeleteCertificate);
  8361. LWS_Send(message);
  8362. return result;
  8363. }
  8364. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8365. {
  8366. mtrace();
  8367. int result = PASS;
  8368. char message[4096]={0};
  8369. json_object *ExtendedTriggerMessage = json_object_new_object();
  8370. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8371. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8372. sprintf(message,"[%d,\"%s\",%s]"
  8373. ,MESSAGE_TYPE_CALLRESULT
  8374. ,uuid
  8375. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8376. json_object_put(ExtendedTriggerMessage);
  8377. LWS_Send(message);
  8378. return result;
  8379. }
  8380. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8381. {
  8382. mtrace();
  8383. int result = PASS;
  8384. char message[4096]={0};
  8385. json_object *GetInstalledCertificateIds = json_object_new_object();
  8386. json_object *certificateHashDataDatas = json_object_new_array();
  8387. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8388. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8389. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8390. {
  8391. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8392. {
  8393. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm) > 0)
  8394. {
  8395. json_object *certificateHashData = json_object_new_object();
  8396. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8397. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8398. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8399. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8400. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8401. }
  8402. }
  8403. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8404. }
  8405. else
  8406. {
  8407. json_object_put(certificateHashDataDatas);
  8408. }
  8409. sprintf(message,"[%d,\"%s\",%s]"
  8410. ,MESSAGE_TYPE_CALLRESULT
  8411. ,uuid
  8412. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8413. json_object_put(GetInstalledCertificateIds);
  8414. LWS_Send(message);
  8415. return result;
  8416. }
  8417. int sendGetLogConfirmation(char *uuid)
  8418. {
  8419. mtrace();
  8420. int result = PASS;
  8421. char message[4096]={0};
  8422. json_object *GetLog = json_object_new_object();
  8423. DEBUG_INFO("sendGetLogConfirmation...\n");
  8424. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8425. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8426. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8427. sprintf(message,"[%d,\"%s\",%s]"
  8428. ,MESSAGE_TYPE_CALLRESULT
  8429. ,uuid
  8430. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8431. json_object_put(GetLog);
  8432. LWS_Send(message);
  8433. return result;
  8434. }
  8435. int sendInstallCertificateConfirmation(char *uuid)
  8436. {
  8437. mtrace();
  8438. int result = PASS;
  8439. char message[4096]={0};
  8440. json_object *InstallCertificate = json_object_new_object();
  8441. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8442. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8443. sprintf(message,"[%d,\"%s\",%s]"
  8444. ,MESSAGE_TYPE_CALLRESULT
  8445. ,uuid
  8446. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8447. json_object_put(InstallCertificate);
  8448. LWS_Send(message);
  8449. return result;
  8450. }
  8451. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8452. {
  8453. mtrace();
  8454. int result = PASS;
  8455. char message[4096]={0};
  8456. json_object *SignedUpdateFirmware = json_object_new_object();
  8457. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8458. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8459. sprintf(message,"[%d,\"%s\",%s]"
  8460. ,MESSAGE_TYPE_CALLRESULT
  8461. ,uuid
  8462. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8463. json_object_put(SignedUpdateFirmware);
  8464. LWS_Send(message);
  8465. return result;
  8466. }
  8467. int sendUnknownConfirmation(char *uuid)
  8468. {
  8469. mtrace();
  8470. int result = PASS;
  8471. char message[256]={0};
  8472. DEBUG_INFO("sendUnknownConfirmation...\n");
  8473. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8474. LWS_Send(message);
  8475. return result;
  8476. }
  8477. //==========================================
  8478. // Handle server request routine Start
  8479. //==========================================
  8480. int handleCancelReservationRequest(char *uuid, char *payload)
  8481. {
  8482. mtrace();
  8483. int result = FAIL;
  8484. int gunNO = 0;
  8485. int reservationIdInt = -1;
  8486. char comfirmstr[20];
  8487. DEBUG_INFO("handleCancelReservationRequest...\n");
  8488. json_object *CancelReservation;
  8489. CancelReservation = json_tokener_parse(payload);
  8490. if(!is_error(CancelReservation))
  8491. {
  8492. // Required data
  8493. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8494. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8495. }
  8496. json_object_put(CancelReservation);
  8497. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8498. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8499. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8500. if(reservationIdInt != -1)
  8501. {
  8502. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8503. //check Transaction active
  8504. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8505. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8506. {
  8507. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8508. {
  8509. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8510. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8511. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8512. {
  8513. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8514. }
  8515. else
  8516. {
  8517. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8518. }
  8519. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8520. goto end;
  8521. }
  8522. }
  8523. for (int index = 0; index < CCS_QUANTITY; index++)
  8524. {
  8525. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8526. {
  8527. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8528. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8529. if(gunType[2] == GUN_TYPE_CCS)
  8530. {
  8531. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8532. }
  8533. else
  8534. {
  8535. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8536. }
  8537. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8538. goto end;
  8539. }
  8540. }
  8541. for (int index = 0; index < GB_QUANTITY; index++)
  8542. {
  8543. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8544. {
  8545. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8546. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8547. if(gunType[2] == GUN_TYPE_GBT)
  8548. {
  8549. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8550. }
  8551. else
  8552. {
  8553. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8554. }
  8555. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8556. goto end;
  8557. }
  8558. }
  8559. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8560. {
  8561. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8562. {
  8563. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8564. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8565. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8566. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8567. goto end;
  8568. }
  8569. }
  8570. for (int index = 0; index < AC_QUANTITY; index++)
  8571. {
  8572. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8573. {
  8574. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8575. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8576. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8577. {
  8578. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8579. }
  8580. else
  8581. {
  8582. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8583. }
  8584. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8585. goto end;
  8586. }
  8587. }
  8588. }
  8589. //The reservationId does NOT match the reservationId
  8590. sendCancelReservationConfirmation(uuid, comfirmstr);
  8591. end:
  8592. // Fill in ocpp packet uuid
  8593. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8594. return result;
  8595. }
  8596. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8597. {
  8598. mtrace();
  8599. int result = FAIL;
  8600. int gunIndex = -1;
  8601. char typeStr[16]={0};
  8602. char comfirmstr[20];
  8603. int specificId = FALSE;
  8604. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8605. json_object *ChangeAvailability;
  8606. ChangeAvailability = json_tokener_parse(payload);
  8607. if(!is_error(ChangeAvailability))
  8608. {
  8609. // Required data
  8610. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8611. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8612. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8613. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8614. }
  8615. json_object_put(ChangeAvailability);
  8616. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8617. {
  8618. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8619. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8620. }
  8621. else if(gunIndex == 0)
  8622. {
  8623. for(int i=0; i < gunTotalNumber; i++)
  8624. {
  8625. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8626. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8627. }
  8628. }
  8629. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8630. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8631. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8632. {
  8633. specificId = TRUE;
  8634. }
  8635. if(specificId == FALSE)
  8636. goto end;
  8637. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8638. {
  8639. //----------------------gunIndex is 0 ------------------------------------------------//
  8640. if(gunIndex == 0)
  8641. {
  8642. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8643. {
  8644. for(int i=0; i < gunTotalNumber; i++)
  8645. {
  8646. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8647. {
  8648. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8649. {
  8650. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8651. {
  8652. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8653. goto end;
  8654. }
  8655. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8656. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8657. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8658. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8659. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8660. {
  8661. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8662. goto end;
  8663. }
  8664. }
  8665. }//END FOR CHAdeMO_QUANTITY
  8666. for (int index = 0; index < CCS_QUANTITY; index++)
  8667. {
  8668. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8669. {
  8670. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8671. {
  8672. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8673. goto end;
  8674. }
  8675. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8676. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8677. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8678. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8679. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8680. {
  8681. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8682. goto end;
  8683. }
  8684. }
  8685. }//END FOR CCS_QUANTITY
  8686. for (int index = 0; index < GB_QUANTITY; index++)
  8687. {
  8688. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8689. {
  8690. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8691. {
  8692. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8693. goto end;
  8694. }
  8695. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8696. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8697. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8698. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8699. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8700. {
  8701. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8702. goto end;
  8703. }
  8704. }
  8705. }// END FOR GB_QUANTITY
  8706. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8707. {
  8708. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8709. {
  8710. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8711. {
  8712. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8713. goto end;
  8714. }
  8715. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8716. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8717. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8718. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8719. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8720. {
  8721. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8722. goto end;
  8723. }
  8724. }
  8725. }// END FOR GENERAL_GUN_QUANTITY
  8726. for (int index = 0; index < AC_QUANTITY; index++)
  8727. {
  8728. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8729. {
  8730. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8731. {
  8732. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8733. goto end;
  8734. }
  8735. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8736. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8737. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8738. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8739. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8740. {
  8741. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8742. goto end;
  8743. }
  8744. }
  8745. }//END FOR AC_QUANTITY
  8746. }// END FOR gunTotalNumber
  8747. }
  8748. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8749. {
  8750. for(int i=0; i < gunTotalNumber; i++)
  8751. {
  8752. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8753. {
  8754. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8755. goto end;
  8756. }
  8757. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8758. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8759. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8760. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8761. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8762. {
  8763. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8764. goto end;
  8765. }
  8766. }
  8767. }
  8768. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8769. goto end;
  8770. }
  8771. //----------------------gunIndex is not 0 ------------------------------------------------//
  8772. //check Transaction active
  8773. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8774. {
  8775. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8776. {
  8777. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8778. {
  8779. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8780. goto end;
  8781. }
  8782. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8783. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8784. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8785. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8786. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8787. {
  8788. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8789. goto end;
  8790. }
  8791. else
  8792. {
  8793. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8794. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8795. goto end;
  8796. }
  8797. }
  8798. }//END FOR CHAdeMO_QUANTITY
  8799. for (int index = 0; index < CCS_QUANTITY; index++)
  8800. {
  8801. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8802. {
  8803. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8804. {
  8805. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8806. goto end;
  8807. }
  8808. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8809. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8810. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8811. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8812. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8813. {
  8814. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8815. goto end;
  8816. }
  8817. else
  8818. {
  8819. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8820. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8821. goto end;
  8822. }
  8823. }
  8824. }//END FOR CCS_QUANTITY
  8825. for (int index = 0; index < GB_QUANTITY; index++)
  8826. {
  8827. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8828. {
  8829. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8830. {
  8831. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8832. goto end;
  8833. }
  8834. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8835. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8836. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8837. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8838. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8839. {
  8840. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8841. goto end;
  8842. }
  8843. else
  8844. {
  8845. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8846. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8847. goto end;
  8848. }
  8849. }
  8850. }// END FOR GB_QUANTITY
  8851. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8852. {
  8853. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8854. {
  8855. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8856. {
  8857. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8858. goto end;
  8859. }
  8860. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8861. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8862. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8863. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8864. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8865. {
  8866. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8867. goto end;
  8868. }
  8869. else
  8870. {
  8871. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8872. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8873. goto end;
  8874. }
  8875. }
  8876. }// END FOR GENERAL_GUN_QUANTITY
  8877. for (int index = 0; index < AC_QUANTITY; index++)
  8878. {
  8879. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8880. {
  8881. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8882. {
  8883. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8884. goto end;
  8885. }
  8886. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8887. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8888. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8889. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8890. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8891. {
  8892. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8893. goto end;
  8894. }
  8895. else
  8896. {
  8897. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8898. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8899. goto end;
  8900. }
  8901. }
  8902. }//END FOR AC_QUANTITY
  8903. }//END FOR AvailabilityTypeStr[Inoperative]
  8904. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8905. {
  8906. //----------------------gunIndex is 0 ------------------------------------------------//
  8907. if(gunIndex == 0)
  8908. {
  8909. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8910. {
  8911. for(int i=0; i < gunTotalNumber; i++)
  8912. {
  8913. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8914. {
  8915. 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
  8916. {
  8917. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8918. goto end;
  8919. }
  8920. }//END FOR CHAdeMO_QUANTITY
  8921. for (int index = 0; index < CCS_QUANTITY; index++)
  8922. {
  8923. 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
  8924. {
  8925. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8926. goto end;
  8927. }
  8928. }//END FOR CCS_QUANTITY
  8929. for (int index = 0; index < GB_QUANTITY; index++)
  8930. {
  8931. 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
  8932. {
  8933. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8934. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8935. goto end;
  8936. }
  8937. }// END FOR GB_QUANTITY
  8938. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8939. {
  8940. 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
  8941. {
  8942. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8943. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8944. goto end;
  8945. }
  8946. }// END FOR GENERAL_GUN_QUANTITY
  8947. for (int index = 0; index < AC_QUANTITY; index++)
  8948. {
  8949. 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
  8950. {
  8951. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8952. goto end;
  8953. }
  8954. }//END FOR CHAdeMO_QUANTITY
  8955. }// END FOR gunTotalNumber
  8956. }
  8957. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8958. {
  8959. for(int i=0; i < gunTotalNumber; i++)
  8960. {
  8961. for (int index = 0; index < AC_QUANTITY; index++)
  8962. {
  8963. 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
  8964. {
  8965. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8966. goto end;
  8967. }
  8968. }//END FOR CHAdeMO_QUANTITY
  8969. } // END FOR gunTotalNumber
  8970. }
  8971. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8972. goto end;
  8973. }
  8974. //----------------------gunIndex is not 0 ------------------------------------------------//
  8975. //check Transaction active
  8976. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8977. {
  8978. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8979. {
  8980. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8981. goto end;
  8982. }
  8983. }//END FOR CHAdeMO_QUANTITY
  8984. for (int index = 0; index < CCS_QUANTITY; index++)
  8985. {
  8986. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8987. {
  8988. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8989. goto end;
  8990. }
  8991. }//END FOR CCS_QUANTITY
  8992. for (int index = 0; index < GB_QUANTITY; index++)
  8993. {
  8994. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8995. {
  8996. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8997. goto end;
  8998. }
  8999. }// END FOR GB_QUANTITY
  9000. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9001. {
  9002. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9003. {
  9004. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9005. goto end;
  9006. }
  9007. }// END FOR GENERAL_GUN_QUANTITY
  9008. for (int index = 0; index < AC_QUANTITY; index++)
  9009. {
  9010. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9011. {
  9012. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9013. goto end;
  9014. }
  9015. }//END FOR AC_QUANTITY
  9016. }//END FOR AvailabilityTypeStr[Operative]
  9017. end:
  9018. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9019. {
  9020. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  9021. }
  9022. else
  9023. {
  9024. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  9025. }
  9026. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9027. {
  9028. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9029. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9030. }
  9031. else if(gunIndex == 0)
  9032. {
  9033. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9034. {
  9035. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  9036. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  9037. }
  9038. }
  9039. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  9040. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9041. return result;
  9042. }
  9043. int handleChangeConfigurationRequest(char *uuid, char *payload)
  9044. {
  9045. mtrace();
  9046. int valueInvalid = NO;
  9047. int result = FAIL;
  9048. char keystr[40]={0};
  9049. char valuestr[501]={0}; //value should be limited in 500 bytes
  9050. char comfirmstr[20]={0};
  9051. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  9052. json_object *ChangeConfiguration;
  9053. ChangeConfiguration = json_tokener_parse(payload);
  9054. if(!is_error(ChangeConfiguration))
  9055. {
  9056. // Required data
  9057. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  9058. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  9059. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  9060. {
  9061. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  9062. }
  9063. else
  9064. {
  9065. valueInvalid = YES;
  9066. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  9067. }
  9068. }
  9069. json_object_put(ChangeConfiguration);
  9070. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  9071. {
  9072. DEBUG_ERROR("Payload is null or value is invalid.\n");
  9073. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9074. }
  9075. else
  9076. {
  9077. int status = setKeyValue(keystr, valuestr);
  9078. switch(status)
  9079. {
  9080. case ConfigurationStatus_Accepted:
  9081. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  9082. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  9083. StoreConfigurationTable();
  9084. break;
  9085. case RebootRequired:
  9086. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  9087. StoreConfigurationTable();
  9088. break;
  9089. case NotSupported:
  9090. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  9091. break;
  9092. case ConfigurationStatus_Rejected:
  9093. default:
  9094. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9095. break;
  9096. }
  9097. }
  9098. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  9099. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  9100. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9101. {
  9102. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9103. SetOcppConnStatus(FALSE);
  9104. }
  9105. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9106. {
  9107. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9108. }
  9109. return result;
  9110. }
  9111. int handleClearCacheRequest(char *uuid, char *payload)
  9112. {
  9113. mtrace();
  9114. int result = FAIL;
  9115. char comfirmstr[20];
  9116. char rmFileCmd[100]={0};
  9117. struct stat stats;
  9118. DEBUG_INFO("handleClearCacheRequest...\n");
  9119. stat("/Storage/OCPP", &stats);
  9120. // Check for directory existence
  9121. if (S_ISDIR(stats.st_mode) == 1)
  9122. {}
  9123. else
  9124. {
  9125. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  9126. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  9127. system(rmFileCmd);
  9128. }
  9129. if(OCPP_cleanLocalCache())
  9130. {
  9131. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  9132. }
  9133. else
  9134. {
  9135. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  9136. }
  9137. sendClearCacheConfirmation(uuid, comfirmstr);
  9138. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9139. return result;
  9140. }
  9141. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9142. {
  9143. mtrace();
  9144. int result = FAIL;
  9145. int resultRename;
  9146. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9147. char chargingProfilePurposeStr[26]={0};
  9148. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9149. char tempchargingProfilePurposeStr[26]={0};
  9150. char str[100]={0};
  9151. char fname[200]={0};
  9152. char comfirmstr[20]={0};
  9153. char word[1600]={0};
  9154. int clearflag = FALSE;
  9155. int chargingProfileIdIsNULL = FALSE;
  9156. int connectorIsNULL = FALSE;
  9157. int chargingProfilePurposeIsNULL = FALSE;
  9158. int stackLevelIsNULL = FALSE;
  9159. //int GotoEnd = FALSE;
  9160. FILE *fptr1, *fptr2;
  9161. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9162. int n_chargingProfile=0;
  9163. int isEmptyFile = FALSE;
  9164. char sLineWord[1600]={0};
  9165. char chargingProfiles[10][100]={0};
  9166. int ChargeProfileCount = 0;
  9167. int ch;
  9168. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9169. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9170. json_object *ClearChargingProfile;
  9171. ClearChargingProfile = json_tokener_parse(payload);
  9172. if(!is_error(ClearChargingProfile))
  9173. {
  9174. // Optional data
  9175. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9176. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9177. else
  9178. chargingProfileIdIsNULL = TRUE;
  9179. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9180. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9181. else
  9182. connectorIsNULL = TRUE;
  9183. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9184. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9185. else
  9186. chargingProfilePurposeIsNULL = TRUE;
  9187. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9188. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9189. else
  9190. stackLevelIsNULL = TRUE;
  9191. }
  9192. json_object_put(ClearChargingProfile);
  9193. if(connectorIdInt > 0)
  9194. {
  9195. if(chargingProfilePurposeIsNULL == TRUE)
  9196. {
  9197. int m = 0;
  9198. memset(fname, 0, ARRAY_SIZE(fname));
  9199. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9200. if((access(fname,F_OK))!=-1)
  9201. {
  9202. strcpy(chargingProfiles[m], fname);
  9203. m = m + 1;
  9204. }
  9205. memset(fname, 0, ARRAY_SIZE(fname));
  9206. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9207. if((access(fname,F_OK))!=-1)
  9208. {
  9209. strcpy(chargingProfiles[m], fname);
  9210. m = m + 1;
  9211. }
  9212. ChargeProfileCount = m;
  9213. }
  9214. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9215. {
  9216. //strcpy(fname, TxDefaultProfile_1_JSON);
  9217. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9218. if((access(fname,F_OK))!=-1)
  9219. {
  9220. strcpy(chargingProfiles[0], fname);
  9221. ChargeProfileCount = 1;
  9222. }
  9223. }
  9224. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9225. {
  9226. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9227. if((access(fname,F_OK))!=-1)
  9228. {
  9229. strcpy(chargingProfiles[0], fname);
  9230. ChargeProfileCount = 1;
  9231. }
  9232. //strcpy(fname, TxProfile_1_JSON);
  9233. }
  9234. }
  9235. else // Check all Charging Profiles
  9236. {
  9237. int i = 0;
  9238. char fnametemp[200]={0};
  9239. ChargeProfileCount = 0;
  9240. //Check ChargePointMaxProfile.json exit
  9241. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9242. {
  9243. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9244. i = i + 1;
  9245. }
  9246. //Check TxDefaultProfile_0.json exit
  9247. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9248. {
  9249. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9250. i = i + 1;
  9251. }
  9252. //Check TxDefaultProfile_%d.json
  9253. for(int j=1; j <= gunTotalNumber; j++)
  9254. {
  9255. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9256. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9257. if((access(fnametemp,F_OK))!=-1)
  9258. {
  9259. strcpy(chargingProfiles[i], fnametemp);
  9260. i = i + 1;
  9261. }
  9262. }
  9263. //Check TxProfile_%d.json
  9264. for(int j=1; j <= gunTotalNumber; j++)
  9265. {
  9266. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9267. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9268. if((access(fnametemp,F_OK))!=-1)
  9269. {
  9270. strcpy(chargingProfiles[i], fnametemp);
  9271. i = i + 1;
  9272. }
  9273. }
  9274. ChargeProfileCount = i;
  9275. }// End connectorIsNULL is TRUE
  9276. if(ChargeProfileCount == 0)
  9277. {
  9278. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9279. goto end;
  9280. }
  9281. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9282. {
  9283. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9284. goto end;
  9285. }
  9286. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9287. {
  9288. memset(str, 0, ARRAY_SIZE(str));
  9289. // clear temp file
  9290. sprintf(str,"rm -f %s",temp);
  9291. system(str);
  9292. for(int k=0; k < ChargeProfileCount; k++)
  9293. {
  9294. memset(str, 0, ARRAY_SIZE(str));
  9295. //clear file in C
  9296. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9297. system(str);
  9298. }
  9299. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9300. goto end;
  9301. }
  9302. else if(connectorIsNULL == TRUE)
  9303. {
  9304. for(int k=0; k < ChargeProfileCount; k++)
  9305. {
  9306. fptr1 = fopen(chargingProfiles[k], "r");
  9307. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9308. //Check Charging Profile Count
  9309. while(fscanf(fptr1, "%s", word) != EOF)
  9310. {
  9311. //DEBUG_INFO("word=%s\n",word);
  9312. if(strstr(word, "chargingProfileId")!= NULL)
  9313. {
  9314. //DEBUG_INFO("test chargingProfileId \n");
  9315. n_chargingProfile = n_chargingProfile + 1;
  9316. //DEBUG_INFO("chargingProfileId Found\n");
  9317. }
  9318. }
  9319. rewind(fptr1);
  9320. //search Charging Profile Element
  9321. //int i= 0;
  9322. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9323. {
  9324. json_object *tmpProfilee;
  9325. tmpProfilee = json_tokener_parse(sLineWord);
  9326. if(!is_error(tmpProfilee))
  9327. {
  9328. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9329. {
  9330. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9331. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9332. }
  9333. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9334. {
  9335. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9336. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9337. }
  9338. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9339. {
  9340. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9341. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9342. }
  9343. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9344. {
  9345. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9346. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9347. }
  9348. }
  9349. json_object_put(tmpProfilee);
  9350. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9351. {
  9352. //------- not write to fptr2-------//
  9353. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9354. //clearflag = TRUE;
  9355. }
  9356. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9357. {
  9358. //------- not write to fptr2-------//
  9359. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9360. }
  9361. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9362. {
  9363. //------- not write to fptr2-------//
  9364. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9365. }
  9366. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9367. {
  9368. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9369. }
  9370. else
  9371. {
  9372. fprintf(fptr2, sLineWord);//writing data into file
  9373. }
  9374. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9375. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9376. if(clearflag == TRUE)
  9377. {
  9378. fclose(fptr1);
  9379. fclose(fptr2);
  9380. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9381. system(str);
  9382. // clear temp file
  9383. sprintf(str,"rm -f %s",temp);
  9384. system(str);
  9385. }
  9386. else
  9387. {
  9388. fclose(fptr1);
  9389. fclose(fptr2);
  9390. memset(str, 0, ARRAY_SIZE(str));
  9391. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9392. system(str);
  9393. resultRename = rename(temp, chargingProfiles[k]);
  9394. if(resultRename == 0)
  9395. {
  9396. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9397. }
  9398. else
  9399. {
  9400. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9401. }
  9402. if(comfirmstr[0]== 0)
  9403. {
  9404. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9405. }
  9406. //Check chargingProfile is empty file
  9407. /*------ Read the file ----------------*/
  9408. fptr1=fopen(chargingProfiles[k],"r");
  9409. ch=fgetc(fptr1);
  9410. rewind(fptr1);
  9411. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9412. if(ch!=EOF)
  9413. {
  9414. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9415. {
  9416. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9417. if(sLineWord[0]=='\0')
  9418. {
  9419. isEmptyFile = TRUE;
  9420. break;
  9421. }
  9422. else
  9423. {
  9424. isEmptyFile = FALSE;
  9425. break;
  9426. }
  9427. }
  9428. }
  9429. else
  9430. isEmptyFile = TRUE;
  9431. fclose(fptr1);
  9432. if(isEmptyFile == TRUE)
  9433. {
  9434. memset(str, 0, ARRAY_SIZE(str));
  9435. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9436. system(str);
  9437. }
  9438. }
  9439. }// End of while(int k=0; k < ChargePointCount; k++)
  9440. }
  9441. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9442. {
  9443. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9444. for(int k=0; k < ChargeProfileCount; k++)
  9445. {
  9446. fptr1 = fopen(chargingProfiles[k], "r");
  9447. fptr2 = fopen(temp, "w+");
  9448. //Check Charging Profile Count
  9449. while(fscanf(fptr1, "%s", word) != EOF)
  9450. {
  9451. //DEBUG_INFO("word=%s\n",word);
  9452. if(strstr(word, "chargingProfileId")!= NULL)
  9453. {
  9454. n_chargingProfile = n_chargingProfile + 1;
  9455. }
  9456. }
  9457. rewind(fptr1);
  9458. //search Charging Profile Element
  9459. //int i= 0;
  9460. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9461. {
  9462. json_object *tmpProfilee;
  9463. tmpProfilee = json_tokener_parse(sLineWord);
  9464. if(!is_error(tmpProfilee))
  9465. {
  9466. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9467. {
  9468. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9469. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9470. }
  9471. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9472. {
  9473. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9474. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9475. }
  9476. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9477. {
  9478. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9479. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9480. }
  9481. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9482. {
  9483. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9484. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9485. }
  9486. }
  9487. json_object_put(tmpProfilee);
  9488. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9489. {
  9490. //------- not write to fptr2-------//
  9491. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9492. //clearflag = TRUE;
  9493. }
  9494. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9495. {
  9496. //------- not write to fptr2-------//
  9497. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9498. }
  9499. else if(stackLevelIsNULL == TRUE)
  9500. {
  9501. //Clear Whole File
  9502. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9503. clearflag = TRUE;
  9504. break;
  9505. }
  9506. else
  9507. {
  9508. fprintf(fptr2, sLineWord);//writing data into file
  9509. }
  9510. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9511. }
  9512. if(clearflag == TRUE)
  9513. {
  9514. fclose(fptr1);
  9515. fclose(fptr2);
  9516. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9517. system(str);
  9518. // clear temp file
  9519. sprintf(str,"rm -f %s",temp);
  9520. system(str);
  9521. }
  9522. else
  9523. {
  9524. fclose(fptr1);
  9525. fclose(fptr2);
  9526. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9527. system(str);
  9528. resultRename = rename(temp, chargingProfiles[k]);
  9529. if(resultRename == 0)
  9530. {
  9531. DEBUG_INFO("File ChargingProfile renamed successfully");
  9532. }
  9533. else
  9534. {
  9535. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9536. }
  9537. if(comfirmstr[0]== 0)
  9538. {
  9539. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9540. }
  9541. //Check chargingProfile is empty file
  9542. /*------ Read the file ----------------*/
  9543. fptr1=fopen(chargingProfiles[k],"r");
  9544. ch=fgetc(fptr1);
  9545. rewind(fptr1);
  9546. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9547. if(ch!=EOF)
  9548. {
  9549. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9550. {
  9551. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9552. if(sLineWord[0]=='\0')
  9553. {
  9554. isEmptyFile = TRUE;
  9555. break;
  9556. }
  9557. else
  9558. {
  9559. isEmptyFile = FALSE;
  9560. break;
  9561. }
  9562. }
  9563. }
  9564. else
  9565. isEmptyFile = TRUE;
  9566. fclose(fptr1);
  9567. if(isEmptyFile == TRUE)
  9568. {
  9569. memset(str, 0, ARRAY_SIZE(str));
  9570. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9571. system(str);
  9572. }
  9573. /*------- End of reading ---------------*/
  9574. }
  9575. } // while(int k=0; k < ChargeProfileCount; k++)
  9576. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9577. end:
  9578. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9579. {
  9580. if(connectorIdInt == 0)
  9581. {
  9582. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9583. {
  9584. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9585. }
  9586. }
  9587. else
  9588. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9589. }
  9590. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9591. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9592. return result;
  9593. }
  9594. void createFirmwareVersionByDataTransfer(void)
  9595. {
  9596. json_object *FirmwareDataTransfer = json_object_new_object();
  9597. // AC & DC model
  9598. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9599. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9600. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9601. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9602. // DC model
  9603. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9604. {
  9605. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9606. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9607. (gunType[3] != GUN_TYPE_UNKNOWN))
  9608. {
  9609. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9610. }
  9611. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9612. {
  9613. // DS DM DW
  9614. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9615. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9616. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9617. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9618. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9619. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9620. }
  9621. else
  9622. {
  9623. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9624. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9625. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9626. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9627. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9628. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9629. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9630. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9631. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9632. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9633. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9634. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9635. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9636. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9637. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9638. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9639. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9640. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9641. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9642. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9643. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9644. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9645. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9646. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9647. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9648. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9649. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9650. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9651. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9652. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9653. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9654. }
  9655. }
  9656. // 4G model
  9657. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9658. {
  9659. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9660. }
  9661. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9662. json_object_put(FirmwareDataTransfer);
  9663. }
  9664. int handleDataTransferRequest(char *uuid, char *payload)
  9665. {
  9666. mtrace();
  9667. json_object *response = json_object_new_object();
  9668. int result = FAIL;
  9669. char tempvendorId[255]={0};
  9670. char tempmessageId[50]={0};
  9671. char tempdata[10240]={0};
  9672. char message[20480]={0};
  9673. DEBUG_INFO("handleDataTransferRequest...\n");
  9674. if((uuid != NULL) && (payload != NULL))
  9675. {
  9676. json_object *DataTransfer;
  9677. DataTransfer = json_tokener_parse(payload);
  9678. if(!is_error(DataTransfer))
  9679. {
  9680. // Required data
  9681. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9682. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9683. // Optional data
  9684. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9685. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9686. if(json_object_object_get(DataTransfer, "data") != NULL)
  9687. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9688. result = PASS;
  9689. }
  9690. json_object_put(DataTransfer);
  9691. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9692. {
  9693. // Send all moudle firmware version on EVSE
  9694. createFirmwareVersionByDataTransfer();
  9695. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9696. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9697. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9698. json_object_put(response);
  9699. }
  9700. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9701. {
  9702. system("/usr/bin/run_tmate_restart.sh &");
  9703. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9704. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9705. json_object_put(response);
  9706. }
  9707. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9708. {
  9709. json_object *data;
  9710. data = json_tokener_parse(tempdata);
  9711. if(!is_error(data))
  9712. {
  9713. 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))
  9714. {
  9715. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9716. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9717. if(json_object_object_get(data, "SOC") != NULL)
  9718. {
  9719. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9720. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9721. }
  9722. if(json_object_object_get(data, "Energy") != NULL)
  9723. {
  9724. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9725. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9726. }
  9727. if(json_object_object_get(data, "Duration") != NULL)
  9728. {
  9729. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9730. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9731. }
  9732. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9733. }
  9734. else
  9735. {
  9736. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9737. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9738. }
  9739. }
  9740. else
  9741. {
  9742. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9743. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9744. }
  9745. json_object_put(data);
  9746. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9747. json_object_put(response);
  9748. }
  9749. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9750. {
  9751. json_object *data;
  9752. data = json_tokener_parse(tempdata);
  9753. if(!is_error(data))
  9754. {
  9755. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9756. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9757. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9758. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9759. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9760. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9761. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9762. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9763. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9764. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9765. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9766. }
  9767. else
  9768. {
  9769. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9770. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9771. }
  9772. json_object_put(data);
  9773. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9774. json_object_put(response);
  9775. }
  9776. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9777. {
  9778. json_object *data;
  9779. data = json_tokener_parse(tempdata);
  9780. if(!is_error(data))
  9781. {
  9782. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9783. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9784. if(json_object_object_get(data, "idToken") != NULL)
  9785. {
  9786. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9787. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9788. }
  9789. else
  9790. {
  9791. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9792. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9793. }
  9794. if(json_object_object_get(data, "price") != NULL) //v1.0
  9795. {
  9796. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9797. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9798. }
  9799. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9800. {
  9801. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9802. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9803. }
  9804. else
  9805. {
  9806. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9807. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9808. }
  9809. }
  9810. else
  9811. {
  9812. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9813. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9814. }
  9815. json_object_put(data);
  9816. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9817. json_object_put(response);
  9818. }
  9819. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9820. {
  9821. json_object *data;
  9822. data = json_tokener_parse(tempdata);
  9823. if(!is_error(data))
  9824. {
  9825. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9826. if(json_object_object_get(data, "txId") != NULL)
  9827. {
  9828. // California pricing V1.0
  9829. DEBUG_INFO("California pricing V1.0\n");
  9830. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9831. sprintf((char*)dmsVersion, "1.0");
  9832. for(int idx = 0;idx<gunTotalNumber;idx++)
  9833. {
  9834. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9835. {
  9836. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9837. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9838. if(json_object_object_get(data, "description") != NULL)
  9839. {
  9840. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9841. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9842. }
  9843. else
  9844. {
  9845. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9846. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9847. }
  9848. }
  9849. }
  9850. }
  9851. else if(json_object_object_get(data, "transactionId") != NULL)
  9852. {
  9853. // California pricing V2.0
  9854. DEBUG_INFO("California pricing V2.0\n");
  9855. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9856. sprintf((char*)dmsVersion, "2.0");
  9857. for(int idx=0;idx<gunTotalNumber;idx++)
  9858. {
  9859. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9860. {
  9861. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9862. if(json_object_object_get(data, "timestamp") != NULL)
  9863. {
  9864. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9865. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9866. }
  9867. else
  9868. {
  9869. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9870. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9871. }
  9872. if(json_object_object_get(data, "meterValue") != NULL)
  9873. {
  9874. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9875. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9876. }
  9877. else
  9878. {
  9879. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9880. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9881. }
  9882. if(json_object_object_get(data, "cost") != NULL)
  9883. {
  9884. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9885. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9886. }
  9887. else
  9888. {
  9889. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9890. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9891. }
  9892. if(json_object_object_get(data, "state") != NULL)
  9893. {
  9894. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9895. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9896. }
  9897. else
  9898. {
  9899. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9900. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9901. }
  9902. if(json_object_object_get(data, "chargingPrice") != NULL)
  9903. {
  9904. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9905. {
  9906. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9907. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9908. }
  9909. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9910. {
  9911. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9912. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9913. }
  9914. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9915. {
  9916. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9917. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9918. }
  9919. }
  9920. else
  9921. {
  9922. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9923. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9924. }
  9925. if(json_object_object_get(data, "idlePrice") != NULL)
  9926. {
  9927. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9928. {
  9929. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9930. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9931. }
  9932. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9933. {
  9934. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9935. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9936. }
  9937. }
  9938. if(json_object_object_get(data, "nextPeriod") != NULL)
  9939. {
  9940. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9941. {
  9942. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9943. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9944. }
  9945. else
  9946. {
  9947. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9948. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9949. }
  9950. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9951. {
  9952. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9953. {
  9954. 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")));
  9955. 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"));
  9956. }
  9957. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9958. {
  9959. 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")));
  9960. 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"));
  9961. }
  9962. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9963. {
  9964. 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")));
  9965. 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"));
  9966. }
  9967. }
  9968. else
  9969. {
  9970. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9971. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9972. }
  9973. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9974. {
  9975. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9976. {
  9977. 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")));
  9978. 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"));
  9979. }
  9980. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9981. {
  9982. 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")));
  9983. 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"));
  9984. }
  9985. }
  9986. }
  9987. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9988. {
  9989. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9990. {
  9991. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9992. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9993. }
  9994. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9995. {
  9996. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9997. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9998. }
  9999. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  10000. {
  10001. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  10002. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  10003. }
  10004. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  10005. {
  10006. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10007. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10008. }
  10009. }
  10010. }
  10011. }
  10012. }
  10013. else
  10014. {
  10015. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10016. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10017. }
  10018. }
  10019. else
  10020. {
  10021. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10022. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10023. }
  10024. json_object_put(data);
  10025. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10026. json_object_put(response);
  10027. }
  10028. else if(strstr(tempmessageId, "FinalCost") != NULL)
  10029. {
  10030. json_object *data;
  10031. data = json_tokener_parse(tempdata);
  10032. if(!is_error(data))
  10033. {
  10034. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10035. if(json_object_object_get(data, "txId") != NULL)
  10036. {
  10037. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  10038. for(int idx = 0;idx<gunTotalNumber;idx++)
  10039. {
  10040. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10041. {
  10042. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10043. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  10044. if(json_object_object_get(data, "description") != NULL)
  10045. {
  10046. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  10047. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  10048. }
  10049. else
  10050. {
  10051. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10052. json_object_object_add(response, "data", json_object_new_string("description not found."));
  10053. }
  10054. }
  10055. }
  10056. }
  10057. else if(json_object_object_get(data, "transactionId") != NULL)
  10058. {
  10059. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  10060. for(int idx = 0;idx<gunTotalNumber;idx++)
  10061. {
  10062. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  10063. {
  10064. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10065. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10066. if(json_object_object_get(data, "cost") != NULL)
  10067. {
  10068. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  10069. ShmOCPP16Data->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10070. }
  10071. else
  10072. {
  10073. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10074. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10075. }
  10076. if(json_object_object_get(data, "priceText") != NULL)
  10077. {
  10078. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10079. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10080. }
  10081. else
  10082. {
  10083. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10084. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  10085. }
  10086. if(json_object_object_get(data, "qrCodeText") != NULL)
  10087. {
  10088. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10089. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10090. }
  10091. }
  10092. }
  10093. }
  10094. else
  10095. {
  10096. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10097. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10098. }
  10099. }
  10100. else
  10101. {
  10102. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10103. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10104. }
  10105. json_object_put(data);
  10106. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10107. json_object_put(response);
  10108. }
  10109. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  10110. {
  10111. json_object *data;
  10112. data = json_tokener_parse(tempdata);
  10113. if(!is_error(data))
  10114. {
  10115. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10116. if(json_object_object_get(data, "Content_Type") != NULL)
  10117. {
  10118. 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))
  10119. {
  10120. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10121. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10122. {
  10123. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10124. }
  10125. }
  10126. else
  10127. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10128. }
  10129. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10130. }
  10131. else
  10132. {
  10133. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10134. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10135. }
  10136. json_object_put(data);
  10137. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10138. json_object_put(response);
  10139. }
  10140. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  10141. {
  10142. json_object *data;
  10143. data = json_tokener_parse(tempdata);
  10144. if(!is_error(data))
  10145. {
  10146. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10147. if(json_object_object_get(data, "ConnectorId") != NULL)
  10148. {
  10149. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  10150. }
  10151. if(json_object_object_get(data, "SerialNo") != NULL)
  10152. {
  10153. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  10154. }
  10155. if(json_object_object_get(data, "Page_Index") != NULL)
  10156. {
  10157. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10158. }
  10159. if(json_object_object_get(data, "Duration") != NULL)
  10160. {
  10161. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10162. }
  10163. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  10164. }
  10165. else
  10166. {
  10167. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10168. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10169. }
  10170. json_object_put(data);
  10171. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10172. json_object_put(response);
  10173. }
  10174. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  10175. {
  10176. json_object *data;
  10177. data = json_tokener_parse(tempdata);
  10178. if(!is_error(data))
  10179. {
  10180. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10181. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10182. {
  10183. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10184. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10185. else
  10186. {
  10187. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10188. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10189. }
  10190. }
  10191. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10192. {
  10193. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10194. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10195. else
  10196. {
  10197. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10198. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10199. }
  10200. }
  10201. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  10202. {
  10203. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  10204. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  10205. else
  10206. {
  10207. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10208. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10209. }
  10210. }
  10211. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  10212. {
  10213. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  10214. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  10215. else
  10216. {
  10217. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10218. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10219. }
  10220. }
  10221. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10222. {
  10223. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10224. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10225. else
  10226. {
  10227. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10228. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10229. }
  10230. }
  10231. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10232. {
  10233. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10234. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10235. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10236. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10237. else
  10238. {
  10239. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10240. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10241. }
  10242. }
  10243. if(json_object_object_get(data, "isAuthentication") != NULL)
  10244. {
  10245. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10246. {
  10247. case 0:
  10248. case 1:
  10249. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10250. break;
  10251. default:
  10252. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10253. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10254. break;
  10255. }
  10256. }
  10257. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10258. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10259. }
  10260. else
  10261. {
  10262. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10263. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10264. }
  10265. json_object_put(data);
  10266. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10267. json_object_put(response);
  10268. }
  10269. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10270. {
  10271. json_object *data;
  10272. data = json_tokener_parse(tempdata);
  10273. if(!is_error(data))
  10274. {
  10275. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10276. {
  10277. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10278. {
  10279. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10280. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10281. }
  10282. else
  10283. {
  10284. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10285. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10286. }
  10287. }
  10288. else
  10289. {
  10290. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10291. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10292. }
  10293. }
  10294. else
  10295. {
  10296. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10297. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10298. }
  10299. json_object_put(data);
  10300. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10301. json_object_put(response);
  10302. }
  10303. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10304. {
  10305. json_object *data;
  10306. data = json_tokener_parse(tempdata);
  10307. if(!is_error(data))
  10308. {
  10309. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10310. if(json_object_object_get(data, "stationName") != NULL)
  10311. {
  10312. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10313. }
  10314. else
  10315. {
  10316. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10317. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10318. }
  10319. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10320. {
  10321. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10322. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10323. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10324. }
  10325. }
  10326. else
  10327. {
  10328. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10329. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10330. }
  10331. json_object_put(data);
  10332. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10333. json_object_put(response);
  10334. }
  10335. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10336. {
  10337. json_object *data;
  10338. data = json_tokener_parse(tempdata);
  10339. if(!is_error(data))
  10340. {
  10341. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10342. if(json_object_object_get(data, "weatherId") != NULL)
  10343. {
  10344. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10345. }
  10346. else
  10347. {
  10348. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10349. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10350. }
  10351. if(json_object_object_get(data, "Temperature") != NULL)
  10352. {
  10353. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10354. }
  10355. else
  10356. {
  10357. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10358. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10359. }
  10360. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10361. {
  10362. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10363. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10364. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10365. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10366. );
  10367. }
  10368. }
  10369. else
  10370. {
  10371. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10372. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10373. }
  10374. json_object_put(data);
  10375. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10376. json_object_put(response);
  10377. }
  10378. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10379. {
  10380. json_object *data;
  10381. data = json_tokener_parse(tempdata);
  10382. if(!is_error(data))
  10383. {
  10384. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10385. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10386. {
  10387. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10388. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10389. }
  10390. else
  10391. {
  10392. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10393. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10394. }
  10395. }
  10396. else
  10397. {
  10398. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10399. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10400. }
  10401. json_object_put(data);
  10402. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10403. json_object_put(response);
  10404. }
  10405. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10406. {
  10407. json_object *data;
  10408. data = json_tokener_parse(tempdata);
  10409. if(!is_error(data))
  10410. {
  10411. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10412. {
  10413. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10414. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10415. if(gun_index < gunTotalNumber)
  10416. {
  10417. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10418. {
  10419. json_object *responsedata = json_object_new_object();
  10420. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10421. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10422. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10423. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10424. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10425. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10426. }
  10427. else
  10428. {
  10429. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10430. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10431. }
  10432. }
  10433. else
  10434. {
  10435. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10436. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10437. }
  10438. }
  10439. else
  10440. {
  10441. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10442. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10443. }
  10444. }
  10445. else
  10446. {
  10447. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10448. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10449. }
  10450. json_object_put(data);
  10451. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10452. json_object_put(response);
  10453. }
  10454. else if(strstr(tempmessageId, "ID_OccupancyFeeDisplay") != NULL)
  10455. {
  10456. json_object *data;
  10457. data = json_tokener_parse(tempdata);
  10458. if(!is_error(data))
  10459. {
  10460. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10461. int gun_index = 0;
  10462. if(json_object_object_get(data, "ConnectorId") != NULL)
  10463. {
  10464. gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10465. if(json_object_object_get(data, "occupancySN") != NULL)
  10466. {
  10467. sprintf((char *)ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].occupancySN, "%s", json_object_get_string(json_object_object_get(data,"occupancySN")));
  10468. }
  10469. else
  10470. {
  10471. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10472. json_object_object_add(response, "data", json_object_new_string("occupancySN data can not get."));
  10473. }
  10474. if(json_object_object_get(data, "actionId") != NULL)
  10475. {
  10476. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].actionId = json_object_get_int(json_object_object_get(data,"actionId"));
  10477. }
  10478. else
  10479. {
  10480. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10481. json_object_object_add(response, "data", json_object_new_string("actionId data can not get."));
  10482. }
  10483. }
  10484. else
  10485. {
  10486. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10487. json_object_object_add(response, "data", json_object_new_string("ConnectorId data can not get."));
  10488. }
  10489. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10490. {
  10491. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].OccupancyFeeDisplayReq = 1;
  10492. }
  10493. }
  10494. else
  10495. {
  10496. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10497. json_object_object_add(response, "data", json_object_new_string("OccupancyFeeDisplay content got something wrong."));
  10498. }
  10499. json_object_put(data);
  10500. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10501. json_object_put(response);
  10502. }
  10503. else if(strstr(tempmessageId, "ID_SetOccupancyPrice") != NULL)
  10504. {
  10505. json_object *data;
  10506. data = json_tokener_parse(tempdata);
  10507. if(!is_error(data))
  10508. {
  10509. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10510. if(json_object_object_get(data, "price") != NULL)
  10511. {
  10512. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.price = json_object_get_double(json_object_object_get(data,"price"));
  10513. }
  10514. else
  10515. {
  10516. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10517. json_object_object_add(response, "data", json_object_new_string("price data can not get."));
  10518. }
  10519. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10520. {
  10521. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.SetOccupancyPriceReq = 1;
  10522. }
  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("SetOccupancyPrice content got something wrong."));
  10528. }
  10529. json_object_put(data);
  10530. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10531. json_object_put(response);
  10532. }
  10533. // Support ISO-15118 related message
  10534. else if(strstr(tempmessageId, "TriggerMessage") != NULL)
  10535. {
  10536. char cmdBuf[1024]={0};
  10537. 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);
  10538. system(cmdBuf);
  10539. ShmOCPP16Data->v2g_extend.SignCertificateReq = 1;
  10540. json_object *responsedata = json_object_new_object();
  10541. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10542. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10543. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10544. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10545. json_object_put(response);
  10546. }
  10547. else if(strstr(tempmessageId, "CertificateSigned") != NULL)
  10548. {
  10549. json_object *data;
  10550. data = json_tokener_parse(tempdata);
  10551. if(!is_error(data))
  10552. {
  10553. FILE *fp = fopen(CERTIFICATE_V2G, "w");
  10554. fprintf(fp, "%s", json_object_get_string(json_object_object_get(data, "certificateChain")));
  10555. fclose(fp);
  10556. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10557. json_object *responsedata = json_object_new_object();
  10558. if(certVerify(PRIVATE_KEY_V2G, CERTIFICATE_V2G) == PASS)
  10559. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10560. else
  10561. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10562. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10563. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10564. }
  10565. else
  10566. {
  10567. json_object *responsedata = json_object_new_object();
  10568. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10569. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10570. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10571. }
  10572. json_object_put(data);
  10573. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10574. json_object_put(response);
  10575. }
  10576. else if(strstr(tempmessageId, "DeleteCertificate") != NULL)
  10577. {
  10578. json_object *data;
  10579. data = json_tokener_parse(tempdata);
  10580. DEBUG_INFO("DeleteCertificate processing...\n");
  10581. if(!is_error(data))
  10582. {
  10583. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm") != NULL)
  10584. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm")));
  10585. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash") != NULL)
  10586. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash")));
  10587. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash") != NULL)
  10588. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash")));
  10589. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber") != NULL)
  10590. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber")));
  10591. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm);
  10592. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash);
  10593. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash);
  10594. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber);
  10595. char temp[256] = {0};
  10596. char compareData[256] = {0};
  10597. int isMatch = TRUE;
  10598. // Check certV2G
  10599. if(access(CERTIFICATE_V2G,F_OK) != -1)
  10600. {
  10601. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_SerialNumber, compareData);
  10602. if(strcmp(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber) != 0)
  10603. isMatch = FALSE;
  10604. if(isMatch == TRUE)
  10605. {
  10606. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerNameHash, compareData);
  10607. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  10608. isMatch = FALSE;
  10609. }
  10610. if(isMatch == TRUE)
  10611. {
  10612. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerKeyHash, compareData);
  10613. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  10614. isMatch = FALSE;
  10615. }
  10616. if(isMatch == TRUE)
  10617. {
  10618. sprintf(temp, "rm -f %s", CERTIFICATE_V2G);
  10619. system(temp);
  10620. json_object *responsedata = json_object_new_object();
  10621. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10622. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10623. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10624. }
  10625. else
  10626. {
  10627. json_object *responsedata = json_object_new_object();
  10628. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10629. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10630. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10631. }
  10632. }
  10633. else
  10634. {
  10635. json_object *responsedata = json_object_new_object();
  10636. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10637. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10638. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10639. }
  10640. }
  10641. else
  10642. {
  10643. json_object *responsedata = json_object_new_object();
  10644. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10645. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10646. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10647. }
  10648. json_object_put(data);
  10649. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10650. json_object_put(response);
  10651. }
  10652. else if(strstr(tempmessageId, "GetInstalledCertificateIds") != NULL)
  10653. {
  10654. json_object *data;
  10655. data = json_tokener_parse(tempdata);
  10656. if(!is_error(data))
  10657. {
  10658. /*
  10659. * TODO:
  10660. * 1. Query certificate to response
  10661. */
  10662. json_object *responsedata = json_object_new_object();
  10663. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10664. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10665. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10666. }
  10667. else
  10668. {
  10669. json_object *responsedata = json_object_new_object();
  10670. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10671. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10672. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10673. }
  10674. json_object_put(data);
  10675. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10676. json_object_put(response);
  10677. }
  10678. else if(strstr(tempmessageId, "InstallCertificate") != NULL)
  10679. {
  10680. json_object *data;
  10681. data = json_tokener_parse(tempdata);
  10682. if(!is_error(data))
  10683. {
  10684. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  10685. if(json_object_object_get(data, "certificateType") != NULL)
  10686. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(data, "certificateType")));
  10687. if(json_object_object_get(data, "certificate") != NULL)
  10688. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(data, "certificate")));
  10689. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType);
  10690. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10691. char temp[1024];
  10692. FILE *fp = fopen(tempCert, "w");
  10693. fprintf(fp, "%s", ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10694. fclose(fp);
  10695. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  10696. char strExpDate[30];
  10697. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  10698. fp = popen(temp, "r");
  10699. if(fp)
  10700. {
  10701. while(fgets(temp, sizeof(temp), fp) != NULL)
  10702. {
  10703. if(strstr(temp, "notAfter=") != NULL)
  10704. {
  10705. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  10706. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  10707. break;
  10708. }
  10709. }
  10710. }
  10711. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  10712. struct tm tmExpDate;
  10713. struct timeb tbExpDate;
  10714. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  10715. tbExpDate.time = mktime(&tmExpDate);
  10716. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  10717. {
  10718. DEBUG_INFO("The enddate is already expired...\n");
  10719. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Rejected");
  10720. }
  10721. else
  10722. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted");
  10723. if(strcmp((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted") == 0)
  10724. {
  10725. if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "V2GRootCertificate") != NULL)
  10726. {
  10727. if(access(ROOTCA_V2G,F_OK) != -1)
  10728. {
  10729. DEBUG_INFO("Existed V2GRootCertificate is found. Replacing...\n");
  10730. rename(ROOTCA_V2G, "/Storage/rootCaV2g_fallback.pem");
  10731. rename(tempCert, ROOTCA_V2G);
  10732. }
  10733. else
  10734. {
  10735. DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
  10736. rename(tempCert, ROOTCA_V2G);
  10737. }
  10738. json_object *responsedata = json_object_new_object();
  10739. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10740. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10741. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10742. }
  10743. else if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "MORootCertificate") != NULL)
  10744. {
  10745. if(access(ROOTCA_MO,F_OK) != -1)
  10746. {
  10747. DEBUG_INFO("Existed MORootCertificate is found. Replacing...\n");
  10748. rename(ROOTCA_MO, "/Storage/rootCaMo_fallback.pem");
  10749. rename(tempCert, ROOTCA_MO);
  10750. }
  10751. else
  10752. {
  10753. DEBUG_INFO("No existed MORootCertificate. Creating...\n");
  10754. rename(tempCert, ROOTCA_MO);
  10755. }
  10756. json_object *responsedata = json_object_new_object();
  10757. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10758. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10759. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10760. }
  10761. else
  10762. {
  10763. json_object *responsedata = json_object_new_object();
  10764. json_object_object_add(responsedata, "status", json_object_new_string("Failed"));
  10765. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10766. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10767. }
  10768. }
  10769. else
  10770. {
  10771. json_object *responsedata = json_object_new_object();
  10772. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10773. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10774. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10775. }
  10776. }
  10777. else
  10778. {
  10779. json_object *responsedata = json_object_new_object();
  10780. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10781. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10782. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10783. }
  10784. json_object_put(data);
  10785. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10786. json_object_put(response);
  10787. }
  10788. else
  10789. {
  10790. // Can not find valid message id
  10791. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10792. }
  10793. }
  10794. else
  10795. {
  10796. // Payload is null
  10797. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10798. }
  10799. LWS_Send(message);
  10800. return result;
  10801. }
  10802. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10803. {
  10804. mtrace();
  10805. int result = FAIL;
  10806. int connectorIdInt, durationInt;
  10807. char chargingRateUnitStr[4]={0};
  10808. char comfirmstr[20];
  10809. int confirmPeriods = 0;
  10810. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10811. json_object *GetCompositeSchedule;
  10812. GetCompositeSchedule = json_tokener_parse(payload);
  10813. if(!is_error(GetCompositeSchedule))
  10814. {
  10815. // Required data
  10816. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10817. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10818. else
  10819. connectorIdInt = -1;
  10820. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10821. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10822. else
  10823. durationInt = 86400;
  10824. // Optional data
  10825. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10826. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10827. }
  10828. json_object_put(GetCompositeSchedule);
  10829. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10830. if((connectorIdInt == 0) ||
  10831. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10832. {
  10833. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10834. struct StructChargingProfile tmpProfile[1];
  10835. if(strstr(chargingRateUnitStr, "W") != NULL)
  10836. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10837. else
  10838. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10839. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10840. {
  10841. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10842. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10843. }
  10844. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10845. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10846. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10847. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10848. {
  10849. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10850. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10851. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10852. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10853. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10854. {
  10855. confirmPeriods = idx;
  10856. break;
  10857. }
  10858. }
  10859. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10860. {
  10861. confirmPeriods += 1;
  10862. }
  10863. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10864. }
  10865. else
  10866. {
  10867. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10868. }
  10869. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10870. return result;
  10871. }
  10872. int handleGetConfigurationRequest(char *uuid, char *payload)
  10873. {
  10874. mtrace();
  10875. int result = FAIL;
  10876. int MaxKeySupported = 0;
  10877. int n_keys = 0;
  10878. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10879. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10880. json_object *GetConfiguration;
  10881. GetConfiguration = json_tokener_parse(payload);
  10882. if(!is_error(GetConfiguration))
  10883. {
  10884. // Optional data
  10885. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10886. {
  10887. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10888. {
  10889. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10890. n_keys = idx + 1;
  10891. }
  10892. }
  10893. }
  10894. json_object_put(GetConfiguration);
  10895. UnknownKeynum = 0;
  10896. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10897. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10898. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10899. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10900. if(n_keys != 0)
  10901. {
  10902. for(int i=0;i<n_keys;i++)
  10903. {
  10904. getKeyValue(requestKey[i]);
  10905. }
  10906. }
  10907. else
  10908. {
  10909. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10910. getKeyValue("");
  10911. }
  10912. processUnkownKey();
  10913. sendGetConfigurationConfirmation(uuid);
  10914. return result;
  10915. }
  10916. static char fnamePlusPath[100]={0};
  10917. static char fnamePWithNoPath[60]={0};
  10918. void checkUploadLog(void)
  10919. {
  10920. FILE *fp;
  10921. /* Open the command for reading. */
  10922. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10923. if (fp == NULL) {
  10924. DEBUG_WARN("Failed to run command\n" );
  10925. exit(1);
  10926. }
  10927. int ftppathlen = 0;
  10928. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10929. int i = 0;
  10930. /* Read the output a line at a time - output it. */
  10931. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10932. if(i==0)
  10933. {
  10934. ftppathlen = strlen(fnamePlusPath);
  10935. DEBUG_INFO("%s\n", fnamePlusPath);
  10936. fnamePlusPath[ftppathlen]='\0';
  10937. break;
  10938. }
  10939. i= i+1;
  10940. }
  10941. /* close */
  10942. pclose(fp);
  10943. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10944. {
  10945. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10946. {
  10947. fnamePlusPath[k]='\0';
  10948. }
  10949. }
  10950. i=1;
  10951. //char fname[60]={0};
  10952. while(i < ftppathlen)
  10953. {
  10954. int len=ftppathlen-i;
  10955. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10956. {
  10957. DEBUG_INFO("compare '/' all right\n");
  10958. break;
  10959. }
  10960. i=i+1;
  10961. }
  10962. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10963. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10964. fnamePWithNoPath[i+1] = '\0';
  10965. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10966. {
  10967. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10968. {
  10969. fnamePWithNoPath[j]='\0';
  10970. }
  10971. }
  10972. FILE* fp1 = fopen(fnamePlusPath, "r");
  10973. if (fp1)
  10974. {
  10975. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10976. // file exists
  10977. fclose(fp1);
  10978. }
  10979. else
  10980. {
  10981. // file doesn't exist
  10982. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10983. }
  10984. }
  10985. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  10986. {
  10987. mtrace();
  10988. int result = FAIL;
  10989. time_t CurrentTime;
  10990. struct tm *tm;
  10991. pthread_t th_Status;
  10992. CurrentTime = time(NULL);
  10993. tm = localtime(&CurrentTime);
  10994. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  10995. 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);
  10996. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  10997. if(!interLock.isGetDiagnosticGoing)
  10998. {
  10999. interLock.isGetDiagnosticGoing = 1;
  11000. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, payload);
  11001. sleep(1);
  11002. }
  11003. else
  11004. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  11005. return result;
  11006. }
  11007. void* GetDiagnosticsProcess(void* data)
  11008. {
  11009. pthread_detach(pthread_self());
  11010. mtrace();
  11011. int retriesInt=0, retryIntervalInt=0;
  11012. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  11013. 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};
  11014. int port=0;
  11015. int isSuccess = FALSE;
  11016. char cmdBuf[2048];
  11017. struct tm *tmNow;
  11018. time_t CurrentTime;
  11019. struct tm tmStart;
  11020. struct tm tmStop;
  11021. CurrentTime = time(NULL);
  11022. tmNow=localtime(&CurrentTime);
  11023. uint16_t targetYear, targetMonth;
  11024. json_object *GetDiagnostics;
  11025. DEBUG_INFO("GetDiagnosticsProcess...\n");
  11026. GetDiagnostics = json_tokener_parse(data);
  11027. if(!is_error(GetDiagnostics))
  11028. {
  11029. // Required data
  11030. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  11031. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  11032. // Optional data
  11033. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  11034. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  11035. else
  11036. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  11037. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  11038. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  11039. else
  11040. retryIntervalInt = 30;
  11041. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  11042. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  11043. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  11044. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  11045. }
  11046. json_object_put(GetDiagnostics);
  11047. // Notify CSU to get log of dispensers.
  11048. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  11049. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  11050. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  11051. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O') ||
  11052. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='L'))
  11053. )
  11054. {
  11055. sprintf((char *)ShmOCPP16Data->GetDiagnostics.StartTime,"%s",startTimestr);
  11056. sprintf((char *)ShmOCPP16Data->GetDiagnostics.StopTime,"%s",stopTimestr);
  11057. ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq = TRUE;
  11058. struct timespec timerGetDiagnostics;
  11059. refreshStartTimer(&timerGetDiagnostics);
  11060. while(ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq != FALSE)
  11061. {
  11062. if(getDiffSecNow(timerGetDiagnostics)>=180)
  11063. {
  11064. ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq = FALSE;
  11065. DEBUG_INFO("Waiting log of dispenser timeout.");
  11066. }
  11067. }
  11068. }
  11069. // Pack log to compress file
  11070. 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) &&
  11071. (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))
  11072. {
  11073. // Pack system log
  11074. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11075. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  11076. targetYear = tmStart.tm_year;
  11077. targetMonth = tmStart.tm_mon;
  11078. do
  11079. {
  11080. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11081. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  11082. if(targetMonth+1>=13)
  11083. {
  11084. targetYear += 1;
  11085. targetMonth = 1;
  11086. }
  11087. else
  11088. {
  11089. targetMonth += 1;
  11090. }
  11091. }while((targetYear < (tmNow->tm_year+1900)) ||
  11092. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11093. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  11094. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  11095. sprintf(cmdBuf, "%s /Storage/OCPP/TransactionRelatedQueue", cmdBuf);
  11096. sprintf(cmdBuf, "%s /Storage/OCPP/QueueTransactionId", cmdBuf);
  11097. sprintf(cmdBuf, "%s /Storage/OCPP/OCPPConfiguration", cmdBuf);
  11098. sprintf(cmdBuf, "%s /Storage/Dispenser*Log.zip", cmdBuf);
  11099. system(cmdBuf);
  11100. // Pack charging & event log
  11101. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11102. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  11103. targetYear = tmStart.tm_year;
  11104. targetMonth = tmStart.tm_mon;
  11105. do
  11106. {
  11107. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11108. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*Ocpp*MessageLog*", cmdBuf, targetYear, targetMonth);
  11109. if(targetMonth+1>=13)
  11110. {
  11111. targetYear += 1;
  11112. targetMonth = 1;
  11113. }
  11114. else
  11115. {
  11116. targetMonth += 1;
  11117. }
  11118. }while((targetYear < (tmNow->tm_year+1900)) ||
  11119. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11120. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  11121. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  11122. system(cmdBuf);
  11123. // Combine log file
  11124. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  11125. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  11126. }
  11127. else
  11128. {
  11129. system("exec /root/logPackTools 'log' 6");
  11130. }
  11131. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11132. system(cmdBuf);
  11133. checkUploadLog();
  11134. //****************location*******************/
  11135. if(strcmp(locationstr,"")==0)
  11136. {
  11137. DEBUG_INFO("location is <Empty>!\n");
  11138. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11139. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11140. goto end;
  11141. }
  11142. memset(protocol, 0, ARRAY_SIZE(protocol));
  11143. memset(user, 0, ARRAY_SIZE(user) );
  11144. memset(password, 0, ARRAY_SIZE(password));
  11145. memset(host, 0, ARRAY_SIZE(host));
  11146. memset(path, 0, ARRAY_SIZE(path));
  11147. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11148. memset(host1, 0, ARRAY_SIZE(host1));
  11149. memset(path1, 0, ARRAY_SIZE(path1));
  11150. /*location: ftp://user:password@host:port/path*/
  11151. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  11152. if((access(fnamePlusPath,F_OK))!=-1)
  11153. {
  11154. DEBUG_INFO("fnamePlusPath exist.\n");
  11155. }
  11156. else
  11157. {
  11158. DEBUG_INFO("fnamePlusPath not exist!\n");
  11159. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11160. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11161. goto end;
  11162. }
  11163. if(strchr(locationstr,'@')==NULL)
  11164. {
  11165. sscanf(locationstr,
  11166. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11167. protocol, host, &port, path);
  11168. strcpy(user,"anonymous");
  11169. strcpy(password,"");
  11170. }
  11171. else
  11172. {
  11173. //DEBUG_INFO("pch=%s\n", pch);
  11174. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11175. protocol, user, password, host, &port, path);
  11176. }
  11177. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  11178. {
  11179. DEBUG_INFO("protocol is not ftp/http ! \n");
  11180. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11181. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11182. goto end;
  11183. }
  11184. if(strncmp(locationstr,"http", 4) == 0)
  11185. {
  11186. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11187. sprintf(ftppath,"/%s", path);
  11188. do
  11189. {
  11190. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11191. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11192. sleep(3);
  11193. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  11194. if(!isSuccess)
  11195. {
  11196. DEBUG_INFO("Diagnostics fail.\n");
  11197. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11198. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11199. sleep(retryIntervalInt);
  11200. }
  11201. else
  11202. {
  11203. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11204. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11205. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11206. }
  11207. retriesInt--;
  11208. }while((isSuccess == 0)&&(retriesInt >= 0));
  11209. }
  11210. else
  11211. {
  11212. sscanf(host,"%[^/]%s",host1, path1);
  11213. if(strlen(path) > 0)
  11214. sprintf(ftppath,"/%s", path);
  11215. else
  11216. sprintf(ftppath,"/%s", path1);
  11217. int ftppathlen=strlen(ftppath);
  11218. int i=1;
  11219. char filenametemp[50];
  11220. while(i < ftppathlen)
  11221. {
  11222. int len=ftppathlen-i;
  11223. if(ftppath[len]== 47) // '/' ascll code: 47
  11224. {
  11225. DEBUG_INFO("find '/' all right\n");
  11226. break;
  11227. }
  11228. i=i+1;
  11229. }
  11230. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11231. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11232. filenametemp[i+1] = 0;
  11233. if(port == 0)
  11234. port = 21;
  11235. do
  11236. {
  11237. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11238. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11239. sleep(3);
  11240. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  11241. if(!isSuccess)
  11242. {
  11243. DEBUG_INFO("Diagnostics fail.\n");
  11244. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11245. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11246. sleep(retryIntervalInt);
  11247. }
  11248. else
  11249. {
  11250. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11251. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11252. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11253. }
  11254. retriesInt--;
  11255. }while((!isSuccess)&&(retriesInt >= 0));
  11256. }
  11257. end:
  11258. system("rm -f /mnt/*");
  11259. system("rm -f /Storage/Dispenser*Log.zip");
  11260. sleep(5);
  11261. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11262. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11263. interLock.isGetDiagnosticGoing = 0;
  11264. pthread_exit(NULL);
  11265. }
  11266. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  11267. {
  11268. mtrace();
  11269. int result = FAIL;
  11270. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  11271. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  11272. {
  11273. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  11274. locallistVersion = -1;
  11275. }
  11276. else
  11277. {
  11278. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  11279. locallistVersion = 0;
  11280. OCPP_getListVerion();
  11281. }
  11282. //from db.OCPP_getListVerion
  11283. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  11284. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  11285. sendGetLocalListVersionConfirmation(uuid,"");
  11286. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  11287. return result;
  11288. }
  11289. int handleRemoteStartRequest(char *uuid, char *payload)
  11290. {
  11291. mtrace();
  11292. int result = PASS;
  11293. int connectorIdInt=-1;
  11294. int tempIndex = 0;
  11295. char comfirmstr[20]={0};
  11296. char cmdBuf[512];
  11297. json_object *RemoteStartTransaction;
  11298. FILE *fp;
  11299. DEBUG_INFO("handleRemoteStartRequest ...\n");
  11300. if(server_pending == TRUE)
  11301. {
  11302. result = FAIL;
  11303. }
  11304. RemoteStartTransaction = json_tokener_parse(payload);
  11305. if(!is_error(RemoteStartTransaction))
  11306. {
  11307. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  11308. {
  11309. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  11310. }
  11311. else
  11312. {
  11313. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11314. {
  11315. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  11316. {
  11317. connectorIdInt = (gun_index+1);
  11318. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  11319. break;
  11320. }
  11321. }
  11322. }
  11323. if(connectorIdInt == 0)
  11324. {
  11325. DEBUG_WARN("Connector id shall not equal 0.\n");
  11326. result = FAIL;
  11327. }
  11328. else if(json_object_object_get(RemoteStartTransaction, "idTag") == NULL)
  11329. {
  11330. DEBUG_WARN("idTag should not be NULL.\n");
  11331. result = FAIL;
  11332. }
  11333. else if(connectorIdInt == -1)
  11334. {
  11335. DEBUG_INFO("Connector id does not specific.\n");
  11336. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11337. {
  11338. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11339. // Required data
  11340. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11341. // Optional data
  11342. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11343. {
  11344. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11345. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11346. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11347. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11348. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11349. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11350. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11351. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11352. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11353. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11354. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11355. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11356. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11357. {
  11358. 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")));
  11359. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11360. 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"));
  11361. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11362. 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"));
  11363. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11364. 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")));
  11365. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11366. {
  11367. 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++)
  11368. {
  11369. 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"));
  11370. 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"));
  11371. 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)
  11372. 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"));
  11373. }
  11374. }
  11375. }
  11376. }
  11377. else
  11378. {
  11379. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11380. }
  11381. }
  11382. }
  11383. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11384. {
  11385. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11386. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11387. // Required data
  11388. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11389. // Optional data
  11390. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11391. {
  11392. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11393. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11394. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11395. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11396. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11397. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11398. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11399. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11400. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11401. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11402. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11403. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11404. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11405. {
  11406. 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")));
  11407. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11408. 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"));
  11409. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11410. 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"));
  11411. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11412. 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")));
  11413. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11414. {
  11415. 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++)
  11416. {
  11417. 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"));
  11418. 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"));
  11419. 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)
  11420. 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"));
  11421. }
  11422. }
  11423. }
  11424. }
  11425. else
  11426. {
  11427. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11428. }
  11429. if((ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D') && (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'W'))
  11430. {
  11431. DEBUG_INFO("Checking charging status for DW series...\n");
  11432. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11433. {
  11434. if(cpinitateMsg.bits[gun_index].isOnCharging ||
  11435. (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL) ||
  11436. (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing") != NULL))
  11437. {
  11438. DEBUG_INFO("Found gun-%d is in charging.\n", gun_index);
  11439. if(connectorIdInt != (gun_index+1))
  11440. {
  11441. DEBUG_WARN("DWseries--> Other connector is in charging.\n");
  11442. result = FAIL;
  11443. break;
  11444. }
  11445. }
  11446. }
  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. DEBUG_INFO("Specified gun-%d type: %d\n", (connectorIdInt -1), gunType[connectorIdInt -1]);
  11460. //check Transaction active
  11461. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11462. {
  11463. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11464. {
  11465. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11466. }
  11467. else
  11468. {
  11469. tempIndex = connectorIdInt -1;
  11470. }
  11471. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11472. {
  11473. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11474. {
  11475. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11476. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11477. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11478. {
  11479. //Reserved
  11480. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11481. }
  11482. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11483. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11484. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11485. {
  11486. //Reserved
  11487. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11488. {
  11489. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11490. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11491. goto end;
  11492. }
  11493. }
  11494. else
  11495. {
  11496. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11497. {
  11498. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11499. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11500. goto end;
  11501. }
  11502. }//END FOR ELSE
  11503. }
  11504. }// END FOR CHAdeMO_QUANTITY
  11505. }
  11506. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11507. {
  11508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11509. {
  11510. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11511. }
  11512. else
  11513. {
  11514. tempIndex = connectorIdInt -1;
  11515. }
  11516. for (int index = 0; index < CCS_QUANTITY; index++)
  11517. {
  11518. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11519. {
  11520. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11521. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11522. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11523. {
  11524. //Reserved
  11525. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11526. }
  11527. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11528. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11529. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11530. {
  11531. //Reserved
  11532. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11533. {
  11534. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11535. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11536. goto end;
  11537. }
  11538. }
  11539. else
  11540. {
  11541. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11542. {
  11543. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11544. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11545. goto end;
  11546. }
  11547. }// END FOR ELSE
  11548. }
  11549. }// END FOR CCS_QUANTITY
  11550. }
  11551. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11552. {
  11553. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11554. {
  11555. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11556. }
  11557. else
  11558. {
  11559. tempIndex = connectorIdInt -1;
  11560. }
  11561. for (int index = 0; index < GB_QUANTITY; index++)
  11562. {
  11563. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11564. {
  11565. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11566. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11567. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11568. {
  11569. //Reserved
  11570. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11571. }
  11572. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11573. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11574. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11575. {
  11576. //Reserved
  11577. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11578. {
  11579. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11580. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11581. goto end;
  11582. }
  11583. }
  11584. else
  11585. {
  11586. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11587. {
  11588. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11589. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11590. goto end;
  11591. }
  11592. }// END FOR ELSE
  11593. }
  11594. } // END FOR GB_QUANTITY
  11595. }
  11596. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11597. {
  11598. tempIndex = connectorIdInt -1;
  11599. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11600. {
  11601. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11602. {
  11603. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11604. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11605. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11606. {
  11607. //Reserved
  11608. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11609. }
  11610. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11611. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11612. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11613. {
  11614. //Reserved
  11615. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11616. {
  11617. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11618. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11619. goto end;
  11620. }
  11621. }
  11622. else
  11623. {
  11624. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11625. {
  11626. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11627. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11628. goto end;
  11629. }
  11630. }// END FOR ELSE
  11631. }
  11632. } // END FOR GB_QUANTITY
  11633. }
  11634. else
  11635. {
  11636. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11637. {
  11638. tempIndex = 2;
  11639. }
  11640. else
  11641. {
  11642. tempIndex = connectorIdInt -1;
  11643. }
  11644. for (int index = 0; index < AC_QUANTITY; index++)
  11645. {
  11646. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11647. {
  11648. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11649. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11650. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11651. {
  11652. //Reserved
  11653. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11654. }
  11655. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11656. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11657. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11658. {
  11659. //Reserved
  11660. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11661. {
  11662. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11663. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11664. goto end;
  11665. }
  11666. }
  11667. else
  11668. {
  11669. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11670. {
  11671. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11672. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11673. goto end;
  11674. }
  11675. }//END FOR ELSE
  11676. }
  11677. }// END FOR AC_QUANTITY
  11678. }
  11679. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11680. {
  11681. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11682. {
  11683. // Save profile to file
  11684. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11685. system(cmdBuf);
  11686. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11687. fp = fopen(cmdBuf, "w");
  11688. 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));
  11689. fclose(fp);
  11690. }
  11691. else
  11692. {
  11693. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11694. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11695. goto end;
  11696. }
  11697. }
  11698. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11699. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11700. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11701. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11702. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11703. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11704. }
  11705. else
  11706. {
  11707. uint8_t isHasIdleConnector = FALSE;
  11708. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11709. {
  11710. DEBUG_INFO("Check not specified gun-%d type: %d\n", gun_index, gunType[gun_index]);
  11711. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11712. {
  11713. isHasIdleConnector = TRUE;
  11714. break;
  11715. }
  11716. }
  11717. if((isHasIdleConnector == TRUE) && !ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11718. {
  11719. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11720. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11721. {
  11722. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11723. {
  11724. // Save profile to file
  11725. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11726. system(cmdBuf);
  11727. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11728. fp = fopen(cmdBuf, "w");
  11729. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11730. fclose(fp);
  11731. refreshStartTimer(&clientTime.RemoteStartWait);
  11732. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11733. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11734. }
  11735. else
  11736. {
  11737. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11738. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11739. }
  11740. }
  11741. else
  11742. {
  11743. refreshStartTimer(&clientTime.RemoteStartWait);
  11744. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11745. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11746. }
  11747. }
  11748. else
  11749. {
  11750. DEBUG_INFO("There is not any connector is idle.\n");
  11751. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11752. }
  11753. }
  11754. }
  11755. else
  11756. {
  11757. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11758. }
  11759. end:
  11760. json_object_put(RemoteStartTransaction);
  11761. sendRemoteStartConfirmation(uuid, comfirmstr);
  11762. return result;
  11763. }
  11764. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11765. {
  11766. mtrace();
  11767. int result = FAIL;
  11768. int match = FALSE;
  11769. int GunNO = 0;
  11770. int tempIndex = 0;
  11771. int transactionIdInt=0;
  11772. int transactionIdIsNULL= TRUE;
  11773. char comfirmstr[20];
  11774. json_object *RemoteStopTransaction;
  11775. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11776. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11777. if(server_pending == TRUE)
  11778. {
  11779. return 0;
  11780. }
  11781. RemoteStopTransaction = json_tokener_parse(payload);
  11782. if(!is_error(RemoteStopTransaction))
  11783. {
  11784. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11785. {
  11786. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11787. transactionIdIsNULL = FALSE;
  11788. }
  11789. }
  11790. json_object_put(RemoteStopTransaction);
  11791. if(transactionIdIsNULL == FALSE)
  11792. {
  11793. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11794. {
  11795. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11796. {
  11797. //check Transaction active
  11798. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11799. {
  11800. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11801. {
  11802. tempIndex = ((gun_index==2) ? 1: 0);
  11803. }
  11804. else
  11805. {
  11806. tempIndex = gun_index;
  11807. }
  11808. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11809. {
  11810. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11811. {
  11812. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11813. {
  11814. match = TRUE;
  11815. GunNO = gun_index;
  11816. }
  11817. }
  11818. }// END FOR CHAdeMO_QUANTITY
  11819. }
  11820. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11821. {
  11822. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11823. {
  11824. tempIndex = ((gun_index==2) ? 1: 0);
  11825. }
  11826. else
  11827. {
  11828. tempIndex = gun_index;
  11829. }
  11830. for (int index = 0; index < CCS_QUANTITY; index++)
  11831. {
  11832. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11833. {
  11834. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11835. {
  11836. match = TRUE;
  11837. GunNO = gun_index;
  11838. }
  11839. }
  11840. }// END FOR CCS_QUANTITY
  11841. }
  11842. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11843. {
  11844. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11845. {
  11846. tempIndex = ((gun_index==2) ? 1: 0);
  11847. }
  11848. else
  11849. {
  11850. tempIndex = gun_index;
  11851. }
  11852. for (int index = 0; index < GB_QUANTITY; index++)
  11853. {
  11854. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11855. {
  11856. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11857. {
  11858. match = TRUE;
  11859. GunNO = gun_index;
  11860. }
  11861. }
  11862. }// END FOR GB_QUANTITY
  11863. }
  11864. else if(gunType[gun_index] == GUN_TYPE_DO)
  11865. {
  11866. tempIndex = gun_index;
  11867. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11868. {
  11869. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11870. {
  11871. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11872. {
  11873. match = TRUE;
  11874. GunNO = gun_index;
  11875. }
  11876. }
  11877. }// END FOR GB_QUANTITY
  11878. }
  11879. else
  11880. {
  11881. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11882. {
  11883. tempIndex = 2;
  11884. }
  11885. else
  11886. {
  11887. tempIndex = gun_index;
  11888. }
  11889. for (int index = 0; index < AC_QUANTITY; index++)
  11890. {
  11891. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11892. {
  11893. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11894. {
  11895. match = TRUE;
  11896. GunNO = gun_index;
  11897. }
  11898. }
  11899. }// END FOR CHAdeMO_QUANTITY
  11900. } // END FOR AC ELSE
  11901. }// CHECK IF ResponseTransactionId == transactionIdInt
  11902. }//END FOR
  11903. if( match == TRUE)
  11904. {
  11905. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11906. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11907. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11908. }
  11909. else
  11910. {
  11911. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11912. }
  11913. }
  11914. else
  11915. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11916. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11917. return result;
  11918. }
  11919. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11920. {
  11921. mtrace();
  11922. int result = FAIL;
  11923. int connectorIdInt=0, reservationIdInt=0;
  11924. int tempIndex = 0;
  11925. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11926. char comfirmstr[20]={0};
  11927. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11928. int c = 0;
  11929. char *loc;
  11930. //char *ptr;
  11931. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11932. strcpy(sstrtemp, stringtrimspace(payload));
  11933. //***(1)connectorId ****/
  11934. c=0;
  11935. loc = strstr(sstrtemp, "connectorId");
  11936. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11937. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11938. {
  11939. sstr[c] = loc[strlen("connectorId")+2+c];
  11940. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11941. c++;
  11942. }
  11943. sstr[c] = '\0';
  11944. connectorIdInt = atoi(sstr);
  11945. //***(2)expiryDate ****/
  11946. loc = strstr(sstrtemp, "expiryDate");
  11947. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11948. c = 0;
  11949. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11950. {
  11951. sstr[c] = loc[3+strlen("expiryDate")+c];
  11952. c++;
  11953. }
  11954. sstr[c] = '\0';
  11955. strcpy(expiryDatestr, sstr);
  11956. //***(3)idTag ****/
  11957. loc = strstr(sstrtemp, "idTag");
  11958. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11959. c = 0;
  11960. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11961. {
  11962. sstr[c] = loc[3+strlen("idTag")+c];
  11963. c++;
  11964. }
  11965. sstr[c] = '\0';
  11966. strcpy(idTagstr, sstr);
  11967. //***(4)parentIdTag ****/
  11968. loc = strstr(sstrtemp, "parentIdTag");
  11969. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11970. c = 0;
  11971. if(loc == NULL)
  11972. {
  11973. strcpy(parentIdTagstr, "");
  11974. }
  11975. else
  11976. {
  11977. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11978. {
  11979. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11980. c++;
  11981. }
  11982. sstr[c] = '\0';
  11983. strcpy(parentIdTagstr, sstr);
  11984. }
  11985. //***(5)reservationId ****/
  11986. c=0;
  11987. loc = strstr(sstrtemp, "reservationId");
  11988. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11989. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11990. {
  11991. sstr[c] = loc[strlen("reservationId")+2+c];
  11992. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11993. c++;
  11994. }
  11995. sstr[c] = '\0';
  11996. reservationIdInt = atoi(sstr);
  11997. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11998. /*
  11999. enum SYSTEM_STATUS
  12000. {
  12001. SYS_MODE_BOOTING = 0,
  12002. SYS_MODE_IDLE = 1,
  12003. SYS_MODE_AUTHORIZING = 2,
  12004. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  12005. SYS_MODE_REASSIGN = 4,
  12006. SYS_MODE_PREPARING = 5,
  12007. SYS_MODE_PREPARE_FOR_EV = 6,
  12008. SYS_MODE_PREPARE_FOR_EVSE = 7,
  12009. SYS_MODE_CHARGING = 8,
  12010. SYS_MODE_TERMINATING = 9,
  12011. SYS_MODE_COMPLETE = 10,
  12012. SYS_MODE_ALARM = 11,
  12013. SYS_MODE_FAULT = 12,
  12014. SYS_MODE_RESERVATION = 13,
  12015. SYS_MODE_BOOKING = 14,
  12016. SYS_MODE_MAINTAIN = 15,
  12017. SYS_MODE_DEBUG = 16,
  12018. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  12019. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  12020. SYS_MODE_UPDATE = 19
  12021. };
  12022. */
  12023. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  12024. {
  12025. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12026. goto end;
  12027. }
  12028. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  12029. {
  12030. //check Transaction active
  12031. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  12032. {
  12033. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12034. {
  12035. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12036. }
  12037. else
  12038. {
  12039. tempIndex = connectorIdInt -1;
  12040. }
  12041. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12042. {
  12043. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12044. {
  12045. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12046. {
  12047. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12048. {
  12049. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12050. {
  12051. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  12052. {
  12053. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12054. }
  12055. else
  12056. {
  12057. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12058. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12059. }
  12060. }
  12061. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  12062. {
  12063. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12064. }
  12065. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12066. {
  12067. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12068. }
  12069. else
  12070. {
  12071. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12072. }
  12073. }
  12074. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_FAULT, SYS_MODE_ALARM, SYS_MODE_TERMINATING ---> SuspendedEV
  12075. {
  12076. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12077. }
  12078. }
  12079. else
  12080. {
  12081. //replace reservation
  12082. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12083. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12084. }
  12085. }
  12086. } // END FOR CHAdeMO_QUANTITY
  12087. }
  12088. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  12089. {
  12090. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12091. {
  12092. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12093. }
  12094. else
  12095. {
  12096. tempIndex = connectorIdInt -1;
  12097. }
  12098. for (int index = 0; index < CCS_QUANTITY; index++)
  12099. {
  12100. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12101. {
  12102. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12103. {
  12104. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12105. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12106. {
  12107. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12108. {
  12109. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  12110. {
  12111. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12112. }
  12113. else
  12114. {
  12115. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12116. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12117. }
  12118. }
  12119. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  12120. {
  12121. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12122. }
  12123. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  12124. {
  12125. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12126. }
  12127. else
  12128. {
  12129. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12130. }
  12131. }
  12132. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_ALARM) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAUL, SYS_MODE_TERMINATING ---> SuspendedEV
  12133. {
  12134. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12135. }
  12136. }
  12137. else
  12138. {
  12139. //replace reservation
  12140. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12141. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12142. }
  12143. }
  12144. } // END FOR CCS_QUANTITY
  12145. }
  12146. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  12147. {
  12148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12149. {
  12150. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12151. }
  12152. else
  12153. {
  12154. tempIndex = connectorIdInt -1;
  12155. }
  12156. for (int index = 0; index < GB_QUANTITY; index++)
  12157. {
  12158. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12159. {
  12160. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12161. {
  12162. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12163. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12164. {
  12165. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12166. {
  12167. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  12168. {
  12169. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12170. }
  12171. else
  12172. {
  12173. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12174. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12175. }
  12176. }
  12177. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  12178. {
  12179. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12180. }
  12181. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12182. {
  12183. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12184. }
  12185. else
  12186. {
  12187. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12188. }
  12189. }
  12190. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM ,SYS_MODE_TERMINATING ---> SuspendedEV
  12191. {
  12192. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12193. }
  12194. }
  12195. else
  12196. {
  12197. //replace reservation
  12198. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12199. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12200. }
  12201. }
  12202. }// END FOR GB_QUANTITY
  12203. }
  12204. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  12205. {
  12206. tempIndex = connectorIdInt -1;
  12207. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12208. {
  12209. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12210. {
  12211. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  12212. {
  12213. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12214. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12215. {
  12216. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12217. {
  12218. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  12219. {
  12220. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12221. }
  12222. else
  12223. {
  12224. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12225. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12226. }
  12227. }
  12228. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  12229. {
  12230. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12231. }
  12232. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12233. {
  12234. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12235. }
  12236. else
  12237. {
  12238. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12239. }
  12240. }
  12241. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM ,SYS_MODE_TERMINATING ---> SuspendedEV
  12242. {
  12243. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12244. }
  12245. }
  12246. else
  12247. {
  12248. //replace reservation
  12249. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12250. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12251. }
  12252. }
  12253. }// END FOR GB_QUANTITY
  12254. }
  12255. else
  12256. {
  12257. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12258. {
  12259. tempIndex = 2;
  12260. }
  12261. else
  12262. {
  12263. tempIndex = (connectorIdInt -1);
  12264. }
  12265. for (int index = 0; index < AC_QUANTITY; index++)
  12266. {
  12267. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12268. {
  12269. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12270. {
  12271. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12272. {
  12273. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12274. {
  12275. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  12276. {
  12277. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12278. }
  12279. else
  12280. {
  12281. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12282. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12283. }
  12284. }
  12285. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  12286. {
  12287. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12288. }
  12289. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12290. {
  12291. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12292. }
  12293. else
  12294. {
  12295. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12296. }
  12297. }
  12298. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM, SYS_MODE_TERMINATING ---> SuspendedEV
  12299. {
  12300. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12301. }
  12302. }
  12303. else
  12304. {
  12305. //replace reservation
  12306. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12307. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12308. }
  12309. }
  12310. } // END FOR AC_QUANTITY
  12311. }
  12312. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12313. }
  12314. else if(connectorIdInt == 0)
  12315. {
  12316. //check Transaction active
  12317. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12318. {
  12319. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12320. {
  12321. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  12322. {
  12323. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12324. goto end;
  12325. }
  12326. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12327. {
  12328. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12329. goto end;
  12330. }
  12331. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  12332. {
  12333. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12334. goto end;
  12335. }
  12336. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12337. {
  12338. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12339. goto end;
  12340. }
  12341. }
  12342. }// END FOR CHAdeMO_QUANTITY
  12343. for (int index = 0; index < CCS_QUANTITY; index++)
  12344. {
  12345. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12346. {
  12347. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  12348. {
  12349. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12350. goto end;
  12351. }
  12352. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12353. {
  12354. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12355. goto end;
  12356. }
  12357. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  12358. {
  12359. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12360. goto end;
  12361. }
  12362. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12363. {
  12364. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12365. goto end;
  12366. }
  12367. }
  12368. } // END FOR CCS_QUANTITY
  12369. for (int index = 0; index < GB_QUANTITY; index++)
  12370. {
  12371. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12372. {
  12373. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  12374. {
  12375. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12376. goto end;
  12377. }
  12378. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12379. {
  12380. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12381. goto end;
  12382. }
  12383. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_TERMINATING) ) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  12384. {
  12385. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12386. goto end;
  12387. }
  12388. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12389. {
  12390. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12391. goto end;
  12392. }
  12393. }
  12394. } // END FOR GB_QUANTITY
  12395. for (int index = 0; index < AC_QUANTITY; index++)
  12396. {
  12397. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12398. {
  12399. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  12400. {
  12401. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12402. goto end;
  12403. }
  12404. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12405. {
  12406. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12407. goto end;
  12408. }
  12409. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  12410. {
  12411. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12412. goto end;
  12413. }
  12414. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12415. {
  12416. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  12417. {
  12418. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12419. goto end;
  12420. }
  12421. }
  12422. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12423. {
  12424. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12425. goto end;
  12426. }
  12427. }
  12428. }// END FOR AC_QUANTITY
  12429. //The connectorId is 0
  12430. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12431. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12432. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12433. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12434. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12435. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12436. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12437. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12438. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12439. result = TRUE;
  12440. return result;
  12441. }
  12442. else
  12443. {
  12444. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12445. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12446. }
  12447. if(strcmp(comfirmstr,"Accepted") == 0)
  12448. {
  12449. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12450. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12451. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12452. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12453. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12454. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12455. result = TRUE;
  12456. return result;
  12457. }
  12458. end:
  12459. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12460. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12461. return result;
  12462. }
  12463. int handleResetRequest(char *uuid, char *payload)
  12464. {
  12465. mtrace();
  12466. int result = FAIL;
  12467. char sstr[10]={0},sstrtemp[30]={ 0 };
  12468. char typestr[10]={0};
  12469. char comfirmstr[20]={0};
  12470. int c = 0;
  12471. char *loc;
  12472. DEBUG_INFO("handleResetRequest...\n");
  12473. strcpy(sstrtemp, stringtrimspace(payload));
  12474. loc = strstr(sstrtemp, "type");
  12475. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12476. c = 0;
  12477. while (loc[3+strlen("type")+c] != '\"')
  12478. {
  12479. sstr[c] = loc[3+strlen("type")+c];
  12480. c++;
  12481. }
  12482. sstr[c] = '\0';
  12483. strcpy(typestr,sstr);
  12484. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12485. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12486. {
  12487. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12488. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12489. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12490. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12491. }
  12492. else
  12493. {
  12494. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12495. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12496. result = PASS;
  12497. }
  12498. sendResetConfirmation(uuid, comfirmstr);
  12499. return result;
  12500. }
  12501. int handleSendLocalListRequest(char *uuid, char *payload)
  12502. {
  12503. mtrace();
  12504. int result = FAIL;
  12505. char comfirmstr[20];
  12506. int checkState_Faulted = FALSE;
  12507. json_object *SendLocalList;
  12508. DEBUG_INFO("handleSendLocalListRequest...\n");
  12509. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12510. {
  12511. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12512. goto end;
  12513. }
  12514. //check Charge Point state
  12515. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12516. {
  12517. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12518. {
  12519. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12520. }
  12521. }
  12522. for (int index = 0; index < CCS_QUANTITY; index++)
  12523. {
  12524. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12525. {
  12526. checkState_Faulted = TRUE; //OCPP Status
  12527. }
  12528. }
  12529. for (int index = 0; index < GB_QUANTITY; index++)
  12530. {
  12531. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12532. {
  12533. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12534. }
  12535. }
  12536. //check Charge Point state
  12537. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12538. {
  12539. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12540. {
  12541. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12542. }
  12543. }
  12544. //check Charge Point state
  12545. for (int index = 0; index < AC_QUANTITY; index++)
  12546. {
  12547. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12548. {
  12549. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12550. }
  12551. }
  12552. if(checkState_Faulted == TRUE)
  12553. {
  12554. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12555. goto end;
  12556. }
  12557. // Parsing payload
  12558. SendLocalList = json_tokener_parse(payload);
  12559. if(!is_error(SendLocalList))
  12560. {
  12561. // Required data
  12562. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12563. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12564. // Optional data
  12565. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12566. {
  12567. //Check UpdateType
  12568. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12569. {
  12570. //Local list full update
  12571. DEBUG_INFO("Local list full update.\n");
  12572. locallistVersion = 0;
  12573. OCPP_getListVerion();
  12574. if((ShmOCPP16Data->SendLocalList.ListVersion > 0) && (ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion))
  12575. {
  12576. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12577. goto end;
  12578. }
  12579. OCPP_cleanLocalList();
  12580. }
  12581. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12582. {
  12583. //Local list different update
  12584. DEBUG_INFO("Local list different update.\n");
  12585. locallistVersion = 0;
  12586. OCPP_getListVerion();
  12587. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12588. {
  12589. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12590. goto end;
  12591. }
  12592. }
  12593. else
  12594. {
  12595. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12596. goto end;
  12597. }
  12598. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  12599. {
  12600. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  12601. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12602. goto end;
  12603. }
  12604. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12605. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12606. {
  12607. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag, "%s", stringtrimspace((char *)json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag"))));
  12608. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12609. {
  12610. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status, "%s", stringtrimspace((char *)json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status"))));
  12611. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12612. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate, "%s", stringtrimspace((char *)json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate"))));
  12613. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12614. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag, "%s", stringtrimspace((char *)json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag"))));
  12615. }
  12616. // Add to db
  12617. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12618. {
  12619. //Local list full update
  12620. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12621. idx,
  12622. ShmOCPP16Data->SendLocalList.ListVersion,
  12623. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12624. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12625. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12626. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12627. // update list
  12628. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12629. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12630. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12631. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12632. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12633. }
  12634. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12635. {
  12636. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12637. idx,
  12638. ShmOCPP16Data->SendLocalList.ListVersion,
  12639. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12640. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12641. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12642. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12643. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12644. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12645. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12646. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12647. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12648. }
  12649. }
  12650. }
  12651. else
  12652. {
  12653. //Check UpdateType
  12654. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12655. {
  12656. //Local list full update
  12657. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12658. OCPP_cleanLocalList();
  12659. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12660. goto end;
  12661. }
  12662. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12663. {
  12664. //Local list different update
  12665. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12666. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12667. goto end;
  12668. }
  12669. }
  12670. result = PASS;
  12671. }
  12672. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12673. end:
  12674. json_object_put(SendLocalList);
  12675. sendSendLocalListConfirmation(uuid, comfirmstr);
  12676. return result;
  12677. }
  12678. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12679. {
  12680. mtrace();
  12681. int result = FAIL;
  12682. struct StructSetChargingProfile SetProfileReq = {0};
  12683. int tempchargingProfileIdInt;
  12684. int tempstackLevelInt;
  12685. int chargingSchedulePeriodCount = 0;
  12686. char comfirmstr[20]={0};
  12687. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12688. char rmFileCmd[128]={0};
  12689. int profileQuantity = 0;
  12690. int replaceableProfileCnt = 0;
  12691. json_object *SetChargingProfile;
  12692. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12693. SetChargingProfile = json_tokener_parse(payload);
  12694. if(!is_error(SetChargingProfile))
  12695. {
  12696. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12697. {
  12698. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12699. }
  12700. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12701. {
  12702. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12703. {
  12704. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12705. }
  12706. else
  12707. {
  12708. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12709. DEBUG_WARN("Cannot find chargingProfileId field.");
  12710. goto end;
  12711. }
  12712. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12713. {
  12714. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12715. }
  12716. else
  12717. {
  12718. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12719. DEBUG_WARN("Cannot find stackLevel field.");
  12720. goto end;
  12721. }
  12722. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12723. {
  12724. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12725. }
  12726. else
  12727. {
  12728. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12729. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12730. goto end;
  12731. }
  12732. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12733. {
  12734. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12735. }
  12736. else
  12737. {
  12738. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12739. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12740. goto end;
  12741. }
  12742. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12743. {
  12744. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12745. }
  12746. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12747. {
  12748. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12749. }
  12750. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12751. {
  12752. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12753. }
  12754. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12755. {
  12756. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12757. }
  12758. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12759. {
  12760. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12761. {
  12762. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  12763. }
  12764. else
  12765. {
  12766. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12767. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12768. goto end;
  12769. }
  12770. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12771. {
  12772. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12773. }
  12774. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12775. {
  12776. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12777. }
  12778. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12779. {
  12780. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.StartSchedule, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  12781. }
  12782. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12783. {
  12784. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12785. if(chargingSchedulePeriodCount <= 10)
  12786. {
  12787. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  12788. {
  12789. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod") != NULL)
  12790. {
  12791. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  12792. }
  12793. else
  12794. {
  12795. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12796. DEBUG_WARN("Cannot find startPeriod field.");
  12797. goto end;
  12798. }
  12799. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit") != NULL)
  12800. {
  12801. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  12802. }
  12803. else
  12804. {
  12805. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12806. DEBUG_WARN("Cannot find limit field.");
  12807. goto end;
  12808. }
  12809. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  12810. {
  12811. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  12812. }
  12813. }
  12814. }
  12815. }
  12816. else
  12817. {
  12818. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12819. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12820. goto end;
  12821. }
  12822. }
  12823. else
  12824. {
  12825. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12826. DEBUG_WARN("Cannot find chargingSchedule field.");
  12827. goto end;
  12828. }
  12829. }
  12830. }
  12831. // Profile periods quantity check
  12832. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12833. {
  12834. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12835. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12836. goto end;
  12837. }
  12838. // Check invalid limit
  12839. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12840. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12841. {
  12842. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12843. {
  12844. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12845. {
  12846. if(((0 < SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit) && (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit < (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='A'?6:6*220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)))) ||
  12847. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12848. {
  12849. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12850. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12851. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12852. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12853. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12854. goto end;
  12855. }
  12856. }
  12857. }
  12858. else
  12859. {
  12860. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12861. {
  12862. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) > modelnameInfo.ratedPower) ||
  12863. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?1:220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)) < (modelnameInfo.ratedPower*0.01)))
  12864. {
  12865. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12866. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12867. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12868. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12869. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12870. goto end;
  12871. }
  12872. }
  12873. }
  12874. }
  12875. // Profile purpose info check
  12876. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12877. {
  12878. FILE *fp;
  12879. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12880. if(SetProfileReq.ConnectorId != 0)
  12881. {
  12882. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12883. DEBUG_WARN("Profile connector id is not 0.\n");
  12884. goto end;
  12885. }
  12886. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12887. if (!fp)
  12888. {
  12889. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12890. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12891. }
  12892. else
  12893. {
  12894. char *line = NULL;
  12895. size_t len = 0;
  12896. while(getline(&line, &len, fp) != -1)
  12897. {
  12898. json_object *obj = NULL;
  12899. obj = json_tokener_parse(line);
  12900. if(is_error(obj))
  12901. {
  12902. DEBUG_ERROR("Parse txProfile from file error.\n");
  12903. }
  12904. else
  12905. {
  12906. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12907. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12908. {
  12909. profileQuantity += 1;
  12910. }
  12911. else
  12912. replaceableProfileCnt += 1;
  12913. }
  12914. }
  12915. }
  12916. fclose(fp);
  12917. }
  12918. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12919. {
  12920. FILE *fp;
  12921. char filename[128]={0};
  12922. int tmpProfileQuantity;
  12923. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12924. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12925. {
  12926. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12927. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12928. goto end;
  12929. }
  12930. if(SetProfileReq.ConnectorId == 0)
  12931. {
  12932. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12933. {
  12934. tmpProfileQuantity = 0;
  12935. memset(filename, 0, ARRAY_SIZE(filename));
  12936. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12937. fp = fopen(filename, "r");
  12938. if (!fp)
  12939. {
  12940. DEBUG_INFO("%s does not create.\n", filename);
  12941. fp = fopen(filename, "w+");
  12942. }
  12943. else
  12944. {
  12945. char *line = NULL;
  12946. size_t len = 0;
  12947. while(getline(&line, &len, fp) != -1)
  12948. {
  12949. json_object *obj = NULL;
  12950. obj = json_tokener_parse(line);
  12951. if(is_error(obj))
  12952. {
  12953. DEBUG_ERROR("Parse txProfile from file error.\n");
  12954. }
  12955. else
  12956. {
  12957. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12958. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12959. {
  12960. tmpProfileQuantity += 1;
  12961. }
  12962. else
  12963. replaceableProfileCnt += 1;
  12964. }
  12965. }
  12966. }
  12967. fclose(fp);
  12968. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12969. }
  12970. }
  12971. else
  12972. {
  12973. memset(filename, 0, ARRAY_SIZE(filename));
  12974. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12975. fp = fopen(filename, "r");
  12976. if (!fp)
  12977. {
  12978. DEBUG_INFO("%s does not create.\n", filename);
  12979. fp = fopen(filename, "w+");
  12980. }
  12981. else
  12982. {
  12983. char *line = NULL;
  12984. size_t len = 0;
  12985. while(getline(&line, &len, fp) != -1)
  12986. {
  12987. json_object *obj = NULL;
  12988. obj = json_tokener_parse(line);
  12989. if(is_error(obj))
  12990. {
  12991. DEBUG_ERROR("Parse txProfile from file error.\n");
  12992. }
  12993. else
  12994. {
  12995. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12996. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12997. {
  12998. profileQuantity += 1;
  12999. }
  13000. else
  13001. replaceableProfileCnt += 1;
  13002. }
  13003. }
  13004. }
  13005. fclose(fp);
  13006. }
  13007. }
  13008. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  13009. {
  13010. int isMatchTransactiodId= FALSE;
  13011. FILE *fp;
  13012. char filename[128]={0};
  13013. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  13014. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  13015. if(SetProfileReq.ConnectorId == 0)
  13016. {
  13017. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13018. DEBUG_WARN("Profile connector id is 0.\n");
  13019. goto end;
  13020. }
  13021. int tempIndex = 0;
  13022. //check Transaction active
  13023. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  13024. {
  13025. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13026. {
  13027. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13028. }
  13029. else
  13030. {
  13031. tempIndex = SetProfileReq.ConnectorId -1;
  13032. }
  13033. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13034. {
  13035. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13036. {
  13037. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13038. {
  13039. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13040. {
  13041. isMatchTransactiodId = TRUE;
  13042. break;
  13043. }
  13044. }
  13045. }
  13046. }
  13047. }
  13048. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  13049. {
  13050. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13051. {
  13052. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13053. }
  13054. else
  13055. {
  13056. tempIndex = SetProfileReq.ConnectorId -1;
  13057. }
  13058. for (int index = 0; index < CCS_QUANTITY; index++)
  13059. {
  13060. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13061. {
  13062. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  13063. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13064. {
  13065. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13066. {
  13067. isMatchTransactiodId = TRUE;
  13068. break;
  13069. }
  13070. }
  13071. }
  13072. }
  13073. }
  13074. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  13075. {
  13076. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13077. {
  13078. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13079. }
  13080. else
  13081. {
  13082. tempIndex = SetProfileReq.ConnectorId -1;
  13083. }
  13084. for (int index = 0; index < GB_QUANTITY; index++)
  13085. {
  13086. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13087. {
  13088. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13089. {
  13090. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13091. {
  13092. isMatchTransactiodId = TRUE;
  13093. break;
  13094. }
  13095. }
  13096. }
  13097. }
  13098. }
  13099. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  13100. {
  13101. tempIndex = SetProfileReq.ConnectorId -1;
  13102. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13103. {
  13104. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13105. {
  13106. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  13107. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13108. {
  13109. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13110. {
  13111. isMatchTransactiodId = TRUE;
  13112. break;
  13113. }
  13114. }
  13115. }
  13116. }
  13117. }
  13118. else
  13119. {
  13120. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13121. {
  13122. tempIndex = 2;
  13123. }
  13124. else
  13125. {
  13126. tempIndex = (SetProfileReq.ConnectorId -1);
  13127. }
  13128. for (int index = 0; index < AC_QUANTITY; index++)
  13129. {
  13130. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13131. {
  13132. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  13133. {
  13134. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13135. {
  13136. isMatchTransactiodId = TRUE;
  13137. break;
  13138. }
  13139. }
  13140. }
  13141. }
  13142. }
  13143. //check Transaction active
  13144. if(isMatchTransactiodId == FALSE)
  13145. {
  13146. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13147. DEBUG_WARN("Tx profile transaction id is not match.\n");
  13148. goto end;
  13149. }
  13150. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13151. {
  13152. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13153. DEBUG_WARN("Connector id is over max gun number.\n");
  13154. goto end;
  13155. }
  13156. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13157. fp = fopen(filename, "r");
  13158. if (!fp)
  13159. {
  13160. DEBUG_INFO("%s does not create.\n", filename);
  13161. fp = fopen(filename, "w+");
  13162. }
  13163. else
  13164. {
  13165. char *line = NULL;
  13166. size_t len = 0;
  13167. while(getline(&line, &len, fp) != -1)
  13168. {
  13169. json_object *obj = NULL;
  13170. obj = json_tokener_parse(line);
  13171. if(is_error(obj))
  13172. {
  13173. DEBUG_ERROR("Parse txProfile from file error.\n");
  13174. }
  13175. else
  13176. {
  13177. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13178. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13179. {
  13180. profileQuantity += 1;
  13181. }
  13182. else
  13183. replaceableProfileCnt += 1;
  13184. }
  13185. }
  13186. }
  13187. fclose(fp);
  13188. }
  13189. // Check ChargeProfileMaxStackLevel
  13190. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  13191. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  13192. {
  13193. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13194. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13195. goto end;
  13196. }
  13197. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13198. {
  13199. FILE *fp;
  13200. char dataLine[4096]={0};
  13201. char fnametemp[128]={0};
  13202. int tmpProfileQuantity;
  13203. //Check ChargePointMaxProfile.json exit
  13204. profileQuantity = 0;
  13205. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  13206. {
  13207. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  13208. //Check Charging Profile Count
  13209. tmpProfileQuantity = 0;
  13210. while(fscanf(fp, "%s", dataLine) != EOF)
  13211. {
  13212. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13213. {
  13214. profileQuantity += 1;
  13215. tmpProfileQuantity += 1;
  13216. }
  13217. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13218. }
  13219. fclose(fp);
  13220. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  13221. }
  13222. //Check TxDefaultProfile_%d.json
  13223. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13224. {
  13225. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13226. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13227. if((access(fnametemp,F_OK))!=-1)
  13228. {
  13229. fp = fopen(fnametemp, "r");
  13230. //Check Charging Profile Count
  13231. tmpProfileQuantity = 0;
  13232. while(fscanf(fp, "%s", dataLine) != EOF)
  13233. {
  13234. //DEBUG_INFO("word=%s\n",word);
  13235. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13236. {
  13237. profileQuantity += 1;
  13238. tmpProfileQuantity += 1;
  13239. }
  13240. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13241. }
  13242. fclose(fp);
  13243. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13244. }
  13245. }
  13246. //Check TxProfile_%d.json
  13247. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13248. {
  13249. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13250. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  13251. if((access(fnametemp,F_OK))!=-1)
  13252. {
  13253. fp = fopen(fnametemp, "r");
  13254. //Check Charging Profile Count
  13255. tmpProfileQuantity = 0;
  13256. while(fscanf(fp, "%s", dataLine) != EOF)
  13257. {
  13258. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13259. {
  13260. profileQuantity += 1;
  13261. tmpProfileQuantity += 1;
  13262. }
  13263. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13264. }
  13265. fclose(fp);
  13266. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13267. }
  13268. }
  13269. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  13270. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  13271. // To check total Profile quantity
  13272. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  13273. {
  13274. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13275. {
  13276. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13277. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13278. goto end;
  13279. }
  13280. }
  13281. else
  13282. {
  13283. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13284. {
  13285. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13286. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13287. goto end;
  13288. }
  13289. }
  13290. }
  13291. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13292. //**********************************Write to File********************************************************/
  13293. {
  13294. FILE *infile;
  13295. FILE *outfile;
  13296. char dataLine[4096]={0};
  13297. char filename[128]={0};
  13298. int chkChar=0;
  13299. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  13300. {
  13301. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13302. {
  13303. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  13304. }
  13305. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13306. {
  13307. if(SetProfileReq.ConnectorId==0)
  13308. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13309. else
  13310. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13311. }
  13312. else
  13313. {
  13314. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13315. }
  13316. infile = fopen (filename, "r");
  13317. outfile = fopen (tempfile, "w");
  13318. chkChar = fgetc(infile);
  13319. rewind(infile);
  13320. if(chkChar == EOF)
  13321. {
  13322. // Profile is empty
  13323. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13324. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13325. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13326. fclose(infile);
  13327. fclose(outfile);
  13328. sprintf(rmFileCmd,"rm -f %s",filename);
  13329. system(rmFileCmd);
  13330. rename(tempfile, filename);
  13331. }
  13332. else
  13333. {
  13334. // Profile is not empty
  13335. int ChargingProfileAdded = FALSE;
  13336. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  13337. {
  13338. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  13339. json_object *tmpChargingProfile;
  13340. tmpChargingProfile = json_tokener_parse(dataLine);
  13341. if(!is_error(SetChargingProfile))
  13342. {
  13343. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13344. {
  13345. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13346. {
  13347. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13348. }
  13349. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13350. {
  13351. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13352. }
  13353. }
  13354. }
  13355. json_object_put(tmpChargingProfile);
  13356. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  13357. {
  13358. if(ChargingProfileAdded == FALSE)
  13359. {
  13360. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13361. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13362. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13363. ChargingProfileAdded = TRUE;
  13364. }
  13365. }
  13366. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13367. {
  13368. if(ChargingProfileAdded == FALSE)
  13369. {
  13370. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13371. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13372. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13373. ChargingProfileAdded = TRUE;
  13374. }
  13375. }
  13376. else
  13377. {
  13378. fprintf(outfile,"%s\n",dataLine);
  13379. if(ChargingProfileAdded == FALSE)
  13380. {
  13381. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13382. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13383. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13384. ChargingProfileAdded = TRUE;
  13385. }
  13386. }
  13387. } // end of while loop
  13388. fclose(infile);
  13389. fclose(outfile);
  13390. sprintf(rmFileCmd,"rm -f %s",filename);
  13391. system(rmFileCmd);
  13392. rename(tempfile, filename);
  13393. }
  13394. }
  13395. sleep(1);
  13396. result = TRUE;
  13397. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13398. }
  13399. end:
  13400. json_object_put(SetChargingProfile);
  13401. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13402. {
  13403. if(SetProfileReq.ConnectorId == 0)
  13404. {
  13405. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13406. {
  13407. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13408. }
  13409. }
  13410. else
  13411. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13412. }
  13413. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13414. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13415. return result;
  13416. }
  13417. int handleTriggerMessageRequest(char *uuid, char *payload)
  13418. {
  13419. mtrace();
  13420. int result = FAIL;
  13421. int connectorIdIsNULL = FALSE;
  13422. int connectorIdInt =0;
  13423. char sstr[40]={0},sstrtemp[100]={ 0 };
  13424. char requestedMessagestr[40]={0};
  13425. char comfirmstr[20]={0};
  13426. int c = 0;
  13427. char *loc;
  13428. DEBUG_INFO("handleTriggerMessageRequest\n");
  13429. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13430. strcpy(sstrtemp, stringtrimspace(payload));
  13431. c = 0;
  13432. loc = strstr(sstrtemp, "requestedMessage");
  13433. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13434. {
  13435. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13436. c++;
  13437. }
  13438. sstr[c] = '\0';
  13439. strcpy(requestedMessagestr, sstr);
  13440. c = 0;
  13441. loc = strstr(sstrtemp, "connectorId");
  13442. if(loc == NULL)
  13443. {
  13444. connectorIdIsNULL = TRUE;
  13445. }
  13446. else
  13447. {
  13448. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13449. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13450. {
  13451. sstr[c] = loc[strlen("connectorId")+2+c];
  13452. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13453. c++;
  13454. }
  13455. sstr[c] = '\0';
  13456. connectorIdInt = atoi(sstr);
  13457. }
  13458. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13459. {
  13460. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13461. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13462. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13463. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13464. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13465. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13466. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13467. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13468. {
  13469. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13470. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13471. return TRUE;
  13472. }
  13473. else
  13474. {
  13475. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13476. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13477. }
  13478. }
  13479. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13480. {
  13481. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13482. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13483. return TRUE;
  13484. }
  13485. //==========================
  13486. // Trigger message
  13487. //==========================
  13488. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13489. {
  13490. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13491. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13492. {
  13493. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13494. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13495. }
  13496. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13497. }
  13498. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13499. {
  13500. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13501. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13502. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13503. }
  13504. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13505. {
  13506. //sendBootNotificationRequest();
  13507. server_sign = FALSE;
  13508. }
  13509. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13510. {
  13511. refreshStartTimer(&clientTime.Heartbeat);
  13512. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13513. }
  13514. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13515. {
  13516. if(connectorIdIsNULL == FALSE)
  13517. {
  13518. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13519. {
  13520. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13521. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13522. }
  13523. }
  13524. else
  13525. {
  13526. for(int idx=0;idx< gunTotalNumber;idx++)
  13527. {
  13528. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13529. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13530. }
  13531. }
  13532. }
  13533. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13534. {
  13535. if(connectorIdIsNULL == FALSE)
  13536. {
  13537. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13538. {
  13539. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13540. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13541. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13542. }
  13543. }
  13544. else
  13545. {
  13546. for(int idx=0;idx< gunTotalNumber;idx++)
  13547. {
  13548. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13549. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13550. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13551. }
  13552. }
  13553. }
  13554. return result;
  13555. }
  13556. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13557. {
  13558. mtrace();
  13559. int result = FAIL;
  13560. int connectorIdInt =0;
  13561. char comfirmstr[20]={0};
  13562. int tempIndex = 0;
  13563. json_object *UnlockConnector;
  13564. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13565. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13566. UnlockConnector = json_tokener_parse(payload);
  13567. if(!is_error(UnlockConnector))
  13568. {
  13569. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13570. {
  13571. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13572. }
  13573. }
  13574. json_object_put(UnlockConnector);
  13575. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13576. if(gunTotalNumber == 0)
  13577. {
  13578. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13579. goto end;
  13580. }
  13581. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13582. {
  13583. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13584. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13585. goto end;
  13586. }
  13587. else
  13588. {
  13589. //check Transaction active
  13590. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13591. {
  13592. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13593. {
  13594. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13595. }
  13596. else
  13597. {
  13598. tempIndex = connectorIdInt -1;
  13599. }
  13600. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13601. {
  13602. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13603. {
  13604. //stop Transaction
  13605. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13606. }
  13607. }
  13608. }
  13609. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13610. {
  13611. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13612. {
  13613. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13614. }
  13615. else
  13616. {
  13617. tempIndex = connectorIdInt -1;
  13618. }
  13619. for (int index = 0; index < CCS_QUANTITY; index++)
  13620. {
  13621. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13622. {
  13623. //stop Transaction
  13624. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13625. }
  13626. }
  13627. }
  13628. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13629. {
  13630. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13631. {
  13632. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13633. }
  13634. else
  13635. {
  13636. tempIndex = connectorIdInt -1;
  13637. }
  13638. for (int index = 0; index < GB_QUANTITY; index++)
  13639. {
  13640. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13641. {
  13642. //stop Transaction
  13643. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13644. }
  13645. }
  13646. }
  13647. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13648. {
  13649. tempIndex = connectorIdInt -1;
  13650. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13651. {
  13652. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13653. {
  13654. //stop Transaction
  13655. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13656. }
  13657. }
  13658. }
  13659. else
  13660. {
  13661. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13662. {
  13663. tempIndex = 2;
  13664. }
  13665. else
  13666. {
  13667. tempIndex = connectorIdInt-1;
  13668. }
  13669. for (int index = 0; index < AC_QUANTITY; index++)
  13670. {
  13671. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13672. {
  13673. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13674. }
  13675. }
  13676. }
  13677. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13678. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13679. result = TRUE;
  13680. return result;
  13681. }
  13682. end:
  13683. //json_object_put(obj); --- remove temporally
  13684. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13685. return result;
  13686. }
  13687. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13688. {
  13689. mtrace();
  13690. int result = FAIL;
  13691. pthread_t t;
  13692. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13693. sendUpdateFirmwareConfirmation(uuid);
  13694. if(!interLock.isUpdateFirmwareGoing)
  13695. {
  13696. interLock.isUpdateFirmwareGoing = 1;
  13697. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  13698. sleep(1);
  13699. }
  13700. else
  13701. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13702. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13703. return result;
  13704. }
  13705. void *UpdateFirmwareProcess(void *data)
  13706. {
  13707. pthread_detach(pthread_self());
  13708. mtrace();
  13709. int retriesInt =0, retryIntervalInt=0;
  13710. char protocol[10], user[64],password[64],host[256], path[1024], ftppath[1024],host1[256],path1[1024];
  13711. int port=0;
  13712. char locationstr[2048]={0}, retrieveDatestr[36]={0};
  13713. int isSuccess = 0;
  13714. char ftpbuf[2048];
  13715. char temp[2048];
  13716. char * pch;
  13717. char filenametemp[256];
  13718. json_object *UpdateFirmware;
  13719. UpdateFirmware = json_tokener_parse(data);
  13720. if(!is_error(UpdateFirmware))
  13721. {
  13722. // Required data
  13723. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13724. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13725. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13726. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13727. // Optional data
  13728. if(json_object_object_get(UpdateFirmware, "retries"))
  13729. {
  13730. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13731. }
  13732. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13733. {
  13734. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13735. }
  13736. }
  13737. json_object_put(UpdateFirmware);
  13738. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13739. memset(path, 0, ARRAY_SIZE(path));
  13740. // Wait retrieveData
  13741. if(strlen(retrieveDatestr) > 10)
  13742. {
  13743. do
  13744. {
  13745. sleep(1);
  13746. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13747. }
  13748. // Ready to download
  13749. system("rm -f /mnt/*");
  13750. if(strncmp(locationstr,"http", 4) == 0)
  13751. {
  13752. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13753. sprintf(ftppath,"/%s", path);
  13754. DEBUG_INFO("locationstr: %s\n", locationstr);
  13755. DEBUG_INFO("protocol: %s\n",protocol);
  13756. DEBUG_INFO("host: %s\n",host);
  13757. DEBUG_INFO("path: %s\n",path);
  13758. DEBUG_INFO("ftppath: %s\n",ftppath);
  13759. int ftppathlen=strlen(ftppath);
  13760. int i=1;
  13761. while(i < ftppathlen)
  13762. {
  13763. int len=ftppathlen-i;
  13764. if(ftppath[len]== 47) // '/' ascll code: 47
  13765. {
  13766. DEBUG_INFO("compare '/' all right\n");
  13767. break;
  13768. }
  13769. i=i+1;
  13770. }
  13771. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13772. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13773. filenametemp[i+1] = 0;
  13774. do
  13775. {
  13776. sleep(1);
  13777. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13778. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13779. sleep(1);
  13780. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13781. if(!isSuccess)
  13782. {
  13783. sleep(1);
  13784. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13785. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13786. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13787. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13788. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13789. }
  13790. else
  13791. {
  13792. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13793. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13794. }
  13795. retriesInt--;
  13796. }while((isSuccess == 0)&&(retriesInt >= 0));
  13797. }
  13798. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13799. {
  13800. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13801. memset(temp, 0, ARRAY_SIZE(temp));
  13802. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13803. strcpy(ftpbuf, locationstr);
  13804. int ftppathlen=strlen(ftpbuf);
  13805. int i=1;
  13806. while(i < ftppathlen)
  13807. {
  13808. int len=ftppathlen-i;
  13809. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13810. {
  13811. DEBUG_INFO(" compare '/' all right\n");
  13812. break;
  13813. }
  13814. i=i+1;
  13815. }
  13816. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13817. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13818. filenametemp[i+1] = 0;
  13819. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13820. pch=strchr(temp,'@');
  13821. if(pch==NULL)
  13822. {
  13823. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13824. protocol, host, &port, path);
  13825. strcpy(user,"anonymous");
  13826. strcpy(password,"");
  13827. }
  13828. else
  13829. {
  13830. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13831. protocol, user, host, &port, path);
  13832. }
  13833. sscanf(host,"%[^/]%s",host1, path1);
  13834. sprintf(ftppath,"%s:/%s", host,path);
  13835. if(port == 0)
  13836. {
  13837. port = 21;
  13838. }
  13839. do
  13840. {
  13841. sleep(1);
  13842. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13843. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13844. sleep(1);
  13845. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13846. if(!isSuccess)
  13847. {
  13848. //BulldogUtil.sleepMs(interval*1000);
  13849. DEBUG_INFO("Update firmware request and download file fail.\n");
  13850. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13851. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13852. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13853. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13854. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13855. }
  13856. else
  13857. {
  13858. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13859. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13860. }
  13861. retriesInt--;
  13862. }while((!isSuccess)&&(retriesInt >= 0));
  13863. }
  13864. else if((strncmp(locationstr,"ftp", 3) == 0) || (strncmp(locationstr,"ftps", 4) == 0)) // ftp/ftps
  13865. {
  13866. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13867. memset(temp, 0, ARRAY_SIZE(temp));
  13868. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13869. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13870. int ftppathlen=strlen(ftpbuf);
  13871. int i=1;
  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_MF,F_OK) != -1)
  14064. {
  14065. DEBUG_INFO("Checking ManufacturerRootCertificate...\n");
  14066. isMatch = TRUE;
  14067. parseCertInfo(ROOTCA_MF, 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_MF, 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_MF, 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_MF);
  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. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14150. return result;
  14151. }
  14152. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  14153. {
  14154. mtrace();
  14155. int result = PASS;
  14156. json_object *ExtendedTriggerMessage;
  14157. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  14158. ExtendedTriggerMessage = json_tokener_parse(payload);
  14159. if(!is_error(ExtendedTriggerMessage))
  14160. {
  14161. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  14162. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  14163. {
  14164. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  14165. }
  14166. else
  14167. {
  14168. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  14169. }
  14170. }
  14171. json_object_put(ExtendedTriggerMessage);
  14172. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  14173. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  14174. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  14175. {
  14176. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  14177. }
  14178. else
  14179. {
  14180. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  14181. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  14182. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  14183. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  14184. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  14185. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  14186. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  14187. {
  14188. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  14189. }
  14190. else
  14191. {
  14192. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  14193. }
  14194. }
  14195. sendExtendedTriggerMessageConfirmation(uuid);
  14196. //==========================
  14197. // Trigger message
  14198. //==========================
  14199. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  14200. {
  14201. //sendBootNotificationRequest();
  14202. server_sign = FALSE;
  14203. }
  14204. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  14205. {
  14206. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14207. }
  14208. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  14209. {
  14210. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  14211. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  14212. {
  14213. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  14214. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  14215. }
  14216. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14217. }
  14218. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  14219. {
  14220. refreshStartTimer(&clientTime.Heartbeat);
  14221. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  14222. }
  14223. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  14224. {
  14225. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14226. {
  14227. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  14228. }
  14229. else
  14230. {
  14231. for(int idx=0;idx< gunTotalNumber;idx++)
  14232. {
  14233. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  14234. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  14235. }
  14236. }
  14237. }
  14238. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  14239. {
  14240. char cmdBuf[1024]={0};
  14241. 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);
  14242. system(cmdBuf);
  14243. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  14244. }
  14245. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  14246. {
  14247. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14248. {
  14249. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  14250. }
  14251. else
  14252. {
  14253. for(int idx=0;idx< gunTotalNumber;idx++)
  14254. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  14255. }
  14256. }
  14257. return result;
  14258. }
  14259. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  14260. {
  14261. mtrace();
  14262. int result = PASS;
  14263. json_object *GetInstalledCertificateIds;
  14264. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  14265. GetInstalledCertificateIds = json_tokener_parse(payload);
  14266. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  14267. if(!is_error(GetInstalledCertificateIds))
  14268. {
  14269. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  14270. DEBUG_INFO("Requested Certificate: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14271. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "Accepted");
  14272. DEBUG_INFO("Access ROOTCA_CS result: %d\n", access(ROOTCA_CS,F_OK));
  14273. // Check CentralSystemRootCertificate
  14274. if(strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "CentralSystemRootCertificate")!= NULL)
  14275. {
  14276. if(access(ROOTCA_CS,F_OK) != -1)
  14277. {
  14278. char parseData[512] = {0};
  14279. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14280. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14281. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, parseData) == PASS)
  14282. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14283. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14284. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14285. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14286. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14287. }
  14288. else
  14289. {
  14290. DEBUG_INFO(">>> No CentralSystemRootCertificate was found.\n");
  14291. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14292. }
  14293. }
  14294. // Check ManufacturerRootCertificate
  14295. else if(strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "ManufacturerRootCertificate") != NULL)
  14296. {
  14297. if(access(ROOTCA_MF,F_OK) != -1)
  14298. {
  14299. char parseData[512] = {0};
  14300. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14301. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14302. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, parseData) == PASS)
  14303. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14304. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14305. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14306. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14307. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14308. }
  14309. else
  14310. {
  14311. DEBUG_INFO(">>> No ManufacturerRootCertificate was found.\n");
  14312. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14313. }
  14314. }
  14315. else
  14316. {
  14317. DEBUG_INFO(">>> No %s was found.\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14318. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14319. }
  14320. }
  14321. json_object_put(GetInstalledCertificateIds);
  14322. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  14323. sendGetInstalledCertificateIdsConfirmation(uuid);
  14324. return result;
  14325. }
  14326. void* GetLogProcess(void* data)
  14327. {
  14328. pthread_detach(pthread_self());
  14329. mtrace();
  14330. 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};
  14331. int port=0;
  14332. int isSuccess = FALSE;
  14333. char cmdBuf[2048];
  14334. struct tm *tmNow;
  14335. time_t CurrentTime;
  14336. struct tm tmStart;
  14337. struct tm tmStop;
  14338. CurrentTime = time(NULL);
  14339. tmNow=localtime(&CurrentTime);
  14340. uint16_t targetYear, targetMonth;
  14341. json_object *GetLog;
  14342. DEBUG_INFO("GetLogProcess...\n");
  14343. GetLog = json_tokener_parse(data);
  14344. if(!is_error(GetLog))
  14345. {
  14346. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  14347. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  14348. if(json_object_object_get(GetLog, "retries") != NULL)
  14349. {
  14350. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  14351. }
  14352. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  14353. {
  14354. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  14355. }
  14356. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  14357. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  14358. {
  14359. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  14360. }
  14361. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  14362. {
  14363. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  14364. }
  14365. }
  14366. json_object_put(GetLog);
  14367. // Pack log to compress file
  14368. 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) &&
  14369. (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))
  14370. {
  14371. // Pack system log
  14372. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14373. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14374. targetYear = tmStart.tm_year;
  14375. targetMonth = tmStart.tm_mon;
  14376. do
  14377. {
  14378. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14379. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  14380. if(targetMonth+1>=13)
  14381. {
  14382. targetYear += 1;
  14383. targetMonth = 1;
  14384. }
  14385. else
  14386. {
  14387. targetMonth += 1;
  14388. }
  14389. }while((targetYear < (tmNow->tm_year+1900)) ||
  14390. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14391. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  14392. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  14393. sprintf(cmdBuf, "%s /Storage/Dispenser*Log.zip", cmdBuf);
  14394. system(cmdBuf);
  14395. // Pack charging & event log
  14396. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14397. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  14398. targetYear = tmStart.tm_year;
  14399. targetMonth = tmStart.tm_mon;
  14400. do
  14401. {
  14402. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14403. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  14404. if(targetMonth+1>=13)
  14405. {
  14406. targetYear += 1;
  14407. targetMonth = 1;
  14408. }
  14409. else
  14410. {
  14411. targetMonth += 1;
  14412. }
  14413. }while((targetYear < (tmNow->tm_year+1900)) ||
  14414. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14415. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  14416. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  14417. system(cmdBuf);
  14418. // Combine log file
  14419. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  14420. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  14421. }
  14422. else
  14423. {
  14424. system("exec /root/logPackTools 'log' 6");
  14425. }
  14426. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetLog.Response_filename);
  14427. system(cmdBuf);
  14428. checkUploadLog();
  14429. //****************location*******************/
  14430. if(strcmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"")==0)
  14431. {
  14432. DEBUG_INFO("location is <Empty>!\n");
  14433. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14434. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14435. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14436. goto end;
  14437. }
  14438. memset(protocol, 0, ARRAY_SIZE(protocol));
  14439. memset(user, 0, ARRAY_SIZE(user) );
  14440. memset(password, 0, ARRAY_SIZE(password));
  14441. memset(host, 0, ARRAY_SIZE(host));
  14442. memset(path, 0, ARRAY_SIZE(path));
  14443. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14444. memset(host1, 0, ARRAY_SIZE(host1));
  14445. memset(path1, 0, ARRAY_SIZE(path1));
  14446. /*location: ftp://user:password@host:port/path*/
  14447. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  14448. if((access(fnamePlusPath,F_OK))!=-1)
  14449. {
  14450. DEBUG_INFO("fnamePlusPath exist.\n");
  14451. }
  14452. else
  14453. {
  14454. DEBUG_INFO("fnamePlusPath not exist!\n");
  14455. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14456. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14457. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14458. goto end;
  14459. }
  14460. if(strchr((char*)ShmOCPP16Data->GetLog.log.remoteLocation,'@')==NULL)
  14461. {
  14462. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,
  14463. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14464. protocol, host, &port, path);
  14465. strcpy(user,"anonymous");
  14466. strcpy(password,"");
  14467. }
  14468. else
  14469. {
  14470. //DEBUG_INFO("pch=%s\n", pch);
  14471. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14472. protocol, user, password, host, &port, path);
  14473. }
  14474. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  14475. {
  14476. DEBUG_INFO("protocol is not ftp/http ! \n");
  14477. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14478. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14479. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14480. goto end;
  14481. }
  14482. if(strncmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"http", 4) == 0)
  14483. {
  14484. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14485. sprintf(ftppath,"/%s", path);
  14486. do
  14487. {
  14488. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14489. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14490. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14491. sleep(3);
  14492. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, (char*)ShmOCPP16Data->GetLog.log.remoteLocation);
  14493. if(!isSuccess)
  14494. {
  14495. DEBUG_INFO("Diagnostics fail.\n");
  14496. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14497. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14498. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14499. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14500. }
  14501. else
  14502. {
  14503. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14504. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14505. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14506. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14507. }
  14508. ShmOCPP16Data->GetLog.retries--;
  14509. }while((isSuccess == 0)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14510. }
  14511. else
  14512. {
  14513. sscanf(host,"%[^/]%s",host1, path1);
  14514. if(strlen(path) > 0)
  14515. sprintf(ftppath,"/%s", path);
  14516. else
  14517. sprintf(ftppath,"/%s", path1);
  14518. int ftppathlen=strlen(ftppath);
  14519. int i=1;
  14520. char filenametemp[50];
  14521. while(i < ftppathlen)
  14522. {
  14523. int len=ftppathlen-i;
  14524. if(ftppath[len]== 47) // '/' ascll code: 47
  14525. {
  14526. DEBUG_INFO("find '/' all right\n");
  14527. break;
  14528. }
  14529. i=i+1;
  14530. }
  14531. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14532. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  14533. filenametemp[i+1] = 0;
  14534. if(port == 0)
  14535. port = 21;
  14536. do
  14537. {
  14538. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14539. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14540. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14541. sleep(3);
  14542. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  14543. if(!isSuccess)
  14544. {
  14545. DEBUG_INFO("Diagnostics fail.\n");
  14546. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14547. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14548. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14549. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14550. }
  14551. else
  14552. {
  14553. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14554. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14555. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14556. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14557. }
  14558. ShmOCPP16Data->GetLog.retries--;
  14559. }while((!isSuccess)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14560. }
  14561. end:
  14562. system("rm -f /mnt/*");
  14563. system("rm -f /Storage/Dispenser*Log.zip");
  14564. sleep(5);
  14565. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14566. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Idle");
  14567. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14568. interLock.isGetDiagnosticGoing = 0;
  14569. pthread_exit(NULL);
  14570. }
  14571. int handleGetLogRequest(char *uuid, char *payload)
  14572. {
  14573. mtrace();
  14574. int result = PASS;
  14575. time_t CurrentTime;
  14576. struct tm *tm;
  14577. DEBUG_INFO("handleGetLogRequest...\n");
  14578. pthread_t th_Status;
  14579. CurrentTime = time(NULL);
  14580. tm = localtime(&CurrentTime);
  14581. memset(ShmOCPP16Data->GetLog.Response_filename, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetLog.Response_filename));
  14582. sprintf((char*)ShmOCPP16Data->GetLog.Response_filename, "%s-%s-%04d%02d%02d%02d%02d%02d.zip", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber, (tm->tm_year+1900), (tm->tm_mon+1),tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
  14583. if(!interLock.isGetDiagnosticGoing)
  14584. {
  14585. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Accepted");
  14586. interLock.isGetDiagnosticGoing = 1;
  14587. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  14588. sleep(1);
  14589. }
  14590. else
  14591. {
  14592. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  14593. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  14594. }
  14595. sendGetLogConfirmation(uuid);
  14596. return result;
  14597. }
  14598. int handleInstallCertificateRequest(char *uuid, char *payload)
  14599. {
  14600. mtrace();
  14601. int result = PASS;
  14602. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  14603. json_object *InstallCertificate;
  14604. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14605. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14606. InstallCertificate = json_tokener_parse(payload);
  14607. if(!is_error(InstallCertificate))
  14608. {
  14609. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14610. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14611. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  14612. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  14613. char temp[1024];
  14614. FILE *fp = fopen(tempCert, "w");
  14615. fprintf(fp, "%s", ShmOCPP16Data->InstallCertificate.certificate);
  14616. fclose(fp);
  14617. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  14618. char strExpDate[30];
  14619. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  14620. fp = popen(temp, "r");
  14621. if(fp)
  14622. {
  14623. while(fgets(temp, sizeof(temp), fp) != NULL)
  14624. {
  14625. if(strstr(temp, "notAfter=") != NULL)
  14626. {
  14627. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14628. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  14629. break;
  14630. }
  14631. }
  14632. }
  14633. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  14634. struct tm tmExpDate;
  14635. struct timeb tbExpDate;
  14636. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  14637. tbExpDate.time = mktime(&tmExpDate);
  14638. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  14639. {
  14640. DEBUG_INFO("The enddate is already expired...\n");
  14641. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14642. goto End;
  14643. }
  14644. // Verify certificate with rootCA
  14645. sprintf(temp ,"openssl verify -CAfile /root/cacert.pem /Storage/OCPP/tempInstallCertificate.pem");
  14646. fp = popen(temp, "r");
  14647. if(fp)
  14648. {
  14649. while(fgets(temp, sizeof(temp), fp) != NULL)
  14650. {
  14651. if((strstr(temp, "tempInstallCertificate.pem: OK") != NULL) || (strstr(temp, "self signed certificate") != NULL))
  14652. {
  14653. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14654. break;
  14655. }
  14656. else
  14657. {
  14658. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14659. }
  14660. }
  14661. }
  14662. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14663. {
  14664. //=====================================================
  14665. // Verify if the certificate is valid or not. (OCSP?)
  14666. //=====================================================
  14667. /*
  14668. DEBUG_INFO("openssl CA verifying...FAIL --> Start OCSP process...\n");
  14669. // Get ocsp url
  14670. char ocspUrl[512];
  14671. sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", tempCert);
  14672. fp = popen(temp, "r");
  14673. if(fp)
  14674. {
  14675. while(fgets(temp, sizeof(temp), fp) != NULL)
  14676. {
  14677. if(strstr(temp, "://") != NULL)
  14678. {
  14679. strcpy(ocspUrl, temp);
  14680. break;
  14681. }
  14682. }
  14683. }
  14684. // Get certificate chain for issuer
  14685. * openssl s_client -connect [serverURL:port] -showcerts | sed -n '/-----BEGIN/,/-------END/p' > tempChain.pem
  14686. *
  14687. // Execute OCSP
  14688. sprintf(temp ,"openssl ocsp -issuer tempChain.pem -cert /Storage/OCPP/tempInstallCertificate.pem -text -url %s", ocspUrl);
  14689. fp = popen(temp, "r");
  14690. if(fp)
  14691. {
  14692. while(fgets(temp, sizeof(temp), fp) != NULL)
  14693. {
  14694. if(strstr(temp, "tempInstallCertificate.pem: good") != NULL)
  14695. {
  14696. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14697. break;
  14698. }
  14699. }
  14700. }
  14701. system("rm -f /Storage/OCPP/tempChain.pem");
  14702. pclose(fp);
  14703. */
  14704. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14705. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14706. {
  14707. DEBUG_INFO("OCSP verifying...FAIL.\n");
  14708. goto End;
  14709. }
  14710. else
  14711. DEBUG_INFO("OCSP verifying...PASS.\n");
  14712. }
  14713. else
  14714. DEBUG_INFO("openssl CA verifying...PASS.\n");
  14715. }
  14716. End:
  14717. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") == 0)
  14718. {
  14719. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "CentralSystemRootCertificate") == 0)
  14720. {
  14721. if(access(ROOTCA_CS,F_OK) != -1)
  14722. {
  14723. DEBUG_INFO("Existed CentralSystemRootCertificate is found. Replacing...\n");
  14724. rename(ROOTCA_CS, "/Storage/OCPP/CentralSystemRootCertificate_fallback.pem");
  14725. rename(tempCert, ROOTCA_CS);
  14726. }
  14727. else
  14728. {
  14729. DEBUG_INFO("No existed CentralSystemRootCertificate. Creating...\n");
  14730. rename(tempCert, ROOTCA_CS);
  14731. }
  14732. }
  14733. else if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "ManufacturerRootCertificate") == 0)
  14734. {
  14735. if(access(ROOTCA_MF,F_OK) != -1)
  14736. {
  14737. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14738. rename(ROOTCA_MF, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14739. rename(tempCert, ROOTCA_MF);
  14740. }
  14741. else
  14742. {
  14743. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14744. rename(tempCert, ROOTCA_MF);
  14745. }
  14746. }
  14747. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  14748. }
  14749. sendInstallCertificateConfirmation(uuid);
  14750. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14751. {
  14752. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidCentralSystemCertificate");
  14753. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14754. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14755. }
  14756. json_object_put(InstallCertificate);
  14757. return result;
  14758. }
  14759. void *SignedUpdateFirmwareProcess(void *data)
  14760. {
  14761. pthread_detach(pthread_self());
  14762. mtrace();
  14763. char protocol[10], user[64],password[64],host[256], path[1024], ftppath[1024],host1[256],path1[1024];
  14764. int port=0;
  14765. int isSuccess = 0;
  14766. char ftpbuf[2048];
  14767. char temp[2048];
  14768. char * pch;
  14769. char firmwareFileName[256];
  14770. DEBUG_INFO("SignedUpdateFirmwareProcess ...\n");
  14771. json_object *SignedUpdateFirmware;
  14772. SignedUpdateFirmware = json_tokener_parse(data);
  14773. if(!is_error(SignedUpdateFirmware))
  14774. {
  14775. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  14776. {
  14777. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  14778. }
  14779. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  14780. {
  14781. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  14782. }
  14783. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  14784. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  14785. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  14786. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  14787. {
  14788. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  14789. }
  14790. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  14791. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  14792. }
  14793. json_object_put(SignedUpdateFirmware);
  14794. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14795. memset(path, 0, ARRAY_SIZE(path));
  14796. // Wait retrieveData
  14797. if(strlen((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location) > 10)
  14798. {
  14799. do
  14800. {
  14801. sleep(1);
  14802. }while(!isOvertNow((uint8_t*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime));
  14803. }
  14804. // Ready to download
  14805. system("rm -f /mnt/*");
  14806. if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"http", 4) == 0)
  14807. {
  14808. sscanf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14809. sprintf(ftppath,"/%s", path);
  14810. DEBUG_INFO("locationstr: %s\n", (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14811. DEBUG_INFO("protocol: %s\n",protocol);
  14812. DEBUG_INFO("host: %s\n",host);
  14813. DEBUG_INFO("path: %s\n",path);
  14814. DEBUG_INFO("ftppath: %s\n",ftppath);
  14815. int ftppathlen=strlen(ftppath);
  14816. int i=1;
  14817. while(i < ftppathlen)
  14818. {
  14819. int len=ftppathlen-i;
  14820. if(ftppath[len]== 47) // '/' ascll code: 47
  14821. {
  14822. DEBUG_INFO("compare '/' all right\n");
  14823. break;
  14824. }
  14825. i=i+1;
  14826. }
  14827. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14828. strncpy(firmwareFileName, ftppath+(ftppathlen-i+1), i+1);
  14829. firmwareFileName[i+1] = 0;
  14830. do
  14831. {
  14832. sleep(1);
  14833. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14834. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14835. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14836. sleep(1);
  14837. isSuccess = httpDownLoadFile(host, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14838. if(!isSuccess)
  14839. {
  14840. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14841. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14842. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14843. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14844. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14845. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14846. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14847. }
  14848. else
  14849. {
  14850. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14851. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14852. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14853. }
  14854. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14855. }while((isSuccess == 0)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14856. }
  14857. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"sftp", 4) == 0) // sftp
  14858. {
  14859. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14860. memset(temp, 0, ARRAY_SIZE(temp));
  14861. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14862. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14863. int ftppathlen=strlen(ftpbuf);
  14864. int i=1;
  14865. while(i < ftppathlen)
  14866. {
  14867. int len=ftppathlen-i;
  14868. if(ftpbuf[len]== 47) // '/' ascii code: 47
  14869. {
  14870. DEBUG_INFO(" compare '/' all right\n");
  14871. break;
  14872. }
  14873. i=i+1;
  14874. }
  14875. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14876. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14877. firmwareFileName[i+1] = 0;
  14878. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14879. pch=strchr(temp,'@');
  14880. if(pch==NULL)
  14881. {
  14882. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14883. protocol, host, &port, path);
  14884. strcpy(user,"anonymous");
  14885. strcpy(password,"");
  14886. }
  14887. else
  14888. {
  14889. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  14890. protocol, user, host, &port, path);
  14891. }
  14892. sscanf(host,"%[^/]%s",host1, path1);
  14893. sprintf(ftppath,"%s:/%s", host,path);
  14894. if(port == 0)
  14895. {
  14896. port = 21;
  14897. }
  14898. do
  14899. {
  14900. sleep(1);
  14901. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14902. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14903. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14904. sleep(1);
  14905. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14906. if(!isSuccess)
  14907. {
  14908. sleep(1);
  14909. DEBUG_INFO("Update firmware request and download file fail.\n");
  14910. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14911. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14912. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14913. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14914. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14915. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14916. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14917. }
  14918. else
  14919. {
  14920. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14921. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14922. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14923. }
  14924. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14925. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14926. }
  14927. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"ftp", 3) == 0) // ftp
  14928. {
  14929. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14930. memset(temp, 0, ARRAY_SIZE(temp));
  14931. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14932. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14933. int ftppathlen=strlen(ftpbuf);
  14934. int i=1;
  14935. while(i < ftppathlen)
  14936. {
  14937. int len=ftppathlen-i;
  14938. if(ftpbuf[len]== 47) // '/' ascll code: 47
  14939. {
  14940. DEBUG_INFO(" compare '/' all right\n");
  14941. break;
  14942. }
  14943. i=i+1;
  14944. }
  14945. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14946. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14947. firmwareFileName[i+1] = 0;
  14948. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14949. pch=strchr(temp,'@');
  14950. if(pch==NULL)
  14951. {
  14952. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14953. protocol, host, &port, path);
  14954. strcpy(user,"anonymous");
  14955. strcpy(password,"");
  14956. }
  14957. else
  14958. {
  14959. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14960. protocol, user, password, host, &port, path);
  14961. }
  14962. sscanf(host,"%[^/]%s",host1, path1);
  14963. sprintf(ftppath,"%s", path1);
  14964. //DEBUG_INFO("protocol =%s\n",protocol);
  14965. //DEBUG_INFO("user =%s\n",user);
  14966. //DEBUG_INFO("password =%s\n",password);
  14967. //DEBUG_INFO("host1 =%s\n",host1);
  14968. //DEBUG_INFO("port =%d\n",port);
  14969. //DEBUG_INFO("path1 =%s\n",path1);
  14970. //DEBUG_INFO("ftppath=%s\n",ftppath);
  14971. //ftpFile(host, user, password, port, ftppath, fname);
  14972. //download firmware pthred
  14973. if(port == 0)
  14974. {
  14975. port = 21;
  14976. }
  14977. do
  14978. {
  14979. sleep(1);
  14980. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14981. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14982. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14983. sleep(1);
  14984. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14985. if(!isSuccess)
  14986. {
  14987. //BulldogUtil.sleepMs(interval*1000);
  14988. DEBUG_INFO("Update firmware request and download file fail.\n");
  14989. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14990. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14991. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14992. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14993. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14994. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14995. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14996. }
  14997. else
  14998. {
  14999. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15000. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  15001. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15002. }
  15003. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15004. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15005. }
  15006. else
  15007. {
  15008. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15009. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15010. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15011. sleep(1);
  15012. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15013. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15014. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15015. }
  15016. // Verify firmware image signature
  15017. struct stat st;
  15018. FILE *fp = fopen("/tmp/signingFirmwareUpdate.crt", "w");
  15019. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  15020. fclose(fp);
  15021. system("openssl x509 -pubkey -noout -in /tmp/signingFirmwareUpdate.crt > /tmp/signingFirmwareUpdate.key");
  15022. fp = fopen("/tmp/signingFirmwareUpdate.sign", "w");
  15023. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  15024. fclose(fp);
  15025. system("openssl base64 -d -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15026. stat("/tmp/signingFirmwareUpdate.sign.256", &st);
  15027. if(st.st_size == 0)
  15028. system("openssl base64 -d -A -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15029. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "Downloaded") != NULL)
  15030. {
  15031. sprintf(temp ,"openssl dgst -verify /tmp/signingFirmwareUpdate.key -signature /tmp/signingFirmwareUpdate.sign.256 /mnt/%s", firmwareFileName);
  15032. fp = popen(temp, "r");
  15033. if(fp)
  15034. {
  15035. while(fgets(temp, sizeof(temp), fp) != NULL)
  15036. {
  15037. if(strstr(temp, "Verified OK") != NULL)
  15038. {
  15039. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15040. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "SignatureVerified");
  15041. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15042. }
  15043. else
  15044. {
  15045. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15046. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InvalidSignature");
  15047. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15048. sleep(1);
  15049. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15050. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InstallationFailed");
  15051. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15052. sleep(1);
  15053. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15054. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15055. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15056. }
  15057. break;
  15058. }
  15059. }
  15060. pclose(fp);
  15061. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "SignatureVerified") != NULL)ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  15062. }
  15063. interLock.isUpdateFirmwareGoing = 0;
  15064. pthread_exit(NULL);
  15065. }
  15066. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  15067. {
  15068. mtrace();
  15069. int result = PASS;
  15070. pthread_t t;
  15071. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  15072. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Accepted");
  15073. sendSignedUpdateFirmwareConfirmation(uuid);
  15074. if(!interLock.isUpdateFirmwareGoing)
  15075. {
  15076. interLock.isUpdateFirmwareGoing = 1;
  15077. pthread_create(&t, NULL, SignedUpdateFirmwareProcess, payload);
  15078. sleep(1);
  15079. }
  15080. else
  15081. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  15082. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareConf = 1;
  15083. return result;
  15084. }
  15085. int handleUnknownRequest(char *uuid, char *payload)
  15086. {
  15087. mtrace();
  15088. int result = PASS;
  15089. DEBUG_INFO("handleUnknownRequest...\n");
  15090. sendUnknownConfirmation(uuid);
  15091. return result;
  15092. }
  15093. //==========================================
  15094. // Handle server response routine
  15095. //==========================================
  15096. void handleAuthorizeResponse(char *payload, int gun_index)
  15097. {
  15098. mtrace();
  15099. char expiryDatestr[36]={0};
  15100. char parentIdTagstr[21]={0};
  15101. char statusstr[20]={0};
  15102. int expiryDateISNULL=FALSE;
  15103. int parentIdTagISNULL=FALSE;
  15104. DEBUG_INFO("handleAuthorizeResponse...\n");
  15105. json_object *Authorize;
  15106. Authorize = json_tokener_parse(payload);
  15107. if(!is_error(Authorize))
  15108. {
  15109. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  15110. {
  15111. // Required data
  15112. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  15113. // Optional data
  15114. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  15115. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  15116. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  15117. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  15118. }
  15119. }
  15120. json_object_put(Authorize);
  15121. if(expiryDateISNULL == FALSE)
  15122. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  15123. if(parentIdTagISNULL == FALSE)
  15124. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  15125. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  15126. //Update idTag information to authorization cache if supproted
  15127. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  15128. {
  15129. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  15130. }
  15131. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  15132. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  15133. authorizeRetryTimes = 0;
  15134. }
  15135. void handleBootNotificationResponse(char *payload, int gun_index)
  15136. {
  15137. mtrace();
  15138. char statusStr[12]={0};
  15139. char currentTimeStr[30]={0};
  15140. int intervalInt = 0;
  15141. DEBUG_INFO("handleBootNotificationResponse...\n");
  15142. json_object *BootNotification;
  15143. BootNotification = json_tokener_parse(payload);
  15144. if(!is_error(BootNotification))
  15145. {
  15146. // Required data
  15147. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  15148. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  15149. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  15150. }
  15151. json_object_put(BootNotification);
  15152. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15153. BootNotificationInterval = intervalInt;
  15154. //write back to ShmOCPP16Data->BootNotification
  15155. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  15156. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15157. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  15158. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  15159. {
  15160. BootNotificationInterval = 0;
  15161. if((intervalInt == 0) || (intervalInt >= 10))
  15162. {
  15163. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  15164. HeartBeatWaitTime = intervalInt;
  15165. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  15166. }
  15167. server_sign = TRUE;
  15168. server_pending =FALSE;
  15169. }
  15170. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  15171. {
  15172. server_pending = TRUE;
  15173. }
  15174. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  15175. srand(time(NULL));
  15176. refreshStartTimer(&clientTime.Heartbeat);
  15177. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  15178. SetOcppConnStatus(TRUE);
  15179. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  15180. }
  15181. void handleDataTransferResponse(char *payload, int gun_index)
  15182. {
  15183. json_object *DataTransfer = json_tokener_parse(payload);
  15184. DEBUG_INFO("Corresponding gun-%d MessageId: %s\n", gun_index, ShmOCPP16Data->DataTransfer[gun_index].MessageId);
  15185. if(!is_error(DataTransfer))
  15186. {
  15187. // Required data
  15188. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  15189. // Optional data
  15190. if(json_object_object_get(DataTransfer, "data") != NULL)
  15191. {
  15192. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15193. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15194. if(!is_error(Data))
  15195. {
  15196. if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Authorize") != NULL)
  15197. {
  15198. if(json_object_object_get(Data, "certificateStatus") != NULL)
  15199. {
  15200. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "%s", json_object_get_string(json_object_object_get(Data, "certificateStatus")));
  15201. }
  15202. if(json_object_object_get(Data, "idTokenInfo") != NULL)
  15203. {
  15204. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "status") != NULL)
  15205. {
  15206. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "status")));
  15207. }
  15208. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "cacheExpiryDateTime") != NULL)
  15209. {
  15210. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.cacheExpiryDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "cacheExpiryDateTime")));
  15211. }
  15212. }
  15213. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  15214. }
  15215. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Get15118EVCertificate") != NULL)
  15216. {
  15217. if(json_object_object_get(Data, "status") != NULL)
  15218. {
  15219. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15220. }
  15221. if(json_object_object_get(Data, "exiResponse") != NULL)
  15222. {
  15223. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_exiResponse, "%s", json_object_get_string(json_object_object_get(Data, "exiResponse")));
  15224. }
  15225. ShmOCPP16Data->v2g_extend.Get15118EVCertificateConf = 1;
  15226. }
  15227. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "GetCertificateStatus") != NULL)
  15228. {
  15229. if(json_object_object_get(Data, "status") != NULL)
  15230. {
  15231. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15232. }
  15233. if(json_object_object_get(Data, "ocspResult") != NULL)
  15234. {
  15235. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_ocspResult, "%s", json_object_get_string(json_object_object_get(Data, "ocspResult")));
  15236. }
  15237. ShmOCPP16Data->v2g_extend.GetCertificateStatusConf = 1;
  15238. }
  15239. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "SignCertificate") != NULL)
  15240. {
  15241. sprintf((char*)ShmOCPP16Data->v2g_extend.SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15242. ShmOCPP16Data->v2g_extend.SignCertificateConf = 1;
  15243. }
  15244. else
  15245. {
  15246. if(json_object_object_get(Data, "msgId") != NULL)
  15247. {
  15248. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  15249. {
  15250. OCPP_update_deduct_info(json_object_get_int(json_object_object_get(Data, "txId")), (char*)json_object_get_string(json_object_object_get(Data, "creditNo")));
  15251. }
  15252. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  15253. {
  15254. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15255. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  15256. }
  15257. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_OccupancyFeeAct") != NULL)
  15258. {
  15259. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15260. {
  15261. sprintf((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_status, "%s", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  15262. if(json_object_object_get(Data, "occupancySN") != NULL)
  15263. sprintf((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_occupancySN, "%s", json_object_get_string(json_object_object_get(Data, "occupancySN")));
  15264. if(json_object_object_get(Data, "startTime") != NULL)
  15265. sprintf((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_startTime, "%s", json_object_get_string(json_object_object_get(Data, "startTime")));
  15266. if(json_object_object_get(Data, "duration") != NULL)
  15267. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_duration = json_object_get_int(json_object_object_get(Data, "duration"));
  15268. if(json_object_object_get(Data, "occupancyFee") != NULL)
  15269. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_occupancyFee = json_object_get_double(json_object_object_get(Data, "occupancyFee"));
  15270. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].OccupancyFeeActReq = 0;
  15271. }
  15272. else
  15273. {
  15274. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  15275. {
  15276. if(ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].OccupancyFeeActReq)
  15277. {
  15278. strcpy((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].response_status, "Rejected");
  15279. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].OccupancyFeeActReq = 0;
  15280. }
  15281. }
  15282. }
  15283. }
  15284. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_OccupancyDeductResult") != NULL)
  15285. {
  15286. if(json_object_object_get(Data, "occupancySN") != NULL)
  15287. OCPP_update_occupancyDeduct_info((char*)json_object_get_string(json_object_object_get(Data, "occupancySN")));
  15288. }
  15289. }
  15290. }
  15291. }
  15292. json_object_put(Data);
  15293. }
  15294. }
  15295. json_object_put(DataTransfer);
  15296. }
  15297. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  15298. {
  15299. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  15300. //struct json_object *obj;
  15301. // obj = json_tokener_parse(payload);
  15302. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  15303. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  15304. //No fields are defined.
  15305. }
  15306. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15307. {
  15308. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  15309. //struct json_object *obj;
  15310. // obj = json_tokener_parse(payload);
  15311. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  15312. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  15313. //No fields are defined.
  15314. }
  15315. void handleHeartbeatResponse(char *payload, int gun_index)
  15316. {
  15317. mtrace();
  15318. DEBUG_INFO("handleHeartbeatResponse...\n");
  15319. json_object *Heartbeat;
  15320. Heartbeat = json_tokener_parse(payload);
  15321. if(!is_error(Heartbeat))
  15322. {
  15323. // Required data
  15324. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  15325. }
  15326. json_object_put(Heartbeat);
  15327. if(FirstHeartBeat == 0)
  15328. {
  15329. FirstHeartBeat = 1;
  15330. DEBUG_INFO("FirstHeartBeat \n");
  15331. }
  15332. HeartBeatWithNOResponse = 0;
  15333. refreshStartTimer(&clientTime.Heartbeat);
  15334. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  15335. }
  15336. void handleMeterValuesResponse(char *payload, int gun_index)
  15337. {
  15338. mtrace();
  15339. DEBUG_INFO("handleMeterValuesResponse...\n");
  15340. isQueueSendable = 1;
  15341. }
  15342. void handleStartTransactionResponse(char *payload, int gun_index)
  15343. {
  15344. mtrace();
  15345. //int transactionIdInt = 0;
  15346. FILE *outfile;
  15347. char data[100]={0};
  15348. DEBUG_INFO("handleStartTransactionResponse...\n");
  15349. json_object *StartTransaction;
  15350. StartTransaction = json_tokener_parse(payload);
  15351. if(!is_error(StartTransaction))
  15352. {
  15353. // Required data
  15354. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  15355. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  15356. // Optional data
  15357. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  15358. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  15359. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15360. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  15361. }
  15362. json_object_put(StartTransaction);
  15363. OCPP_updatePeriodEnergy(gun_index);
  15364. //-----------Start : write to the Queue TransactionId file -----------------//
  15365. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  15366. {}
  15367. else
  15368. {
  15369. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  15370. if(log == NULL)
  15371. {
  15372. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  15373. return ;
  15374. }
  15375. else
  15376. {
  15377. fclose(log);
  15378. }
  15379. }
  15380. // open file for writing
  15381. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  15382. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  15383. {
  15384. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  15385. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  15386. fputs(data, outfile);
  15387. fclose (outfile);
  15388. DEBUG_INFO("Update QueueTransactionId done...\n");
  15389. }
  15390. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15391. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15392. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  15393. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  15394. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15395. isQueueSendable = 1;
  15396. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  15397. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  15398. }
  15399. void handleStatusNotificationResponse(char *payload, int gun_index)
  15400. {
  15401. mtrace();
  15402. DEBUG_INFO("handleStatusNotificationResponse...\n");
  15403. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15404. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15405. if(gun_index != 99)
  15406. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  15407. }
  15408. void handleStopTransactionnResponse(char *payload, int gun_index)
  15409. {
  15410. mtrace();
  15411. DEBUG_INFO("handleStopTransactionnResponse...\n");
  15412. json_object *StopTransaction;
  15413. StopTransaction = json_tokener_parse(payload);
  15414. if(!is_error(StopTransaction))
  15415. {
  15416. // Optional data
  15417. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  15418. {
  15419. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  15420. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  15421. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  15422. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15423. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  15424. }
  15425. }
  15426. json_object_put(StopTransaction);
  15427. isQueueSendable = 1;
  15428. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  15429. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  15430. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15431. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15432. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  15433. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  15434. }
  15435. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  15436. {
  15437. mtrace();
  15438. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  15439. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  15440. }
  15441. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  15442. {
  15443. mtrace();
  15444. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  15445. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  15446. }
  15447. void handleSignCertificateResponse(char *payload, int gun_index)
  15448. {
  15449. mtrace();
  15450. DEBUG_INFO("handleSignCertificateResponse...\n");
  15451. json_object *SignCertificate;
  15452. SignCertificate = json_tokener_parse(payload);
  15453. if(!is_error(SignCertificate))
  15454. {
  15455. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  15456. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  15457. }
  15458. json_object_put(SignCertificate);
  15459. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  15460. }
  15461. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15462. {
  15463. mtrace();
  15464. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  15465. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  15466. }
  15467. //==========================================
  15468. // Handle Error routine
  15469. //==========================================
  15470. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  15471. {
  15472. mtrace();
  15473. #ifdef SystemLogMessage
  15474. DEBUG_INFO("errorCode: %s\n", errorCode);
  15475. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  15476. DEBUG_INFO("errorDetails: %s\n", payload);
  15477. #endif
  15478. }
  15479. //===============================================
  15480. // Common routine
  15481. //===============================================
  15482. int initialConfigurationTable(void)
  15483. {
  15484. //clock_t start_t, end_t, total_t;
  15485. FILE *fp;
  15486. FILE *outfile;
  15487. char str[512]={0};
  15488. int confVersion = 24;
  15489. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  15490. //start_t = clock();
  15491. //printf("Starting of the program, start_t = %ld\n", start_t);
  15492. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  15493. // Check configuration file size is correct
  15494. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  15495. {
  15496. struct stat st;
  15497. stat("/Storage/OCPP/OCPPConfiguration", &st);
  15498. if(st.st_size < 3100)
  15499. {
  15500. system("rm -f /Storage/OCPP/OCPPConfiguration");
  15501. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  15502. }
  15503. }
  15504. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  15505. {
  15506. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15507. if(outfile == NULL)
  15508. {
  15509. DEBUG_INFO("Error opening file\n");
  15510. return FALSE;
  15511. }
  15512. /*Core Profile*/
  15513. //AllowOfflineTxForUnknownId
  15514. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  15517. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15518. //AuthorizationCacheEnabled
  15519. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15522. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15523. //AuthorizeRemoteTxRequests
  15524. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  15525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  15527. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15528. //BlinkRepeat
  15529. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15530. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15532. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15533. //ClockAlignedDataInterval
  15534. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15537. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15538. //ConnectionTimeOut
  15539. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15541. if(ShmSysConfigAndInfo->SysConfig.ModelName[3]=='J')
  15542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "55" );
  15543. else
  15544. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15545. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15546. //GetConfigurationMaxKeys
  15547. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15549. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  15550. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15551. // HeartbeatInterval
  15552. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  15555. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15556. // LightIntensity
  15557. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15560. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15561. // LocalAuthorizeOffline
  15562. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  15563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15566. // LocalPreAuthorize
  15567. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  15568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15571. // MaxEnergyOnInvalidId
  15572. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15575. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15576. // MeterValuesAlignedData
  15577. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15579. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15580. 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" );
  15581. else
  15582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15584. // MeterValuesAlignedDataMaxLength
  15585. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15587. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  15589. else
  15590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  15591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15592. // MeterValuesSampledData
  15593. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15595. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15596. 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" );
  15597. else
  15598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15599. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15600. // MeterValuesSampledDataMaxLength
  15601. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15603. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  15605. else
  15606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  15607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15608. // MeterValueSampleInterval
  15609. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  15612. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15613. // MinimumStatusDuration
  15614. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  15617. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  15618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15619. // NumberOfConnectors
  15620. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15622. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15623. {
  15624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15625. }
  15626. else
  15627. {
  15628. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15629. }
  15630. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15631. // ResetRetries
  15632. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15636. // ConnectorPhaseRotation
  15637. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15640. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15641. // ConnectorPhaseRotationMaxLength
  15642. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15645. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15646. // StopTransactionOnEVSideDisconnect
  15647. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  15648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15650. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15651. // StopTransactionOnInvalidId
  15652. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  15653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15655. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15656. // StopTxnAlignedData
  15657. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  15660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15661. // StopTxnAlignedDataMaxLength
  15662. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15664. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15665. {
  15666. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", 8);
  15667. }
  15668. else
  15669. {
  15670. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", 10);
  15671. }
  15672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15673. // StopTxnSampledData
  15674. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "" );
  15677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15678. // StopTxnSampledDataMaxLength
  15679. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15681. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15682. {
  15683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 8);
  15684. }
  15685. else
  15686. {
  15687. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 10);
  15688. }
  15689. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15690. // SupportedFeatureProfiles
  15691. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15694. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15695. // SupportedFeatureProfilesMaxLength
  15696. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15699. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15700. // TransactionMessageAttempts
  15701. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15704. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15706. // TransactionMessageRetryInterval
  15707. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15710. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15711. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15712. // UnlockConnectorOnEVSideDisconnect
  15713. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  15714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15716. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15717. // WebSocketPingInterval
  15718. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15722. // QueueOffLineMeterValues
  15723. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  15724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  15726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15727. // AuthorizationKey
  15728. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  15731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15732. // SecurityProfile
  15733. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15735. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  15736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15737. // DefaultPrice
  15738. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15742. // CustomDisplayCostAndPrice
  15743. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15747. // CustomIdleFeeAfterStop
  15748. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15751. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15752. // TimeOffset
  15753. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  15756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15757. // NextTimeOffsetTransitionDateTime
  15758. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  15761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15762. // TimeOffsetNextTransition
  15763. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  15766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15767. // SystemUptimeSec
  15768. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15772. // FreeVend
  15773. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15777. // FreeVendIdtag
  15778. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15782. // OcppServer
  15783. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15785. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15786. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15787. // MaintainServer
  15788. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15790. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  15791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15792. // StatusNotificationPeriodically
  15793. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  15794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15797. // StatusNotificationInterval
  15798. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15802. // PreAuthAmount
  15803. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  15806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15807. // isEnableLocalPowerSharing
  15808. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15810. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15812. // PowerSharingServerIP
  15813. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15815. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  15816. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15817. // EVCCID_PREFIX
  15818. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15821. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15822. // OffLineMaxChargingPower
  15823. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  15826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15827. // Configuration Version
  15828. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  15829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  15831. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15832. // Charging profile refresh interval
  15833. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  15834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  15835. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  15836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  15837. // CpoName
  15838. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  15839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  15840. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "Zerova");
  15841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  15842. // Ocpp Software certificated version
  15843. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  15844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  15845. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  15846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  15847. // Check certificate of download link
  15848. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = 1;
  15849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemName, "AuthDownloadlinkCertificate");
  15850. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "FALSE");
  15851. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthDownloadlinkCertificate", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData);
  15852. //* Local Auth List Management Profile*/
  15853. #if 0
  15854. //For OCTT Test Case
  15855. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  15857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15858. #endif
  15859. #if 1
  15860. //LocalAuthListEnabled
  15861. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15865. #endif
  15866. //LocalAuthListMaxLength
  15867. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  15870. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15871. //SendLocalListMaxLength
  15872. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  15875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15876. //ReserveConnectorZeroSupported
  15877. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15880. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15881. //* Smart Charging Profile */
  15882. //ChargeProfileMaxStackLevel
  15883. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  15886. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15887. // ChargingScheduleAllowedChargingRateUnit
  15888. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15889. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  15891. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15892. // ChargingScheduleMaxPeriods
  15893. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15897. // ConnectorSwitch3to1PhaseSupported
  15898. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  15901. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15902. // MaxChargingProfilesInstalled
  15903. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15904. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  15906. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15907. fclose(outfile);
  15908. }
  15909. else
  15910. {
  15911. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  15912. char keystr[60]={0};
  15913. char readonlystr[10]={0};
  15914. char valuestr[256]={0};
  15915. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  15916. if(fp == NULL) {
  15917. DEBUG_INFO("Error opening file");
  15918. return FALSE;
  15919. }
  15920. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  15921. {
  15922. //DEBUG_INFO("Get Configuration \n");
  15923. if(strlen(str) > 0)
  15924. {
  15925. json_object *OCPPConfiguration;
  15926. OCPPConfiguration = json_tokener_parse(str);
  15927. if(json_object_object_get(OCPPConfiguration, "key") != NULL)
  15928. strcpy(keystr, json_object_get_string(json_object_object_get(OCPPConfiguration,"key")));
  15929. if(json_object_object_get(OCPPConfiguration, "readonly") != NULL)
  15930. strcpy(readonlystr, json_object_get_string(json_object_object_get(OCPPConfiguration,"readonly")));
  15931. if(json_object_object_get(OCPPConfiguration, "value") != NULL)
  15932. strcpy(valuestr, json_object_get_string(json_object_object_get(OCPPConfiguration,"value")));
  15933. json_object_put(OCPPConfiguration);
  15934. // DEBUG_INFO("keystr=%s\n",keystr);
  15935. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  15936. // DEBUG_INFO("valuestr=%s\n",valuestr);
  15937. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  15938. {
  15939. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15940. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15941. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  15942. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  15943. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  15944. }
  15945. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  15946. {
  15947. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15948. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  15950. }
  15951. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  15952. {
  15953. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15954. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  15955. }
  15956. if(strcmp(keystr, "BlinkRepeat") == 0)
  15957. {
  15958. //Charger.BlinkRepeat = Integer.parseInt(value);
  15959. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15960. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  15961. }
  15962. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  15963. {
  15964. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15965. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  15966. }
  15967. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  15968. {
  15969. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15970. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  15971. }
  15972. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  15973. {
  15974. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15975. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  15976. }
  15977. if(strcmp(keystr, "HeartbeatInterval") == 0)
  15978. {
  15979. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15980. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  15981. HeartBeatWaitTime = atoi(valuestr);
  15982. }
  15983. if(strcmp(keystr, "LightIntensity") == 0)
  15984. {
  15985. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15986. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  15987. }
  15988. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  15989. {
  15990. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  15992. }
  15993. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  15994. {
  15995. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15996. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  15997. }
  15998. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  15999. {
  16000. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16001. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  16002. }
  16003. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  16004. {
  16005. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16006. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  16007. }
  16008. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  16009. {
  16010. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  16012. }
  16013. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  16014. {
  16015. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16016. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  16017. }
  16018. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  16019. {
  16020. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16021. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  16022. }
  16023. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  16024. {
  16025. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16026. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  16027. }
  16028. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  16029. {
  16030. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16031. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  16032. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  16033. }
  16034. if(strcmp(keystr, "NumberOfConnectors") == 0)
  16035. {
  16036. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  16038. }
  16039. if(strcmp(keystr, "ResetRetries") == 0)
  16040. {
  16041. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16042. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  16043. }
  16044. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  16045. {
  16046. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16047. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  16048. }
  16049. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  16050. {
  16051. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  16053. }
  16054. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  16055. {
  16056. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  16058. }
  16059. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  16060. {
  16061. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16062. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  16063. }
  16064. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  16065. {
  16066. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16067. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  16068. }
  16069. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  16070. {
  16071. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16072. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16073. }
  16074. if(strcmp(keystr, "StopTxnSampledData") == 0)
  16075. {
  16076. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16077. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  16078. }
  16079. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  16080. {
  16081. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16082. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16083. }
  16084. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  16085. {
  16086. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16087. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  16088. }
  16089. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  16090. {
  16091. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16092. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  16093. }
  16094. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  16095. {
  16096. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16097. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  16098. TransactionMessageAttemptsValue = atoi(valuestr);
  16099. }
  16100. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  16101. {
  16102. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  16104. TransactionMessageRetryIntervalValue = atoi(valuestr);
  16105. }
  16106. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  16107. {
  16108. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16109. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  16110. }
  16111. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  16112. {
  16113. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16114. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  16115. }
  16116. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  16117. {
  16118. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16119. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  16120. }
  16121. if(strcmp(keystr, "AuthorizationKey") == 0)
  16122. {
  16123. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16124. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  16125. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  16126. }
  16127. if(strcmp(keystr, "SecurityProfile") == 0)
  16128. {
  16129. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16130. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  16131. }
  16132. if(strcmp(keystr, "DefaultPrice") == 0)
  16133. {
  16134. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16135. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  16136. }
  16137. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  16138. {
  16139. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  16141. }
  16142. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  16143. {
  16144. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16145. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  16146. }
  16147. if(strcmp(keystr, "TimeOffset") == 0)
  16148. {
  16149. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16150. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  16151. }
  16152. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  16153. {
  16154. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16155. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  16156. }
  16157. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  16158. {
  16159. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16160. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  16161. }
  16162. if(strcmp(keystr, "SystemUptimeSec") == 0)
  16163. {
  16164. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16165. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  16166. }
  16167. if(strcmp(keystr, "FreeVend") == 0)
  16168. {
  16169. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16170. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  16171. }
  16172. if(strcmp(keystr, "FreeVendIdtag") == 0)
  16173. {
  16174. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16175. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  16176. }
  16177. if(strcmp(keystr, "OcppServer") == 0)
  16178. {
  16179. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16180. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  16181. }
  16182. if(strcmp(keystr, "MaintainServer") == 0)
  16183. {
  16184. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16185. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  16186. }
  16187. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  16188. {
  16189. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16190. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  16191. }
  16192. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  16193. {
  16194. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16195. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  16196. }
  16197. if(strcmp(keystr, "PreAuthAmount") == 0)
  16198. {
  16199. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16200. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  16201. }
  16202. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  16203. {
  16204. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16205. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  16206. }
  16207. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  16208. {
  16209. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16210. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  16211. }
  16212. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  16213. {
  16214. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16215. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  16216. }
  16217. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  16218. {
  16219. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16220. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  16221. }
  16222. if(strcmp(keystr, "ConfigurationVersion") == 0)
  16223. {
  16224. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16225. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  16226. }
  16227. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  16228. {
  16229. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16230. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  16231. }
  16232. if(strcmp(keystr, "CpoName") == 0)
  16233. {
  16234. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", valuestr);
  16236. }
  16237. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  16238. {
  16239. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16240. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  16241. }
  16242. if(strcmp(keystr, "AuthDownloadlinkCertificate") == 0)
  16243. {
  16244. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16245. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "%s", valuestr);
  16246. }
  16247. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  16248. {
  16249. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16250. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  16251. }
  16252. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  16253. {
  16254. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16255. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  16256. }
  16257. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  16258. {
  16259. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16260. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  16261. }
  16262. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  16263. {
  16264. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16265. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  16266. }
  16267. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  16268. {
  16269. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16270. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  16271. }
  16272. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16273. {
  16274. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16275. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  16276. }
  16277. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  16278. {
  16279. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16280. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  16281. }
  16282. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  16283. {
  16284. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16285. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  16286. }
  16287. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  16288. {
  16289. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16290. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  16291. }
  16292. }
  16293. }
  16294. fclose(fp);
  16295. }
  16296. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  16297. {
  16298. return PASS;
  16299. }
  16300. else
  16301. {
  16302. return FAIL;
  16303. }
  16304. }
  16305. void StoreConfigurationTable(void)
  16306. {
  16307. FILE *outfile;
  16308. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  16309. if(outfile == NULL)
  16310. {
  16311. DEBUG_INFO("Error opening file");
  16312. return ;
  16313. }
  16314. /*Core Profile*/
  16315. //AllowOfflineTxForUnknownId
  16316. /*
  16317. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  16318. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  16319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  16320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  16321. */
  16322. //DEBUG_INFO("data=%s\n",data);
  16323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  16324. //AuthorizationCacheEnabled
  16325. /*
  16326. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  16327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  16328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  16329. */
  16330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  16331. //AuthorizeRemoteTxRequests
  16332. /*
  16333. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  16334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  16335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  16336. */
  16337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  16338. //BlinkRepeat
  16339. /*
  16340. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  16341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  16342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  16343. */
  16344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  16345. //ClockAlignedDataInterval
  16346. /*
  16347. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  16348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  16349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  16350. */
  16351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  16352. //ConnectionTimeOut
  16353. /*
  16354. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  16355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  16356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  16357. */
  16358. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  16359. //GetConfigurationMaxKeys
  16360. /*
  16361. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  16362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  16363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  16364. */
  16365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  16366. // HeartbeatInterval
  16367. /*
  16368. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  16369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  16370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  16371. */
  16372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  16373. // LightIntensity
  16374. /*
  16375. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  16376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  16377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  16378. */
  16379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  16380. // LocalAuthorizeOffline
  16381. /*
  16382. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  16383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  16384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  16385. */
  16386. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16387. // LocalPreAuthorize
  16388. /*
  16389. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  16390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  16391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  16392. */
  16393. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  16394. // MaxEnergyOnInvalidId
  16395. /*
  16396. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  16397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  16398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  16399. */
  16400. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  16401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  16402. // MeterValuesAlignedData
  16403. /*
  16404. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  16405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  16406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16407. */
  16408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  16409. // MeterValuesAlignedDataMaxLength
  16410. /*
  16411. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  16412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  16413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  16414. */
  16415. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  16416. // MeterValuesSampledData
  16417. /*
  16418. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  16419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  16420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16421. */
  16422. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  16423. // MeterValuesSampledDataMaxLength
  16424. /*
  16425. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  16426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  16427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  16428. */
  16429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  16430. // MeterValueSampleInterval
  16431. /*
  16432. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  16433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  16434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  16435. */
  16436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  16437. // MinimumStatusDuration
  16438. /*
  16439. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  16440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  16441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  16442. */
  16443. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16444. // NumberOfConnectors
  16445. /*
  16446. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  16447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  16448. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16449. {
  16450. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  16451. }
  16452. else
  16453. {
  16454. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  16455. }
  16456. */
  16457. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  16458. // ResetRetries
  16459. /*
  16460. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  16461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  16462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  16463. */
  16464. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  16465. // ConnectorPhaseRotation
  16466. /*
  16467. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  16468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  16469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  16470. */
  16471. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  16472. // ConnectorPhaseRotationMaxLength
  16473. /*
  16474. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  16475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  16476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  16477. */
  16478. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  16479. // StopTransactionOnEVSideDisconnect
  16480. /*
  16481. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  16482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  16483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  16484. */
  16485. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  16486. // StopTransactionOnInvalidId
  16487. /*
  16488. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  16489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  16490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  16491. */
  16492. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  16493. // StopTxnAlignedData
  16494. /*
  16495. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  16496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  16497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  16498. */
  16499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  16500. // StopTxnAlignedDataMaxLength
  16501. /*
  16502. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  16503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  16504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  16505. */
  16506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  16507. // StopTxnSampledData
  16508. /*
  16509. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  16510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  16511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  16512. */
  16513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  16514. // StopTxnSampledDataMaxLength
  16515. /*
  16516. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  16517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  16518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  16519. */
  16520. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  16521. // SupportedFeatureProfiles
  16522. /*
  16523. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  16524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  16525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  16526. */
  16527. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  16528. // SupportedFeatureProfilesMaxLength
  16529. /*
  16530. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  16531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  16532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  16533. */
  16534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  16535. // TransactionMessageAttempts
  16536. /*
  16537. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  16538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  16539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  16540. */
  16541. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16542. // TransactionMessageRetryInterval
  16543. /*
  16544. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  16545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  16546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  16547. */
  16548. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16549. // UnlockConnectorOnEVSideDisconnect
  16550. /*
  16551. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  16552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  16553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  16554. */
  16555. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  16556. // WebSocketPingInterval
  16557. /*
  16558. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  16559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  16560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  16561. */
  16562. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16563. // QueueOffLineMeterValues
  16564. /*
  16565. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  16566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  16567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  16568. */
  16569. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  16570. // AuthorizationKey
  16571. /*
  16572. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  16573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  16574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  16575. */
  16576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16577. // SecurityProfile
  16578. /*
  16579. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  16580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  16581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  16582. */
  16583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16584. // DefaultPrice
  16585. /*
  16586. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  16587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  16588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  16589. */
  16590. json_object *tmp;
  16591. tmp = json_tokener_parse((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16592. if(!is_error(tmp))
  16593. {
  16594. DEBUG_INFO("JSON string type\n");
  16595. json_object *target = json_object_new_object();
  16596. json_object_object_add(target, "key", json_object_new_string("DefaultPrice"));
  16597. json_object_object_add(target, "readonly", (ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility?json_object_new_boolean(0):json_object_new_boolean(1)));
  16598. json_object_object_add(target, "value", json_object_new_string((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData));
  16599. fprintf(outfile, "%s\n", json_object_to_json_string_ext(target, JSON_C_TO_STRING_PLAIN));
  16600. json_object_put(target);
  16601. }
  16602. else
  16603. {
  16604. DEBUG_INFO("Normal string type\n");
  16605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16606. }
  16607. json_object_put(tmp);
  16608. // CustomDisplayCostAndPrice
  16609. /*
  16610. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  16611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  16612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  16613. */
  16614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  16615. // CustomIdleFeeAfterStop
  16616. /*
  16617. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  16618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  16619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  16620. */
  16621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  16622. // TimeOffset
  16623. /*
  16624. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  16625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  16626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  16627. */
  16628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  16629. // NextTimeOffsetTransitionDateTime
  16630. /*
  16631. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  16632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  16633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  16634. */
  16635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  16636. // TimeOffsetNextTransition
  16637. /*
  16638. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  16639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  16640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  16641. */
  16642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  16643. // SystemUptimeSec
  16644. /*
  16645. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  16646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  16647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  16648. */
  16649. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  16650. // FreeVend
  16651. /*
  16652. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  16653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  16654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  16655. */
  16656. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  16657. // FreeVendIdtag
  16658. /*
  16659. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  16660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  16661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  16662. */
  16663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16664. // OcppServer
  16665. /*
  16666. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  16667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  16668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  16669. */
  16670. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16671. // MaintainServer
  16672. /*
  16673. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  16674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  16675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  16676. */
  16677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16678. // StatusNotificationPeriodically
  16679. /*
  16680. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  16681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  16682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  16683. */
  16684. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  16685. // StatusNotificationInterval
  16686. /*
  16687. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  16688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  16689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  16690. */
  16691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  16692. // PreAuthAmount
  16693. /*
  16694. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  16695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  16696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  16697. */
  16698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  16699. // isEnableLocalPowerSharing
  16700. /*
  16701. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  16702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  16703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  16704. */
  16705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  16706. // PowerSharingServerIP
  16707. /*
  16708. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  16709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  16710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  16711. */
  16712. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  16713. // EVCCID_PREFIX
  16714. /*
  16715. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  16716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  16717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  16718. */
  16719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  16720. // OffLineMaxChargingPower
  16721. /*
  16722. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  16723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  16724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  16725. */
  16726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  16727. // ConfigurationVersion
  16728. /*
  16729. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  16730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  16731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  16732. */
  16733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  16734. // CharingProfileRefreshInterval
  16735. /*
  16736. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  16737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  16738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  16739. */
  16740. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  16741. // CpoName
  16742. /*
  16743. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  16744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  16745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "" );
  16746. */
  16747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  16748. // OcppSoftwareVersion
  16749. /*
  16750. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  16751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  16752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  16753. */
  16754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  16755. // AuthDownloadlinkCertificate
  16756. /*
  16757. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = 1;
  16758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemName, "AuthDownloadlinkCertificate");
  16759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE" );
  16760. */
  16761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthDownloadlinkCertificate", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData);
  16762. //* Local Auth List Management Profile*/
  16763. //LocalAuthListEnabled
  16764. /*
  16765. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  16766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  16767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  16768. */
  16769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16770. //LocalAuthListMaxLength
  16771. /*
  16772. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  16773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  16774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  16775. */
  16776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  16777. //SendLocalListMaxLength
  16778. /*
  16779. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  16780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  16781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  16782. */
  16783. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  16784. //ReserveConnectorZeroSupported
  16785. /*
  16786. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  16787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  16788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  16789. */
  16790. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16791. //* Smart Charging Profile */
  16792. //ChargeProfileMaxStackLevel
  16793. /*
  16794. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  16795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  16796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  16797. */
  16798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16799. // ChargingScheduleAllowedChargingRateUnit
  16800. /*
  16801. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  16802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  16803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  16804. */
  16805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16806. // ChargingScheduleMaxPeriods
  16807. /*
  16808. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  16809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  16810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  16811. */
  16812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16813. // ConnectorSwitch3to1PhaseSupported
  16814. /*
  16815. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  16816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  16817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  16818. */
  16819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16820. // MaxChargingProfilesInstalled
  16821. /*
  16822. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  16823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  16824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  16825. */
  16826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16827. fclose(outfile);
  16828. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16829. }
  16830. void getKeyValue(char *keyReq)
  16831. {
  16832. int isEmpty = FALSE;
  16833. int isKnowKey = FALSE;
  16834. DEBUG_INFO("keyReq = %s\n", keyReq);
  16835. if((keyReq == NULL) || (strlen(keyReq) == 0))
  16836. isEmpty = TRUE;
  16837. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  16838. {
  16839. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  16840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  16841. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16842. {
  16843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  16844. }
  16845. else
  16846. {
  16847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  16848. }
  16849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  16850. isKnowKey = TRUE;
  16851. }
  16852. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  16853. {
  16854. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  16855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  16856. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16857. {
  16858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  16859. }
  16860. else
  16861. {
  16862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  16863. }
  16864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  16865. isKnowKey = TRUE;
  16866. }
  16867. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  16868. {
  16869. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  16870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  16871. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16872. {
  16873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  16874. }
  16875. else
  16876. {
  16877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  16878. }
  16879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  16880. isKnowKey = TRUE;
  16881. }
  16882. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  16883. {
  16884. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  16885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  16886. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16887. {
  16888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  16889. }
  16890. else
  16891. {
  16892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  16893. }
  16894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  16895. isKnowKey = TRUE;
  16896. }
  16897. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  16898. {
  16899. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  16900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  16901. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16902. {
  16903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  16904. }
  16905. else
  16906. {
  16907. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  16908. }
  16909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  16910. isKnowKey = TRUE;
  16911. }
  16912. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  16913. {
  16914. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  16915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  16916. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16917. {
  16918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  16919. }
  16920. else
  16921. {
  16922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  16923. }
  16924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  16925. isKnowKey = TRUE;
  16926. }
  16927. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  16928. {
  16929. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  16930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  16931. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16932. {
  16933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  16934. }
  16935. else
  16936. {
  16937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  16938. }
  16939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  16940. isKnowKey = TRUE;
  16941. }
  16942. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  16943. {
  16944. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  16945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  16946. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16947. {
  16948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  16949. }
  16950. else
  16951. {
  16952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  16953. }
  16954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  16955. isKnowKey = TRUE;
  16956. }
  16957. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  16958. {
  16959. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  16960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  16961. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  16962. {
  16963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  16964. }
  16965. else
  16966. {
  16967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  16968. }
  16969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  16970. isKnowKey = TRUE;
  16971. }
  16972. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  16973. {
  16974. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  16975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  16976. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  16977. {
  16978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  16979. }
  16980. else
  16981. {
  16982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  16983. }
  16984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  16985. isKnowKey = TRUE;
  16986. }
  16987. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  16988. {
  16989. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  16990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  16991. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  16992. {
  16993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  16994. }
  16995. else
  16996. {
  16997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  16998. }
  16999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  17000. isKnowKey = TRUE;
  17001. }
  17002. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  17003. {
  17004. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  17005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  17006. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  17007. {
  17008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17009. }
  17010. else
  17011. {
  17012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17013. }
  17014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  17015. isKnowKey = TRUE;
  17016. }
  17017. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  17018. {
  17019. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  17020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  17021. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  17022. {
  17023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17024. }
  17025. else
  17026. {
  17027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17028. }
  17029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  17030. isKnowKey = TRUE;
  17031. }
  17032. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  17033. {
  17034. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  17035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  17036. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  17037. {
  17038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17039. }
  17040. else
  17041. {
  17042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17043. }
  17044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  17045. isKnowKey = TRUE;
  17046. }
  17047. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  17048. {
  17049. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  17050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  17051. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  17052. {
  17053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  17054. }
  17055. else
  17056. {
  17057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  17058. }
  17059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  17060. isKnowKey = TRUE;
  17061. }
  17062. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  17063. {
  17064. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  17065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  17066. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  17067. {
  17068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17069. }
  17070. else
  17071. {
  17072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17073. }
  17074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  17075. isKnowKey = TRUE;
  17076. }
  17077. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  17078. {
  17079. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  17080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  17081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  17082. {
  17083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  17084. }
  17085. else
  17086. {
  17087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  17088. }
  17089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  17090. isKnowKey = TRUE;
  17091. }
  17092. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  17093. {
  17094. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  17095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  17096. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  17097. {
  17098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  17099. }
  17100. else
  17101. {
  17102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  17103. }
  17104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  17105. isKnowKey = TRUE;
  17106. }
  17107. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  17108. {
  17109. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  17110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  17111. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  17112. {
  17113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  17114. }
  17115. else
  17116. {
  17117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  17118. }
  17119. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  17120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  17121. isKnowKey = TRUE;
  17122. }
  17123. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  17124. {
  17125. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  17126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  17127. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  17128. {
  17129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  17130. }
  17131. else
  17132. {
  17133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  17134. }
  17135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  17136. isKnowKey = TRUE;
  17137. }
  17138. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  17139. {
  17140. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  17141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  17142. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17143. {
  17144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  17145. }
  17146. else
  17147. {
  17148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  17149. }
  17150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  17151. isKnowKey = TRUE;
  17152. }
  17153. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  17154. {
  17155. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  17156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  17157. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  17158. {
  17159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17160. }
  17161. else
  17162. {
  17163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17164. }
  17165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  17166. isKnowKey = TRUE;
  17167. }
  17168. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  17169. {
  17170. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  17171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  17172. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17173. {
  17174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17175. }
  17176. else
  17177. {
  17178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17179. }
  17180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  17181. isKnowKey = TRUE;
  17182. }
  17183. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  17184. {
  17185. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  17186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  17187. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17188. {
  17189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17190. }
  17191. else
  17192. {
  17193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17194. }
  17195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  17196. isKnowKey = TRUE;
  17197. }
  17198. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  17199. {
  17200. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  17201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  17202. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17203. {
  17204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17205. }
  17206. else
  17207. {
  17208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17209. }
  17210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  17211. isKnowKey = TRUE;
  17212. }
  17213. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  17214. {
  17215. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  17216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  17217. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17218. {
  17219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17220. }
  17221. else
  17222. {
  17223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17224. }
  17225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  17226. isKnowKey = TRUE;
  17227. }
  17228. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  17229. {
  17230. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  17231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  17232. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17233. {
  17234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  17235. }
  17236. else
  17237. {
  17238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  17239. }
  17240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  17241. isKnowKey = TRUE;
  17242. }
  17243. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  17244. {
  17245. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  17246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  17247. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17248. {
  17249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17250. }
  17251. else
  17252. {
  17253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17254. }
  17255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  17256. isKnowKey = TRUE;
  17257. }
  17258. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  17259. {
  17260. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  17261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  17262. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17263. {
  17264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  17265. }
  17266. else
  17267. {
  17268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  17269. }
  17270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  17271. isKnowKey = TRUE;
  17272. }
  17273. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  17274. {
  17275. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  17276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  17277. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17278. {
  17279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17280. }
  17281. else
  17282. {
  17283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17284. }
  17285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  17286. isKnowKey = TRUE;
  17287. }
  17288. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  17289. {
  17290. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  17291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  17292. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17293. {
  17294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  17295. }
  17296. else
  17297. {
  17298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  17299. }
  17300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  17301. isKnowKey = TRUE;
  17302. }
  17303. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  17304. {
  17305. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  17306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  17307. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17308. {
  17309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  17310. }
  17311. else
  17312. {
  17313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  17314. }
  17315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  17316. isKnowKey = TRUE;
  17317. }
  17318. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  17319. {
  17320. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  17321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  17322. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17323. {
  17324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17325. }
  17326. else
  17327. {
  17328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17329. }
  17330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  17331. isKnowKey = TRUE;
  17332. }
  17333. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  17334. {
  17335. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  17336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  17337. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17338. {
  17339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  17340. }
  17341. else
  17342. {
  17343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  17344. }
  17345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  17346. isKnowKey = TRUE;
  17347. }
  17348. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  17349. {
  17350. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  17351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  17352. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17353. {
  17354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  17355. }
  17356. else
  17357. {
  17358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  17359. }
  17360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  17361. isKnowKey = TRUE;
  17362. }
  17363. /*
  17364. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  17365. {
  17366. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  17367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  17368. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  17369. {
  17370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  17371. }
  17372. else
  17373. {
  17374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  17375. }
  17376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  17377. isKnowKey = TRUE;
  17378. }*/
  17379. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  17380. {
  17381. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  17382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  17383. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17384. {
  17385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  17386. }
  17387. else
  17388. {
  17389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  17390. }
  17391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  17392. isKnowKey = TRUE;
  17393. }
  17394. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  17395. {
  17396. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  17397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  17398. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  17399. {
  17400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  17401. }
  17402. else
  17403. {
  17404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  17405. }
  17406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  17407. isKnowKey = TRUE;
  17408. }
  17409. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  17410. {
  17411. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  17412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  17413. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17414. {
  17415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  17416. }
  17417. else
  17418. {
  17419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  17420. }
  17421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  17422. isKnowKey = TRUE;
  17423. }
  17424. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  17425. {
  17426. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  17427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  17428. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17429. {
  17430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  17431. }
  17432. else
  17433. {
  17434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  17435. }
  17436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  17437. isKnowKey = TRUE;
  17438. }
  17439. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  17440. {
  17441. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  17442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  17443. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17444. {
  17445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  17446. }
  17447. else
  17448. {
  17449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  17450. }
  17451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  17452. isKnowKey = TRUE;
  17453. }
  17454. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  17455. {
  17456. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  17457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  17458. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17459. {
  17460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  17461. }
  17462. else
  17463. {
  17464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  17465. }
  17466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  17467. isKnowKey = TRUE;
  17468. }
  17469. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  17470. {
  17471. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  17472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  17473. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17474. {
  17475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  17476. }
  17477. else
  17478. {
  17479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  17480. }
  17481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  17482. isKnowKey = TRUE;
  17483. }
  17484. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  17485. {
  17486. struct sysinfo s_info;
  17487. int error = sysinfo(&s_info);
  17488. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  17489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  17490. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  17491. {
  17492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  17493. }
  17494. else
  17495. {
  17496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  17497. }
  17498. if(error != 0)
  17499. {
  17500. DEBUG_WARN("System uptime get error: %d\n", error);
  17501. }
  17502. else
  17503. {
  17504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  17505. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  17506. }
  17507. isKnowKey = TRUE;
  17508. }
  17509. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  17510. {
  17511. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  17512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  17513. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17514. {
  17515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  17516. }
  17517. else
  17518. {
  17519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  17520. }
  17521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  17522. isKnowKey = TRUE;
  17523. }
  17524. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  17525. {
  17526. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  17527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  17528. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17529. {
  17530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  17531. }
  17532. else
  17533. {
  17534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  17535. }
  17536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  17537. isKnowKey = TRUE;
  17538. }
  17539. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  17540. {
  17541. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  17542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  17543. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17544. {
  17545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  17546. }
  17547. else
  17548. {
  17549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  17550. }
  17551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  17552. isKnowKey = TRUE;
  17553. }
  17554. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  17555. {
  17556. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  17557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  17558. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17559. {
  17560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  17561. }
  17562. else
  17563. {
  17564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  17565. }
  17566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  17567. isKnowKey = TRUE;
  17568. }
  17569. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  17570. {
  17571. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  17572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  17573. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17574. {
  17575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  17576. }
  17577. else
  17578. {
  17579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  17580. }
  17581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  17582. isKnowKey = TRUE;
  17583. }
  17584. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  17585. {
  17586. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  17587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  17588. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17589. {
  17590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  17591. }
  17592. else
  17593. {
  17594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  17595. }
  17596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  17597. isKnowKey = TRUE;
  17598. }
  17599. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  17600. {
  17601. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  17602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  17603. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17604. {
  17605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  17606. }
  17607. else
  17608. {
  17609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  17610. }
  17611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  17612. isKnowKey = TRUE;
  17613. }
  17614. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  17615. {
  17616. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  17617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  17618. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17619. {
  17620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  17621. }
  17622. else
  17623. {
  17624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  17625. }
  17626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  17627. isKnowKey = TRUE;
  17628. }
  17629. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  17630. {
  17631. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  17632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  17633. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17634. {
  17635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  17636. }
  17637. else
  17638. {
  17639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  17640. }
  17641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  17642. isKnowKey = TRUE;
  17643. }
  17644. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  17645. {
  17646. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  17647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  17648. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17649. {
  17650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  17651. }
  17652. else
  17653. {
  17654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  17655. }
  17656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  17657. isKnowKey = TRUE;
  17658. }
  17659. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  17660. {
  17661. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  17662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  17663. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17664. {
  17665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  17666. }
  17667. else
  17668. {
  17669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  17670. }
  17671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  17672. isKnowKey = TRUE;
  17673. }
  17674. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  17675. {
  17676. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  17677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  17678. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  17679. {
  17680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  17681. }
  17682. else
  17683. {
  17684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  17685. }
  17686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  17687. isKnowKey = TRUE;
  17688. }
  17689. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  17690. {
  17691. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  17692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  17693. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  17694. {
  17695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  17696. }
  17697. else
  17698. {
  17699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  17700. }
  17701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  17702. isKnowKey = TRUE;
  17703. }
  17704. if(isEmpty || strcmp(keyReq, "CpoName") == 0 )
  17705. {
  17706. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CpoName].Item, "CpoName");
  17707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Key, "CpoName");
  17708. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  17709. {
  17710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "0"/*"FALSE"*/);
  17711. }
  17712. else
  17713. {
  17714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "1"/*"TRUE"*/);
  17715. }
  17716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData );
  17717. isKnowKey = TRUE;
  17718. }
  17719. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  17720. {
  17721. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  17722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  17723. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  17724. {
  17725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  17726. }
  17727. else
  17728. {
  17729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  17730. }
  17731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  17732. isKnowKey = TRUE;
  17733. }
  17734. if(isEmpty || strcmp(keyReq, "AuthDownloadlinkCertificate") == 0 )
  17735. {
  17736. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthDownloadlinkCertificate].Item, "AuthDownloadlinkCertificate");
  17737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].Key, "AuthDownloadlinkCertificate");
  17738. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility == 1)
  17739. {
  17740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].ReadOnly, "0"/*"FALSE"*/);
  17741. }
  17742. else
  17743. {
  17744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].ReadOnly, "1"/*"TRUE"*/);
  17745. }
  17746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData );
  17747. isKnowKey = TRUE;
  17748. }
  17749. #if 1
  17750. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  17751. {
  17752. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  17753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  17754. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17755. {
  17756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  17757. }
  17758. else
  17759. {
  17760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  17761. }
  17762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  17763. isKnowKey = TRUE;
  17764. }
  17765. #endif
  17766. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  17767. {
  17768. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  17769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  17770. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17771. {
  17772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17773. }
  17774. else
  17775. {
  17776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17777. }
  17778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  17779. isKnowKey = TRUE;
  17780. }
  17781. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  17782. {
  17783. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  17784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  17785. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17786. {
  17787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17788. }
  17789. else
  17790. {
  17791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17792. }
  17793. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  17794. isKnowKey = TRUE;
  17795. }
  17796. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  17797. {
  17798. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  17799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  17800. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17801. {
  17802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  17803. }
  17804. else
  17805. {
  17806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  17807. }
  17808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  17809. isKnowKey = TRUE;
  17810. }
  17811. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  17812. {
  17813. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  17814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  17815. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17816. {
  17817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  17818. }
  17819. else
  17820. {
  17821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  17822. }
  17823. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  17824. isKnowKey = TRUE;
  17825. }
  17826. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  17827. {
  17828. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  17829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  17830. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17831. {
  17832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  17833. }
  17834. else
  17835. {
  17836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  17837. }
  17838. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  17839. isKnowKey = TRUE;
  17840. }
  17841. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  17842. {
  17843. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  17844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  17845. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17846. {
  17847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  17848. }
  17849. else
  17850. {
  17851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  17852. }
  17853. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  17854. isKnowKey = TRUE;
  17855. }
  17856. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  17857. {
  17858. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  17859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  17860. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17861. {
  17862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  17863. }
  17864. else
  17865. {
  17866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  17867. }
  17868. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  17869. isKnowKey = TRUE;
  17870. }
  17871. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  17872. {
  17873. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  17874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  17875. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17876. {
  17877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  17878. }
  17879. else
  17880. {
  17881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  17882. }
  17883. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  17884. isKnowKey = TRUE;
  17885. }
  17886. //=========================================================
  17887. if(!isEmpty && !isKnowKey)
  17888. {
  17889. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  17890. strcpy(unknownkey[UnknownKeynum], keyReq);
  17891. UnknownKeynum = UnknownKeynum + 1;
  17892. }
  17893. }
  17894. void processUnkownKey(void)
  17895. {
  17896. DEBUG_INFO("processUnkownKey...\n");
  17897. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  17898. for(int index=0; index < UnknownKeynum; index++)
  17899. {
  17900. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  17901. {
  17902. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  17903. }
  17904. }
  17905. }
  17906. int setKeyValue(char *key, char *value)
  17907. {
  17908. int isSuccess = NotSupported;
  17909. int check_ascii=0;
  17910. char str[501]={0};
  17911. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  17912. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  17913. {
  17914. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  17915. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  17916. {
  17917. strcpy(str, (const char*)value);
  17918. for(int i = 0; str[i]; i++){
  17919. str[i] = tolower(str[i]);
  17920. }
  17921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17922. isSuccess = ConfigurationStatus_Accepted;
  17923. }
  17924. else
  17925. {
  17926. isSuccess = ConfigurationStatus_Rejected;
  17927. }
  17928. }
  17929. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  17930. {
  17931. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  17932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  17933. {
  17934. strcpy(str, (const char*)value);
  17935. for(int i = 0; str[i]; i++){
  17936. str[i] = tolower(str[i]);
  17937. }
  17938. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17939. isSuccess = ConfigurationStatus_Accepted;
  17940. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  17941. }
  17942. else
  17943. {
  17944. isSuccess = ConfigurationStatus_Rejected;
  17945. }
  17946. }
  17947. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  17948. {
  17949. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  17950. {
  17951. strcpy(str, (const char*)value);
  17952. for(int i = 0; str[i]; i++)
  17953. {
  17954. str[i] = tolower(str[i]);
  17955. }
  17956. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  17957. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17958. isSuccess = ConfigurationStatus_Accepted;
  17959. }
  17960. else
  17961. {
  17962. isSuccess = ConfigurationStatus_Rejected;
  17963. }
  17964. }
  17965. if(strcmp(key, "BlinkRepeat") == 0)
  17966. {
  17967. //Charger.BlinkRepeat = Integer.parseInt(value);
  17968. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  17969. {
  17970. check_ascii = value[0];
  17971. if( (check_ascii < 48) || (check_ascii > 57) )
  17972. {
  17973. isSuccess = ConfigurationStatus_Rejected;
  17974. }
  17975. else
  17976. {
  17977. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  17978. isSuccess = ConfigurationStatus_Accepted;
  17979. }
  17980. }
  17981. else
  17982. {
  17983. isSuccess = ConfigurationStatus_Rejected;
  17984. }
  17985. }
  17986. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  17987. {
  17988. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  17989. {
  17990. check_ascii = value[0];
  17991. if( (check_ascii < 48) || (check_ascii > 57) )
  17992. {
  17993. isSuccess = ConfigurationStatus_Rejected;
  17994. }
  17995. else
  17996. {
  17997. if((atoi(value) == 0) || (atoi(value) >= 5))
  17998. {
  17999. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  18000. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  18001. isSuccess = ConfigurationStatus_Accepted;
  18002. }
  18003. else
  18004. isSuccess = ConfigurationStatus_Rejected;
  18005. }
  18006. }
  18007. else
  18008. {
  18009. isSuccess = ConfigurationStatus_Rejected;
  18010. }
  18011. }
  18012. if(strcmp(key, "ConnectionTimeOut") == 0 )
  18013. {
  18014. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  18015. {
  18016. check_ascii = value[0];
  18017. if( (check_ascii < 48) || (check_ascii > 57) )
  18018. {
  18019. isSuccess = ConfigurationStatus_Rejected;
  18020. }
  18021. else
  18022. {
  18023. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  18024. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  18025. isSuccess = ConfigurationStatus_Accepted;
  18026. }
  18027. }
  18028. else
  18029. {
  18030. isSuccess = ConfigurationStatus_Rejected;
  18031. }
  18032. }
  18033. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  18034. {
  18035. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  18036. {
  18037. check_ascii = value[0];
  18038. if( (check_ascii < 48) || (check_ascii > 57) )
  18039. {
  18040. isSuccess = ConfigurationStatus_Rejected;
  18041. }
  18042. else
  18043. {
  18044. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18045. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  18046. isSuccess = ConfigurationStatus_Accepted;
  18047. }
  18048. }
  18049. else
  18050. {
  18051. isSuccess = ConfigurationStatus_Rejected;
  18052. }
  18053. }
  18054. if(strcmp(key, "HeartbeatInterval") == 0)
  18055. {
  18056. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  18057. {
  18058. check_ascii = value[0];
  18059. if( (check_ascii < 48) || (check_ascii > 57) )
  18060. {
  18061. isSuccess = ConfigurationStatus_Rejected;
  18062. }
  18063. else
  18064. {
  18065. if((atoi(value) == 0) || (atoi(value) >= 10))
  18066. {
  18067. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18068. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  18069. HeartBeatWaitTime = atoi(value);
  18070. isSuccess = ConfigurationStatus_Accepted;
  18071. }
  18072. else
  18073. {
  18074. isSuccess = ConfigurationStatus_Rejected;
  18075. }
  18076. }
  18077. }
  18078. else
  18079. {
  18080. isSuccess = ConfigurationStatus_Rejected;
  18081. }
  18082. }
  18083. if(strcmp(key, "LightIntensity") == 0)
  18084. {
  18085. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  18086. {
  18087. check_ascii = value[0];
  18088. if( (check_ascii < 48) || (check_ascii > 57) )
  18089. {
  18090. isSuccess = ConfigurationStatus_Rejected;
  18091. }
  18092. else
  18093. {
  18094. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  18095. isSuccess = ConfigurationStatus_Accepted;
  18096. }
  18097. }
  18098. else
  18099. {
  18100. isSuccess = ConfigurationStatus_Rejected;
  18101. }
  18102. }
  18103. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  18104. {
  18105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  18106. {
  18107. strcpy(str, (const char*)value);
  18108. for(int i = 0; str[i]; i++)
  18109. {
  18110. str[i] = tolower(str[i]);
  18111. }
  18112. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18113. isSuccess = ConfigurationStatus_Accepted;
  18114. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  18115. }
  18116. else
  18117. {
  18118. isSuccess = ConfigurationStatus_Rejected;
  18119. }
  18120. }
  18121. if(strcmp(key, "LocalPreAuthorize") == 0)
  18122. {
  18123. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  18124. {
  18125. strcpy(str, (const char*)value);
  18126. for(int i = 0; str[i]; i++)
  18127. {
  18128. str[i] = tolower(str[i]);
  18129. }
  18130. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18131. isSuccess = ConfigurationStatus_Accepted;
  18132. }
  18133. else
  18134. {
  18135. isSuccess = ConfigurationStatus_Rejected;
  18136. }
  18137. }
  18138. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  18139. {
  18140. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  18141. {
  18142. check_ascii = value[0];
  18143. if( (check_ascii < 48) || (check_ascii > 57) )
  18144. {
  18145. isSuccess = ConfigurationStatus_Rejected;
  18146. }
  18147. else
  18148. {
  18149. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  18150. isSuccess = ConfigurationStatus_Accepted;
  18151. }
  18152. }
  18153. else
  18154. {
  18155. isSuccess = ConfigurationStatus_Rejected;
  18156. }
  18157. }
  18158. if(strcmp(key, "MeterValuesAlignedData") == 0)
  18159. {
  18160. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  18161. {
  18162. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  18163. isSuccess = ConfigurationStatus_Accepted;
  18164. }
  18165. else
  18166. {
  18167. isSuccess = ConfigurationStatus_Rejected;
  18168. }
  18169. }
  18170. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  18171. {
  18172. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  18173. {
  18174. check_ascii = value[0];
  18175. if( (check_ascii < 48) || (check_ascii > 57) )
  18176. {
  18177. isSuccess = ConfigurationStatus_Rejected;
  18178. }
  18179. else
  18180. {
  18181. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18182. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  18183. isSuccess = ConfigurationStatus_Accepted;
  18184. }
  18185. }
  18186. else
  18187. {
  18188. isSuccess = ConfigurationStatus_Rejected;
  18189. }
  18190. }
  18191. if(strcmp(key, "MeterValuesSampledData") == 0 )
  18192. {
  18193. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  18194. {
  18195. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  18196. isSuccess = ConfigurationStatus_Accepted;
  18197. }
  18198. else
  18199. {
  18200. isSuccess = ConfigurationStatus_Rejected;
  18201. }
  18202. }
  18203. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  18204. {
  18205. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  18206. {
  18207. check_ascii = value[0];
  18208. if( (check_ascii < 48) || (check_ascii > 57) )
  18209. {
  18210. isSuccess = ConfigurationStatus_Rejected;
  18211. }
  18212. else
  18213. {
  18214. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18215. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  18216. isSuccess = ConfigurationStatus_Accepted;
  18217. }
  18218. }
  18219. else
  18220. {
  18221. isSuccess = ConfigurationStatus_Rejected;
  18222. }
  18223. }
  18224. if(strcmp(key, "MeterValueSampleInterval") == 0)
  18225. {
  18226. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  18227. {
  18228. check_ascii = value[0];
  18229. if( (check_ascii < 48) || (check_ascii > 57) )
  18230. {
  18231. isSuccess = ConfigurationStatus_Rejected;
  18232. }
  18233. else
  18234. {
  18235. if((atoi(value) == 0) || (atoi(value) >= 3))
  18236. {
  18237. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  18239. isSuccess = ConfigurationStatus_Accepted;
  18240. }
  18241. else
  18242. {
  18243. isSuccess = ConfigurationStatus_Rejected;
  18244. }
  18245. }
  18246. }
  18247. else
  18248. {
  18249. isSuccess = ConfigurationStatus_Rejected;
  18250. }
  18251. }
  18252. if(strcmp(key, "MinimumStatusDuration") == 0)
  18253. {
  18254. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  18255. {
  18256. check_ascii = value[0];
  18257. if( (check_ascii < 48) || (check_ascii > 57) )
  18258. {
  18259. isSuccess = ConfigurationStatus_Rejected;
  18260. }
  18261. else
  18262. {
  18263. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  18264. {
  18265. isSuccess = ConfigurationStatus_Rejected;
  18266. }
  18267. else
  18268. {
  18269. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  18270. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  18271. server_cycle_Status = atoi(value); //StatusNotification Cycle
  18272. isSuccess = ConfigurationStatus_Accepted;
  18273. }
  18274. }
  18275. }
  18276. else
  18277. {
  18278. isSuccess = ConfigurationStatus_Rejected;
  18279. }
  18280. }
  18281. if(strcmp(key, "NumberOfConnectors") == 0)
  18282. {
  18283. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  18284. {
  18285. check_ascii = value[0];
  18286. if( (check_ascii < 48) || (check_ascii > 57) )
  18287. {
  18288. isSuccess = ConfigurationStatus_Rejected;
  18289. }
  18290. else
  18291. {
  18292. //Charger.ResetRetries = Integer.parseInt(value);
  18293. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  18294. isSuccess = ConfigurationStatus_Accepted;
  18295. }
  18296. }
  18297. else
  18298. {
  18299. isSuccess = ConfigurationStatus_Rejected;
  18300. }
  18301. }
  18302. if(strcmp(key, "ResetRetries") == 0)
  18303. {
  18304. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  18305. {
  18306. check_ascii = value[0];
  18307. if( (check_ascii < 48) || (check_ascii > 57) )
  18308. {
  18309. isSuccess = ConfigurationStatus_Rejected;
  18310. }
  18311. else
  18312. {
  18313. //Charger.ResetRetries = Integer.parseInt(value);
  18314. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  18315. isSuccess = ConfigurationStatus_Accepted;
  18316. }
  18317. }
  18318. else
  18319. {
  18320. isSuccess = ConfigurationStatus_Rejected;
  18321. }
  18322. }
  18323. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  18324. {
  18325. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  18326. {
  18327. strcpy(str, (const char*)value);
  18328. for(int i = 0; str[i]; i++)
  18329. {
  18330. str[i] = tolower(str[i]);
  18331. }
  18332. if(strcmp(str, "notapplicable")== 0)
  18333. {
  18334. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  18335. isSuccess = ConfigurationStatus_Accepted;
  18336. }
  18337. else if(strcmp(str, "unknown")== 0)
  18338. {
  18339. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  18340. isSuccess = ConfigurationStatus_Accepted;
  18341. }
  18342. else if(strcmp(str, "rst")== 0)
  18343. {
  18344. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  18345. isSuccess = ConfigurationStatus_Accepted;
  18346. }
  18347. else if(strcmp(str, "rts")== 0)
  18348. {
  18349. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  18350. isSuccess = ConfigurationStatus_Accepted;
  18351. }
  18352. else if(strcmp(str, "srt")== 0)
  18353. {
  18354. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  18355. isSuccess = ConfigurationStatus_Accepted;
  18356. }
  18357. else if(strcmp(str, "str")== 0)
  18358. {
  18359. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  18360. isSuccess = ConfigurationStatus_Accepted;
  18361. }
  18362. else if(strcmp(str, "trs")== 0)
  18363. {
  18364. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  18365. isSuccess = ConfigurationStatus_Accepted;
  18366. }
  18367. else if(strcmp(str, "tsr")== 0)
  18368. {
  18369. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  18370. isSuccess = ConfigurationStatus_Accepted;
  18371. }
  18372. else
  18373. {
  18374. isSuccess = ConfigurationStatus_Rejected;
  18375. }
  18376. }
  18377. else
  18378. {
  18379. isSuccess = ConfigurationStatus_Rejected;
  18380. }
  18381. }
  18382. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  18383. {
  18384. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  18385. {
  18386. check_ascii = value[0];
  18387. if( (check_ascii < 48) || (check_ascii > 57) )
  18388. {
  18389. isSuccess = ConfigurationStatus_Rejected;
  18390. }
  18391. else
  18392. {
  18393. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  18394. isSuccess = ConfigurationStatus_Accepted;
  18395. }
  18396. }
  18397. else
  18398. {
  18399. isSuccess = ConfigurationStatus_Rejected;
  18400. }
  18401. }
  18402. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  18403. {
  18404. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  18405. {
  18406. strcpy(str, (const char*)value);
  18407. for(int i = 0; str[i]; i++)
  18408. {
  18409. str[i] = tolower(str[i]);
  18410. }
  18411. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18412. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18413. isSuccess = ConfigurationStatus_Accepted;
  18414. }
  18415. else
  18416. {
  18417. isSuccess = ConfigurationStatus_Rejected;
  18418. }
  18419. }
  18420. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  18421. {
  18422. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  18423. {
  18424. strcpy(str, (const char*)value);
  18425. for(int i = 0; str[i]; i++)
  18426. {
  18427. str[i] = tolower(str[i]);
  18428. }
  18429. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  18430. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18431. isSuccess = ConfigurationStatus_Accepted;
  18432. }
  18433. else
  18434. {
  18435. isSuccess = ConfigurationStatus_Rejected;
  18436. }
  18437. }
  18438. if(strcmp(key, "StopTxnAlignedData") == 0)
  18439. {
  18440. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  18441. {
  18442. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  18443. isSuccess = ConfigurationStatus_Accepted;
  18444. }
  18445. else
  18446. {
  18447. isSuccess = ConfigurationStatus_Rejected;
  18448. }
  18449. }
  18450. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  18451. {
  18452. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  18453. {
  18454. check_ascii = value[0];
  18455. if( (check_ascii < 48) || (check_ascii > 57) )
  18456. {
  18457. isSuccess = ConfigurationStatus_Rejected;
  18458. }
  18459. else
  18460. {
  18461. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  18462. isSuccess = ConfigurationStatus_Accepted;
  18463. }
  18464. }
  18465. else
  18466. {
  18467. isSuccess = ConfigurationStatus_Rejected;
  18468. }
  18469. }
  18470. if(strcmp(key, "StopTxnSampledData") == 0)
  18471. {
  18472. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  18473. {
  18474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  18475. isSuccess = ConfigurationStatus_Accepted;
  18476. }
  18477. else
  18478. {
  18479. isSuccess = ConfigurationStatus_Rejected;
  18480. }
  18481. }
  18482. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  18483. {
  18484. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  18485. {
  18486. check_ascii = value[0];
  18487. if( (check_ascii < 48) || (check_ascii > 57) )
  18488. {
  18489. isSuccess = ConfigurationStatus_Rejected;
  18490. }
  18491. else
  18492. {
  18493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  18494. isSuccess = ConfigurationStatus_Accepted;
  18495. }
  18496. }
  18497. else
  18498. {
  18499. isSuccess = ConfigurationStatus_Rejected;
  18500. }
  18501. }
  18502. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  18503. {
  18504. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  18505. {
  18506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  18507. isSuccess = ConfigurationStatus_Accepted;
  18508. }
  18509. else
  18510. {
  18511. isSuccess = ConfigurationStatus_Rejected;
  18512. }
  18513. }
  18514. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  18515. {
  18516. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  18517. {
  18518. check_ascii = value[0];
  18519. if( (check_ascii < 48) || (check_ascii > 57) )
  18520. {
  18521. isSuccess = ConfigurationStatus_Rejected;
  18522. }
  18523. else
  18524. {
  18525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  18526. isSuccess = ConfigurationStatus_Accepted;
  18527. }
  18528. }
  18529. else
  18530. {
  18531. isSuccess = ConfigurationStatus_Rejected;
  18532. }
  18533. }
  18534. if(strcmp(key, "TransactionMessageAttempts") == 0)
  18535. {
  18536. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  18537. {
  18538. check_ascii = value[0];
  18539. if( (check_ascii < 48) || (check_ascii > 57) )
  18540. {
  18541. isSuccess = ConfigurationStatus_Rejected;
  18542. }
  18543. else
  18544. {
  18545. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  18546. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  18547. TransactionMessageAttemptsValue = atoi(value);
  18548. isSuccess = ConfigurationStatus_Accepted;
  18549. }
  18550. }
  18551. else
  18552. {
  18553. isSuccess = ConfigurationStatus_Rejected;
  18554. }
  18555. }
  18556. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  18557. {
  18558. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  18559. {
  18560. check_ascii = value[0];
  18561. if( (check_ascii < 48) || (check_ascii > 57) )
  18562. {
  18563. isSuccess = ConfigurationStatus_Rejected;
  18564. }
  18565. else
  18566. {
  18567. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  18568. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  18569. TransactionMessageRetryIntervalValue = atoi(value);
  18570. isSuccess = ConfigurationStatus_Accepted;
  18571. }
  18572. }
  18573. else
  18574. {
  18575. isSuccess = ConfigurationStatus_Rejected;
  18576. }
  18577. }
  18578. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  18579. {
  18580. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  18581. {
  18582. strcpy(str, (const char*)value);
  18583. for(int i = 0; str[i]; i++)
  18584. {
  18585. str[i] = tolower(str[i]);
  18586. }
  18587. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18588. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18589. isSuccess = ConfigurationStatus_Accepted;
  18590. }
  18591. else
  18592. {
  18593. isSuccess = ConfigurationStatus_Rejected;
  18594. }
  18595. }
  18596. if(strcmp(key, "WebSocketPingInterval") == 0)
  18597. {
  18598. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  18599. {
  18600. check_ascii = value[0];
  18601. if( (check_ascii < 48) || (check_ascii > 57) )
  18602. {
  18603. isSuccess = ConfigurationStatus_Rejected;
  18604. }
  18605. else
  18606. {
  18607. if((atoi(value) == 0) || (atoi(value) >= 10))
  18608. {
  18609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  18610. isSuccess = ConfigurationStatus_Accepted;
  18611. }
  18612. else
  18613. isSuccess = ConfigurationStatus_Rejected;
  18614. }
  18615. }
  18616. else
  18617. {
  18618. isSuccess = ConfigurationStatus_Rejected;
  18619. }
  18620. }
  18621. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  18622. {
  18623. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  18624. {
  18625. strcpy(str, (const char*)value);
  18626. for(int i = 0; str[i]; i++)
  18627. {
  18628. str[i] = tolower(str[i]);
  18629. }
  18630. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18631. isSuccess = ConfigurationStatus_Accepted;
  18632. }
  18633. else
  18634. {
  18635. isSuccess = ConfigurationStatus_Rejected;
  18636. }
  18637. }
  18638. if(strcmp(key, "AuthorizationKey") == 0)
  18639. {
  18640. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  18641. {
  18642. strcpy(str, (const char*)value);
  18643. int strlength = strlen(str);
  18644. char capture[3];
  18645. char stackItem = 0;
  18646. char password[21] = {0};
  18647. printf("String length: %d\n", strlength);
  18648. for(int idx=0; idx<(strlength/2); idx++)
  18649. {
  18650. capture[0] = str[(idx*2)];
  18651. capture[1] = str[(idx*2)+1];
  18652. capture[2] = 0;
  18653. stackItem = (char)strtol(capture, NULL, 16); // number base 16
  18654. sprintf(password,"%s%c", password, stackItem);
  18655. }
  18656. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", password);
  18657. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18658. isSuccess = ConfigurationStatus_Accepted;
  18659. }
  18660. else
  18661. {
  18662. isSuccess = ConfigurationStatus_Rejected;
  18663. }
  18664. }
  18665. if(strcmp(key, "SecurityProfile") == 0)
  18666. {
  18667. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  18668. {
  18669. check_ascii = value[0];
  18670. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  18671. {
  18672. isSuccess = ConfigurationStatus_Rejected;
  18673. }
  18674. else if(check_ascii == 0x33)
  18675. {
  18676. isSuccess = NotSupported;
  18677. }
  18678. else
  18679. {
  18680. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  18681. {
  18682. if(((check_ascii - 0x30) == 1) ||
  18683. ((check_ascii - 0x30) == 2) ||
  18684. (((check_ascii - 0x30) == 3) && (access(CERTIFICATE_CP,F_OK) != -1)))
  18685. {
  18686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  18687. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  18688. isSuccess = ConfigurationStatus_Accepted;
  18689. }
  18690. else
  18691. isSuccess = ConfigurationStatus_Rejected;
  18692. }
  18693. else
  18694. isSuccess = ConfigurationStatus_Rejected;
  18695. }
  18696. }
  18697. else
  18698. {
  18699. isSuccess = ConfigurationStatus_Rejected;
  18700. }
  18701. }
  18702. if(strcmp(key, "DefaultPrice") == 0)
  18703. {
  18704. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  18705. {
  18706. strcpy(str, (const char*)value);
  18707. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  18708. isSuccess = ConfigurationStatus_Accepted;
  18709. }
  18710. else
  18711. {
  18712. isSuccess = ConfigurationStatus_Rejected;
  18713. }
  18714. }
  18715. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  18716. {
  18717. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  18718. {
  18719. strcpy(str, (const char*)value);
  18720. for(int i = 0; str[i]; i++)
  18721. {
  18722. str[i] = tolower(str[i]);
  18723. }
  18724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18725. isSuccess = ConfigurationStatus_Accepted;
  18726. }
  18727. else
  18728. {
  18729. isSuccess = ConfigurationStatus_Rejected;
  18730. }
  18731. }
  18732. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  18733. {
  18734. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  18735. {
  18736. strcpy(str, (const char*)value);
  18737. for(int i = 0; str[i]; i++)
  18738. {
  18739. str[i] = tolower(str[i]);
  18740. }
  18741. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18742. isSuccess = ConfigurationStatus_Accepted;
  18743. }
  18744. else
  18745. {
  18746. isSuccess = ConfigurationStatus_Rejected;
  18747. }
  18748. }
  18749. if(strcmp(key, "TimeOffset") == 0)
  18750. {
  18751. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  18752. {
  18753. strcpy(str, (const char*)value);
  18754. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  18755. isSuccess = ConfigurationStatus_Accepted;
  18756. }
  18757. else
  18758. {
  18759. isSuccess = ConfigurationStatus_Rejected;
  18760. }
  18761. }
  18762. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  18763. {
  18764. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  18765. {
  18766. strcpy(str, (const char*)value);
  18767. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  18768. isSuccess = ConfigurationStatus_Accepted;
  18769. }
  18770. else
  18771. {
  18772. isSuccess = ConfigurationStatus_Rejected;
  18773. }
  18774. }
  18775. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  18776. {
  18777. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  18778. {
  18779. strcpy(str, (const char*)value);
  18780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  18781. isSuccess = ConfigurationStatus_Accepted;
  18782. }
  18783. else
  18784. {
  18785. isSuccess = ConfigurationStatus_Rejected;
  18786. }
  18787. }
  18788. if(strcmp(key, "SystemUptimeSec") == 0)
  18789. {
  18790. isSuccess = NotSupported;
  18791. }
  18792. if(strcmp(key, "FreeVend") == 0)
  18793. {
  18794. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  18795. {
  18796. strcpy(str, (const char*)value);
  18797. for(int i = 0; str[i]; i++)
  18798. {
  18799. str[i] = tolower(str[i]);
  18800. }
  18801. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  18802. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18803. isSuccess = ConfigurationStatus_Accepted;
  18804. }
  18805. else
  18806. {
  18807. isSuccess = ConfigurationStatus_Rejected;
  18808. }
  18809. }
  18810. if(strcmp(key, "FreeVendIdtag") == 0)
  18811. {
  18812. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  18813. {
  18814. strcpy(str, (const char*)value);
  18815. if(strlen(str) <= 20)
  18816. {
  18817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  18818. isSuccess = ConfigurationStatus_Accepted;
  18819. }
  18820. else
  18821. {
  18822. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  18823. isSuccess = ConfigurationStatus_Rejected;
  18824. }
  18825. }
  18826. else
  18827. {
  18828. isSuccess = ConfigurationStatus_Rejected;
  18829. }
  18830. }
  18831. if(strcmp(key, "OcppServer") == 0)
  18832. {
  18833. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  18834. {
  18835. strcpy(str, (const char*)value);
  18836. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  18837. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  18838. isSuccess = ConfigurationStatus_Accepted;
  18839. }
  18840. else
  18841. {
  18842. isSuccess = ConfigurationStatus_Rejected;
  18843. }
  18844. }
  18845. if(strcmp(key, "MaintainServer") == 0)
  18846. {
  18847. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  18848. {
  18849. strcpy(str, (const char*)value);
  18850. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  18851. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  18852. isSuccess = ConfigurationStatus_Accepted;
  18853. }
  18854. else
  18855. {
  18856. isSuccess = ConfigurationStatus_Rejected;
  18857. }
  18858. }
  18859. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  18860. {
  18861. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  18862. {
  18863. strcpy(str, (const char*)value);
  18864. for(int i = 0; str[i]; i++)
  18865. {
  18866. str[i] = tolower(str[i]);
  18867. }
  18868. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  18869. isSuccess = ConfigurationStatus_Accepted;
  18870. }
  18871. else
  18872. {
  18873. isSuccess = ConfigurationStatus_Rejected;
  18874. }
  18875. }
  18876. if(strcmp(key, "StatusNotificationInterval") == 0)
  18877. {
  18878. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  18879. {
  18880. check_ascii = value[0];
  18881. if( (check_ascii < 48) || (check_ascii > 57) )
  18882. {
  18883. isSuccess = ConfigurationStatus_Rejected;
  18884. }
  18885. else
  18886. {
  18887. if((atoi(value) == 0) || (atoi(value) >= 10))
  18888. {
  18889. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  18890. isSuccess = ConfigurationStatus_Accepted;
  18891. }
  18892. else
  18893. isSuccess = ConfigurationStatus_Rejected;
  18894. }
  18895. }
  18896. else
  18897. {
  18898. isSuccess = ConfigurationStatus_Rejected;
  18899. }
  18900. }
  18901. if(strcmp(key, "PreAuthAmount") == 0)
  18902. {
  18903. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  18904. {
  18905. check_ascii = value[0];
  18906. if( (check_ascii < 48) || (check_ascii > 57) )
  18907. {
  18908. isSuccess = ConfigurationStatus_Rejected;
  18909. }
  18910. else
  18911. {
  18912. if(atof(value) >= 0)
  18913. {
  18914. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  18915. isSuccess = ConfigurationStatus_Accepted;
  18916. }
  18917. else
  18918. isSuccess = ConfigurationStatus_Rejected;
  18919. }
  18920. }
  18921. else
  18922. {
  18923. isSuccess = ConfigurationStatus_Rejected;
  18924. }
  18925. }
  18926. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  18927. {
  18928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  18929. {
  18930. check_ascii = value[0];
  18931. if( (check_ascii < 48) || (check_ascii > 57) )
  18932. {
  18933. isSuccess = ConfigurationStatus_Rejected;
  18934. }
  18935. else
  18936. {
  18937. if(atoi(value) >= 0)
  18938. {
  18939. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  18940. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  18941. isSuccess = ConfigurationStatus_Accepted;
  18942. }
  18943. else
  18944. isSuccess = ConfigurationStatus_Rejected;
  18945. }
  18946. }
  18947. else
  18948. {
  18949. isSuccess = ConfigurationStatus_Rejected;
  18950. }
  18951. }
  18952. if(strcmp(key, "PowerSharingServerIP") == 0)
  18953. {
  18954. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  18955. {
  18956. strcpy(str, (const char*)value);
  18957. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  18958. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  18959. isSuccess = ConfigurationStatus_Accepted;
  18960. }
  18961. else
  18962. {
  18963. isSuccess = ConfigurationStatus_Rejected;
  18964. }
  18965. }
  18966. if(strcmp(key, "EVCCID_PREFIX") == 0)
  18967. {
  18968. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  18969. {
  18970. strcpy(str, (const char*)value);
  18971. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  18972. isSuccess = ConfigurationStatus_Accepted;
  18973. }
  18974. else
  18975. {
  18976. isSuccess = ConfigurationStatus_Rejected;
  18977. }
  18978. }
  18979. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  18980. {
  18981. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  18982. {
  18983. if(atoi(value) > modelnameInfo.ratedPower)
  18984. {
  18985. isSuccess = ConfigurationStatus_Rejected;
  18986. }
  18987. else{
  18988. strcpy(str, (const char*)value);
  18989. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  18990. isSuccess = ConfigurationStatus_Accepted;
  18991. }
  18992. }
  18993. else
  18994. {
  18995. isSuccess = ConfigurationStatus_Rejected;
  18996. }
  18997. }
  18998. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  18999. {
  19000. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  19001. {
  19002. if((atoi(value) != 0) && (atoi(value) < 5))
  19003. {
  19004. isSuccess = ConfigurationStatus_Rejected;
  19005. }
  19006. else{
  19007. strcpy(str, (const char*)value);
  19008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  19009. isSuccess = ConfigurationStatus_Accepted;
  19010. }
  19011. }
  19012. else
  19013. {
  19014. isSuccess = ConfigurationStatus_Rejected;
  19015. }
  19016. }
  19017. if(strcmp(key, "CpoName") == 0)
  19018. {
  19019. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  19020. {
  19021. strcpy(str, (const char*)value);
  19022. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", str );
  19023. isSuccess = ConfigurationStatus_Accepted;
  19024. }
  19025. else
  19026. {
  19027. isSuccess = ConfigurationStatus_Rejected;
  19028. }
  19029. }
  19030. if(strcmp(key, "OcppSoftwareVersion") == 0)
  19031. {
  19032. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  19033. {
  19034. strcpy(str, (const char*)value);
  19035. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", str );
  19036. isSuccess = ConfigurationStatus_Accepted;
  19037. }
  19038. else
  19039. {
  19040. isSuccess = ConfigurationStatus_Rejected;
  19041. }
  19042. }
  19043. if(strcmp(key, "AuthDownloadlinkCertificate") == 0)
  19044. {
  19045. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility == 1)
  19046. {
  19047. strcpy(str, (const char*)value);
  19048. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "%s", str );
  19049. isSuccess = ConfigurationStatus_Accepted;
  19050. }
  19051. else
  19052. {
  19053. isSuccess = ConfigurationStatus_Rejected;
  19054. }
  19055. }
  19056. #if 0
  19057. //For OCPP Test Case
  19058. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  19059. {
  19060. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19061. {
  19062. strcpy(str, (const char*)value);
  19063. for(int i = 0; str[i]; i++)
  19064. {
  19065. str[i] = tolower(str[i]);
  19066. }
  19067. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19068. isSuccess = ConfigurationStatus_Accepted;
  19069. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19070. }
  19071. else
  19072. {
  19073. isSuccess = ConfigurationStatus_Rejected;
  19074. }
  19075. }
  19076. #endif
  19077. #if 1
  19078. if(strcmp(key, "LocalAuthListEnabled") == 0)
  19079. {
  19080. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19081. {
  19082. strcpy(str, (const char*)value);
  19083. for(int i = 0; str[i]; i++)
  19084. {
  19085. str[i] = tolower(str[i]);
  19086. }
  19087. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19088. isSuccess = ConfigurationStatus_Accepted;
  19089. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19090. }
  19091. else
  19092. {
  19093. isSuccess = ConfigurationStatus_Rejected;
  19094. }
  19095. }
  19096. #endif
  19097. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  19098. {
  19099. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  19100. {
  19101. check_ascii = value[0];
  19102. if( (check_ascii < 48) || (check_ascii > 57) )
  19103. {
  19104. isSuccess = ConfigurationStatus_Rejected;
  19105. }
  19106. else
  19107. {
  19108. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  19109. isSuccess = ConfigurationStatus_Accepted;
  19110. }
  19111. }
  19112. else
  19113. {
  19114. isSuccess = ConfigurationStatus_Rejected;
  19115. }
  19116. }
  19117. if(strcmp(key, "SendLocalListMaxLength") == 0)
  19118. {
  19119. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  19120. {
  19121. check_ascii = value[0];
  19122. if( (check_ascii < 48) || (check_ascii > 57) )
  19123. {
  19124. isSuccess = ConfigurationStatus_Rejected;
  19125. }
  19126. else
  19127. {
  19128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  19129. isSuccess = ConfigurationStatus_Accepted;
  19130. }
  19131. }
  19132. else
  19133. {
  19134. isSuccess = ConfigurationStatus_Rejected;
  19135. }
  19136. }
  19137. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  19138. {
  19139. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  19140. {
  19141. strcpy(str, (const char*)value);
  19142. for(int i = 0; str[i]; i++)
  19143. {
  19144. str[i] = tolower(str[i]);
  19145. }
  19146. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19147. isSuccess = ConfigurationStatus_Accepted;
  19148. }
  19149. else
  19150. {
  19151. isSuccess = ConfigurationStatus_Rejected;
  19152. }
  19153. }
  19154. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  19155. {
  19156. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  19157. {
  19158. check_ascii = value[0];
  19159. if( (check_ascii < 48) || (check_ascii > 57) )
  19160. {
  19161. isSuccess = ConfigurationStatus_Rejected;
  19162. }
  19163. else
  19164. {
  19165. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  19166. isSuccess = ConfigurationStatus_Accepted;
  19167. }
  19168. }
  19169. else
  19170. {
  19171. isSuccess = ConfigurationStatus_Rejected;
  19172. }
  19173. }
  19174. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  19175. {
  19176. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  19177. {
  19178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  19179. isSuccess = ConfigurationStatus_Accepted;
  19180. }
  19181. else
  19182. {
  19183. isSuccess = ConfigurationStatus_Rejected;
  19184. }
  19185. }
  19186. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  19187. {
  19188. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  19189. {
  19190. check_ascii = value[0];
  19191. if( (check_ascii < 48) || (check_ascii > 57) )
  19192. {
  19193. isSuccess = ConfigurationStatus_Rejected;
  19194. }
  19195. else
  19196. {
  19197. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  19198. isSuccess = ConfigurationStatus_Accepted;
  19199. }
  19200. }
  19201. else
  19202. {
  19203. isSuccess = ConfigurationStatus_Rejected;
  19204. }
  19205. }
  19206. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  19207. {
  19208. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  19209. {
  19210. strcpy(str, (const char*)value);
  19211. for(int i = 0; str[i]; i++)
  19212. {
  19213. str[i] = tolower(str[i]);
  19214. }
  19215. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19216. isSuccess = ConfigurationStatus_Accepted;
  19217. }
  19218. else
  19219. {
  19220. isSuccess = ConfigurationStatus_Rejected;
  19221. }
  19222. }
  19223. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  19224. {
  19225. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  19226. {
  19227. check_ascii = value[0];
  19228. if( (check_ascii < 48) || (check_ascii > 57) )
  19229. {
  19230. isSuccess = ConfigurationStatus_Rejected;
  19231. }
  19232. else
  19233. {
  19234. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  19235. isSuccess = ConfigurationStatus_Accepted;
  19236. }
  19237. }
  19238. else
  19239. {
  19240. isSuccess = ConfigurationStatus_Rejected;
  19241. }
  19242. }
  19243. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19244. return isSuccess;
  19245. }
  19246. int TransactionMessageAttemptsGet(void)
  19247. {
  19248. return TransactionMessageAttemptsValue;
  19249. }
  19250. int FirstHeartBeatResponse(void)
  19251. {
  19252. return FirstHeartBeat;
  19253. }
  19254. int TransactionMessageRetryIntervalGet(void)
  19255. {
  19256. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19257. }
  19258. int ReadHttpStatus(int sock)
  19259. {
  19260. //char c;
  19261. char buff[1024]="",*ptr=buff+1;
  19262. int bytes_received, status;
  19263. DEBUG_INFO("Begin Response ..\n");
  19264. while((bytes_received = recv(sock, ptr, 1, 0))){
  19265. if(bytes_received==-1){
  19266. perror("ReadHttpStatus");
  19267. exit(1);
  19268. }
  19269. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  19270. ptr++;
  19271. }
  19272. *ptr=0;
  19273. ptr=buff+1;
  19274. sscanf(ptr,"%*s %d ", &status);
  19275. DEBUG_INFO("%s\n",ptr);
  19276. DEBUG_INFO("status=%d\n",status);
  19277. DEBUG_INFO("End Response ..\n");
  19278. return (bytes_received>0)?status:0;
  19279. }
  19280. //the only filed that it parsed is 'Content-Length'
  19281. int ParseHeader(int sock)
  19282. {
  19283. //char c;
  19284. char buff[1024]="",*ptr=buff+4;
  19285. int bytes_received;
  19286. DEBUG_INFO("Begin HEADER ..\n");
  19287. while((bytes_received = recv(sock, ptr, 1, 0))){
  19288. if(bytes_received==-1){
  19289. perror("Parse Header");
  19290. exit(1);
  19291. }
  19292. if(
  19293. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  19294. (ptr[-1]=='\r') && (*ptr=='\n' )
  19295. ) break;
  19296. ptr++;
  19297. }
  19298. *ptr=0;
  19299. ptr=buff+4;
  19300. //printf("%s",ptr);
  19301. if(bytes_received){
  19302. ptr=strstr(ptr,"Content-Length:");
  19303. if(ptr){
  19304. sscanf(ptr,"%*s %d",&bytes_received);
  19305. }else
  19306. bytes_received=-1; //unknown size
  19307. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  19308. }
  19309. DEBUG_INFO("End HEADER ..\n");
  19310. return bytes_received ;
  19311. }
  19312. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  19313. {
  19314. int result = TRUE;
  19315. char rmFileCmd[300]={0};
  19316. char FilePath[256]={0};
  19317. char ftpbuf[2048];
  19318. int systemresult;
  19319. sprintf(FilePath,"/mnt/%s",filename);
  19320. system("ping 8.8.8.8 &");
  19321. if((access(FilePath,F_OK))!=-1)
  19322. {
  19323. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19324. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19325. system(rmFileCmd);
  19326. }
  19327. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19328. if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
  19329. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --ca-certificate=/root/cacert.pem",filename, url);
  19330. else
  19331. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  19332. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19333. systemresult = system(ftpbuf);
  19334. if(systemresult != 0)
  19335. {
  19336. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  19337. result = FALSE;
  19338. }
  19339. system("pkill ping");
  19340. return result;
  19341. }
  19342. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  19343. {
  19344. int result = TRUE;
  19345. char rmFileCmd[300]={0};
  19346. char FilePath[256]={0};
  19347. char ftpbuf[2048];
  19348. int systemresult;
  19349. sprintf(FilePath,"/mnt/%s",filename);
  19350. system("ping 8.8.8.8 &");
  19351. if((access(FilePath,F_OK))!=-1)
  19352. {
  19353. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19354. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19355. system(rmFileCmd);
  19356. }
  19357. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19358. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  19359. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19360. systemresult = system(ftpbuf);
  19361. if(systemresult != 0)
  19362. {
  19363. DEBUG_WARN("scp error!\n");
  19364. result = FALSE;
  19365. }
  19366. system("pkill ping");
  19367. return result;
  19368. }
  19369. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  19370. {
  19371. int result = TRUE;
  19372. char rmFileCmd[300]={0};
  19373. char FilePath[256]={0};
  19374. char ftpbuf[2048];
  19375. int systemresult;
  19376. sprintf(FilePath,"/mnt/%s",filename);
  19377. system("ping 8.8.8.8 &");
  19378. if((access(FilePath,F_OK))!=-1)
  19379. {
  19380. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19381. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19382. system(rmFileCmd);
  19383. }
  19384. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19385. if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
  19386. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --ca-certificate=/root/cacert.pem",filename, url);
  19387. else
  19388. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  19389. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19390. systemresult = system(ftpbuf);
  19391. if(systemresult != 0)
  19392. {
  19393. if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
  19394. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp --ca-certificate=/root/cacert.pem",filename, url);
  19395. else
  19396. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp --no-check-certificate",filename, url);
  19397. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19398. systemresult = system(ftpbuf);
  19399. if(systemresult != 0)
  19400. {
  19401. DEBUG_WARN("FTP download fail!\n");
  19402. result = FALSE;
  19403. }
  19404. }
  19405. system("pkill ping");
  19406. return result;
  19407. }
  19408. int httpUploadFile(char *location, char *path, char *filename,char *url)
  19409. {
  19410. char rmFileCmd[100]={0};
  19411. char FilePath[100]={0};
  19412. char buf[512];
  19413. int systemresult = 0;
  19414. //DEBUG_INFO("filename=%s\n",filename);
  19415. //DEBUG_INFO("url=%s\n",url);
  19416. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  19417. if((access(FilePath,F_OK))!=-1)
  19418. {
  19419. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19420. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19421. system(rmFileCmd);
  19422. }
  19423. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  19424. if(fp == NULL)
  19425. {
  19426. DEBUG_INFO("log is NULL\n");
  19427. return FALSE;
  19428. }
  19429. else
  19430. {
  19431. fprintf(fp, "%s\n", url);
  19432. fprintf(fp, "%s\n", filename);
  19433. fclose(fp);
  19434. }
  19435. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  19436. if(phpFP == NULL)
  19437. {
  19438. DEBUG_INFO("PHP upload fail.\n");
  19439. return FALSE;
  19440. }
  19441. else
  19442. {
  19443. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19444. {
  19445. if(strstr(buf, "result") != NULL)
  19446. {
  19447. sscanf(buf, "result: %d", &systemresult);
  19448. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  19449. }
  19450. }
  19451. pclose(phpFP);
  19452. }
  19453. if(systemresult != 1)
  19454. {
  19455. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  19456. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  19457. if(phpFP == NULL)
  19458. {
  19459. DEBUG_WARN("PHP PUT upload fail.\n");
  19460. return FALSE;
  19461. }
  19462. else
  19463. {
  19464. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19465. {
  19466. if(strstr(buf, "result") != NULL)
  19467. {
  19468. sscanf(buf, "result: %d", &systemresult);
  19469. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  19470. }
  19471. }
  19472. pclose(phpFP);
  19473. }
  19474. }
  19475. if(systemresult != 1)
  19476. {
  19477. DEBUG_WARN("PHP PUT upload fail.\n");
  19478. return FALSE;
  19479. }
  19480. return TRUE;
  19481. }
  19482. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  19483. {
  19484. int result = FALSE;
  19485. char ftpbuf[200];
  19486. int systemresult;
  19487. /*
  19488. // Domaind name transfer to IP address
  19489. struct hostent* server;
  19490. char *IPbuffer;
  19491. server = gethostbyname(location);
  19492. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  19493. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19494. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  19495. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  19496. systemresult = system(ftpbuf);
  19497. if(systemresult != 0)
  19498. {
  19499. DEBUG_INFO("ftpput error!\n");
  19500. }
  19501. else
  19502. {
  19503. result = TRUE;
  19504. DEBUG_INFO("ftpput OK!\n");
  19505. }
  19506. return result;
  19507. }
  19508. int GetOcppServerURL()
  19509. {
  19510. int result = FALSE;
  19511. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  19512. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  19513. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  19514. struct yuarel url;
  19515. char urlStr[512];
  19516. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  19517. {
  19518. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  19519. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19520. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19521. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  19522. if(yuarel_parse(&url, urlStr) != -1)
  19523. {
  19524. sprintf(OcppProtocol, "%s", url.scheme);
  19525. sprintf(OcppHost, "%s", url.host);
  19526. if(url.path == NULL)
  19527. OcppTempPath[0] = '\0';
  19528. else
  19529. {
  19530. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  19531. {
  19532. sprintf(OcppTempPath, "%s/", url.path);
  19533. }
  19534. else
  19535. {
  19536. sprintf(OcppTempPath, "%s", url.path);
  19537. }
  19538. }
  19539. if(url.port == 0)
  19540. {
  19541. if(strcmp(OcppProtocol, "wss") == 0)
  19542. OcppPort = 443;
  19543. else
  19544. OcppPort = 80;
  19545. }
  19546. else
  19547. OcppPort = url.port;
  19548. result = TRUE;
  19549. }
  19550. }
  19551. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  19552. {
  19553. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  19554. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19555. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19556. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  19557. if(yuarel_parse(&url, urlStr) != -1)
  19558. {
  19559. sprintf(OcppProtocol, "%s", url.scheme);
  19560. sprintf(OcppHost, "%s", url.host);
  19561. if(url.path == NULL)
  19562. OcppTempPath[0] = '\0';
  19563. else
  19564. sprintf(OcppTempPath, "%s", url.path);
  19565. if(url.port == 0)
  19566. {
  19567. if(strcmp(OcppProtocol, "wss") == 0)
  19568. OcppPort = 443;
  19569. else
  19570. OcppPort = 80;
  19571. }
  19572. else
  19573. OcppPort = url.port;
  19574. result = TRUE;
  19575. }
  19576. }
  19577. else
  19578. {
  19579. strcpy(OcppHost,"");
  19580. }
  19581. return result;
  19582. }
  19583. int GetOcppPath()
  19584. {
  19585. int result = FALSE;
  19586. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  19587. {
  19588. if(OcppTempPath == NULL)
  19589. {
  19590. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19591. }
  19592. else
  19593. {
  19594. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19595. }
  19596. result = TRUE;
  19597. goto End;
  19598. }
  19599. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  19600. {
  19601. if(OcppTempPath == NULL)
  19602. {
  19603. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  19604. }
  19605. else
  19606. {
  19607. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  19608. }
  19609. result = TRUE;
  19610. goto End;
  19611. }
  19612. else
  19613. {
  19614. strcpy(OcppPath,"");
  19615. }
  19616. End:
  19617. return result;
  19618. }
  19619. int GetOcppPort()
  19620. {
  19621. return OcppPort;
  19622. }
  19623. int GetOcppConnStatus(void)
  19624. {
  19625. return ShmOCPP16Data->OcppConnStatus;
  19626. }
  19627. void SetOcppConnStatus(uint8_t status)
  19628. {
  19629. ShmOCPP16Data->OcppConnStatus = status;
  19630. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  19631. }
  19632. int GetHeartBeatWithNOResponse(void)
  19633. {
  19634. return HeartBeatWithNOResponse;
  19635. }
  19636. void SetHeartBeatWithNOResponse(void)
  19637. {
  19638. HeartBeatWithNOResponse = 0;
  19639. }
  19640. void GetStartTransactionIdTag(int gun_index)
  19641. {
  19642. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  19643. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  19644. }
  19645. int GetStartTransactionId(int gun_index)
  19646. {
  19647. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19648. }
  19649. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  19650. {
  19651. char ch;
  19652. FILE *fptr1;
  19653. int temptransactionId;
  19654. char str[100]={0};
  19655. temptransactionId = 0;
  19656. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  19657. {
  19658. DEBUG_INFO("IdTag is empty.\n");
  19659. return temptransactionId;
  19660. }
  19661. /*------ Read the file ----------------*/
  19662. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  19663. if (!fptr1)
  19664. {
  19665. DEBUG_INFO("QueueTransactionId file open error.\n");
  19666. //printf(" File not found or unable to open the input file!!\n");
  19667. return temptransactionId;
  19668. }
  19669. ch=fgetc(fptr1);
  19670. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  19671. rewind(fptr1);
  19672. if(ch!=EOF)
  19673. {
  19674. // printf("%c",ch);
  19675. while (fgets(str, 100, fptr1) != NULL)
  19676. {
  19677. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19678. if(str[0]=='\0')
  19679. {
  19680. break;
  19681. }
  19682. char *revbuf[8] = {0}; // Variable store string split
  19683. int num = 0;// Quantity after string split
  19684. DEBUG_INFO("Transaction queue data= %s\n", str);
  19685. splitstring(str,",",revbuf,&num); // String split
  19686. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  19687. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  19688. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  19689. DEBUG_INFO("------------------------------\n");
  19690. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  19691. {
  19692. if(isStopTransaction)
  19693. {
  19694. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  19695. {
  19696. temptransactionId = atoi(revbuf[2]);
  19697. //break;
  19698. }
  19699. }
  19700. else
  19701. {
  19702. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  19703. {
  19704. temptransactionId = atoi(revbuf[2]);
  19705. //break;
  19706. }
  19707. }
  19708. }
  19709. }
  19710. }
  19711. else
  19712. DEBUG_INFO("EOF\n");
  19713. fclose(fptr1);
  19714. /*------- End of reading ---------------*/
  19715. return temptransactionId;
  19716. }
  19717. void SetTransactionIdZero(int transactionId)
  19718. {
  19719. char ch;
  19720. FILE *fptr1, *fptr2;
  19721. int temptransactionId = 0;
  19722. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  19723. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  19724. if (!fptr1)
  19725. {
  19726. //printf(" File not found or unable to open the input file!!\n");
  19727. return ;
  19728. }
  19729. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  19730. if (!fptr2)
  19731. {
  19732. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  19733. fclose(fptr1);
  19734. return ;
  19735. }
  19736. ch=fgetc(fptr1);
  19737. rewind(fptr1);
  19738. if(ch!=EOF)
  19739. {
  19740. // copy all contents to the temporary file except the specific line
  19741. while (fgets(str, 100, fptr1) != NULL)
  19742. {
  19743. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19744. if(str[0]=='\0')
  19745. {
  19746. break;
  19747. }
  19748. char *revbuf[8] = {0};
  19749. int num = 0;
  19750. strcpy(strtemp, str);
  19751. splitstring(str,",",revbuf,&num);
  19752. if(revbuf[2][0] != '\0')
  19753. {
  19754. temptransactionId = atoi(revbuf[2]);
  19755. if(transactionId != temptransactionId)
  19756. {
  19757. fprintf(fptr2, "%s\n", strtemp);
  19758. }
  19759. }
  19760. }
  19761. }
  19762. fclose(fptr1);
  19763. fclose(fptr2);
  19764. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  19765. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  19766. /*------ Read the file ----------------*/
  19767. }
  19768. int InternetDisconnect(void)
  19769. {
  19770. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  19771. }
  19772. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  19773. void storeTempStopTransaction(int gun_index)
  19774. {
  19775. char guid[37]={0};
  19776. int tempIndex = 0;
  19777. char TempStopTransaction[256];
  19778. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19779. DEBUG_INFO("storeTempStopTransaction...\n");
  19780. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  19781. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  19782. //=========================== Stop Transaction Time ===============================================
  19783. getNowDatetime(ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  19784. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19785. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19786. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19787. {
  19788. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19789. {
  19790. tempIndex = ((gun_index==2) ? 1: 0);
  19791. }
  19792. else
  19793. {
  19794. tempIndex = gun_index;
  19795. }
  19796. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19797. {
  19798. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19799. {
  19800. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  19801. }
  19802. }// END OF CHAdeMO_QUANTITY
  19803. }
  19804. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19805. {
  19806. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19807. {
  19808. tempIndex = ((gun_index==2) ? 1: 0);
  19809. }
  19810. else
  19811. {
  19812. tempIndex = gun_index;
  19813. }
  19814. for (int index = 0; index < CCS_QUANTITY; index++)
  19815. {
  19816. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19817. {
  19818. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  19819. }
  19820. }// END OF CCS_QUANTITY
  19821. }
  19822. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19823. {
  19824. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19825. {
  19826. tempIndex = ((gun_index==2) ? 1: 0);
  19827. }
  19828. else
  19829. {
  19830. tempIndex = gun_index;
  19831. }
  19832. for (int index = 0; index < GB_QUANTITY; index++)
  19833. {
  19834. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19835. {
  19836. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  19837. }
  19838. }// END OF GB_QUANTITY
  19839. }
  19840. else if(gunType[gun_index] == GUN_TYPE_DO)
  19841. {
  19842. tempIndex = gun_index;
  19843. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19844. {
  19845. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19846. {
  19847. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  19848. }
  19849. }
  19850. }
  19851. else
  19852. {
  19853. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19854. {
  19855. tempIndex = 2;
  19856. }
  19857. else
  19858. {
  19859. tempIndex = gun_index;
  19860. }
  19861. for (int index = 0; index < AC_QUANTITY; index++)
  19862. {
  19863. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19864. {
  19865. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  19866. }
  19867. }// END OF AC_QUANTITY
  19868. }
  19869. //======================================== Message create ==============================================
  19870. json_object *StopTransaction = json_object_new_object();
  19871. json_object *transactionDatas = json_object_new_array();
  19872. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  19873. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  19874. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  19875. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  19876. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  19877. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  19878. meterValueBufferQuery(gun_index, transactionDatas);
  19879. if(json_object_array_length(transactionDatas) > 0) json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  19880. random_uuid(guid);
  19881. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  19882. ,MESSAGE_TYPE_CALL
  19883. ,guid
  19884. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  19885. json_object_put(StopTransaction);
  19886. // Check File "TempStopTransaction" Exist
  19887. if((access(TempStopTransaction,F_OK))!=-1)
  19888. {
  19889. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  19890. fclose(fopen(TempStopTransaction, "w"));
  19891. }
  19892. else
  19893. {
  19894. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  19895. FILE *log = fopen(TempStopTransaction, "w+");
  19896. if(log == NULL)
  19897. {
  19898. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  19899. return ;
  19900. }
  19901. else
  19902. {
  19903. fclose(log);
  19904. }
  19905. }
  19906. //Add TempStopTransaction | Update TempStopTransaction
  19907. // open file for writing
  19908. FILE *outfile;
  19909. outfile = fopen (TempStopTransaction, "a");
  19910. //DEBUG_INFO("data = %s\n", queuedata);
  19911. fputs(queuedata, outfile);
  19912. fputs("\n", outfile);
  19913. fclose (outfile);
  19914. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19915. OCPP_updatePeriodEnergy(gun_index);
  19916. }
  19917. void checkTempStopTransaction(int gun_index)
  19918. {
  19919. FILE *fptr1;
  19920. char ch;
  19921. char str[QUEUE_MESSAGE_LENGTH]={0};
  19922. char guid[37]={0};
  19923. char tempdata[65]={0};
  19924. char connectorStr[2]={0};
  19925. char TempStopTransaction[256];
  19926. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19927. fptr1 = fopen(TempStopTransaction, "r");
  19928. //TempStopTransaction格式: 槍號,StopTransaction封包
  19929. if (!fptr1)
  19930. {
  19931. //printf(" File not found or unable to open the input file!!\n");
  19932. return ;
  19933. }
  19934. ch=fgetc(fptr1);
  19935. //printf(" Now the content of the file %s is : \n",fname);
  19936. rewind(fptr1);
  19937. if(ch!=EOF)
  19938. {
  19939. // copy all contents to the temporary file except the specific line
  19940. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  19941. {
  19942. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19943. if(str[0]=='\0')
  19944. {
  19945. break;
  19946. }
  19947. //TempStopTransaction格式: 槍號,StopTransaction封包
  19948. strncpy(connectorStr, str, 1);
  19949. if(atoi(connectorStr) != (gun_index+1))
  19950. {
  19951. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  19952. fclose(fptr1);
  19953. return ;
  19954. }
  19955. //random_uuid(guid);
  19956. strncpy(guid, str+6, 36); //copy guid
  19957. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  19958. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  19959. {
  19960. //DEBUG_INFO("StopTransaction mapitem pass\n");
  19961. }
  19962. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  19963. OCPP_insert_transaction_msg(NO, str);
  19964. memset(str,0,ARRAY_SIZE(str));
  19965. }
  19966. }
  19967. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  19968. fclose(fptr1);
  19969. remove(TempStopTransaction); // remove the original file
  19970. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19971. }
  19972. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  19973. {
  19974. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  19975. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  19976. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  19977. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  19978. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  19979. }
  19980. void FillTransactionId(int ConnectorId, int TransactionId)
  19981. {
  19982. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  19983. ShmOCPP16Data->StartTransaction[ConnectorId-1].ResponseTransactionId = TransactionId;
  19984. }
  19985. int GetWebSocketPingInterval(void)
  19986. {
  19987. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  19988. }
  19989. int GetServerSign(void)
  19990. {
  19991. return server_sign;
  19992. }
  19993. uint8_t GetOcppSecurityProfile()
  19994. {
  19995. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  19996. }
  19997. void MergeCertificates()
  19998. {
  19999. char cmdBuf[2048]={0};
  20000. if(access(ROOTCA_CS,F_OK) != -1)
  20001. {
  20002. sprintf(cmdBuf, "cat /root/cacert.pem %s > /root/certCA.pem", ROOTCA_CS);
  20003. }
  20004. else
  20005. {
  20006. sprintf(cmdBuf, "cat /root/cacert.pem > /root/certCA.pem");
  20007. }
  20008. system(cmdBuf);
  20009. }
  20010. void GetOcppChargerBoxId(uint8_t *data)
  20011. {
  20012. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  20013. }
  20014. void GetOcppSecurityPassword(uint8_t *data)
  20015. {
  20016. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  20017. }
  20018. void SetOcppVersion(uint8_t *version)
  20019. {
  20020. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  20021. DEBUG_INFO("ocpp version: %s\n", version);
  20022. if(strstr((char*)version, "ocpp1.6") != NULL)
  20023. {
  20024. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  20025. }
  20026. else if(strstr((char*)version, "ocpp2.0") != NULL)
  20027. {
  20028. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  20029. system("pkill OcppBackend");
  20030. }
  20031. }
  20032. void SetServerSign(int value)
  20033. {
  20034. server_sign = value;
  20035. }
  20036. int GetBootNotificationInterval(void)
  20037. {
  20038. return BootNotificationInterval;
  20039. }
  20040. int GetInternetConn(void)
  20041. {
  20042. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  20043. }
  20044. int GetBackendConnectionTimeout(void)
  20045. {
  20046. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  20047. }
  20048. int isConnectorInitMode(int gun_index)
  20049. {
  20050. int tempIndex = 0;
  20051. int result = TRUE;
  20052. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  20053. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20054. {
  20055. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20056. {
  20057. tempIndex = ((gun_index==2) ? 1: 0);
  20058. }
  20059. else
  20060. {
  20061. tempIndex = gun_index;
  20062. }
  20063. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20064. {
  20065. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  20066. {
  20067. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20068. } //end of the same index
  20069. }//end of for CHAdeMO_QUANTITY
  20070. }
  20071. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20072. {
  20073. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20074. {
  20075. tempIndex = ((gun_index==2) ? 1: 0);
  20076. }
  20077. else
  20078. {
  20079. tempIndex = gun_index;
  20080. }
  20081. for (int index = 0; index < CCS_QUANTITY; index++)
  20082. {
  20083. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20084. {
  20085. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20086. } //end of the same index
  20087. } // end of for CCS_QUANTITY
  20088. }
  20089. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20090. {
  20091. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20092. {
  20093. tempIndex = ((gun_index==2) ? 1: 0);
  20094. }
  20095. else
  20096. {
  20097. tempIndex = gun_index;
  20098. }
  20099. for (int index = 0; index < GB_QUANTITY; index++)
  20100. {
  20101. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20102. {
  20103. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20104. } //end of the same index
  20105. } // end of for GB_QUANTITY
  20106. }
  20107. else if(gunType[gun_index] == GUN_TYPE_DO)
  20108. {
  20109. tempIndex = gun_index;
  20110. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20111. {
  20112. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20113. {
  20114. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20115. } //end of the same index
  20116. }
  20117. }
  20118. else
  20119. {
  20120. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20121. {
  20122. tempIndex = 2;
  20123. }
  20124. else
  20125. {
  20126. tempIndex = gun_index;
  20127. }
  20128. for (int index = 0; index < AC_QUANTITY; index++)
  20129. {
  20130. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20131. {
  20132. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20133. }//end of the same index
  20134. }//end of for AC_QUANTITY
  20135. }
  20136. return result;
  20137. }
  20138. void refreshProcDogTimer()
  20139. {
  20140. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  20141. }
  20142. void InitialSystemValue(void)
  20143. {
  20144. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  20145. locallistVersion=0;
  20146. BootNotificationInterval = 0;
  20147. authorizeRetryTimes = 0;
  20148. GunStatusInterval = 10;
  20149. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  20150. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  20151. //Heart Beat
  20152. HeartBeatWithNOResponse = 0;
  20153. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  20154. if(HeartBeatWaitTime == 0)
  20155. FirstHeartBeat = TRUE;
  20156. else
  20157. FirstHeartBeat = FALSE;
  20158. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  20159. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  20160. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  20161. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  20162. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  20163. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  20164. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  20165. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  20166. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  20167. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  20168. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  20169. //Status && ConnectorPlugIn Setting
  20170. Connector0PreviousSystemStatus = 99;
  20171. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20172. {
  20173. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  20174. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  20175. }
  20176. for (int index = 0; index < CCS_QUANTITY; index++)
  20177. {
  20178. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  20179. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  20180. }
  20181. for (int index = 0; index < GB_QUANTITY; index++)
  20182. {
  20183. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  20184. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  20185. }
  20186. for (int index = 0; index < AC_QUANTITY; index++)
  20187. {
  20188. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  20189. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  20190. }
  20191. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20192. {
  20193. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  20194. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  20195. }
  20196. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  20197. {
  20198. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  20199. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  20200. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  20201. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  20202. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  20203. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  20204. }
  20205. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  20206. refreshStartTimer(&clientTime.Heartbeat);
  20207. sleep(1);
  20208. }
  20209. void LWS_Send(char *str)
  20210. {
  20211. //=====================================================
  20212. // Check InternetConn 0: disconnected, 1: connected
  20213. //====================================================
  20214. if(GetOcppConnStatus() == 0)
  20215. {
  20216. DEBUG_INFO("offline now !!!\n");
  20217. return;
  20218. }
  20219. // Only disable isWebsocketSendable operation initiated by charger
  20220. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20221. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20222. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20223. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20224. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20225. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20226. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20227. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20228. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20229. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20230. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20231. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20232. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20233. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20234. {
  20235. isWebsocketSendable = 0;
  20236. }
  20237. pthread_mutex_lock(&lock_send);
  20238. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20239. sprintf((char *)SendBuffer, "%s", str);
  20240. SendBufLen = strlen(str);
  20241. pthread_mutex_unlock(&lock_send);
  20242. lws_callback_on_writable(wsi_client);
  20243. //lws_service(context, 0);
  20244. //sleep(1);
  20245. }
  20246. void LWS_SendNow(char *str)
  20247. {
  20248. //=====================================================
  20249. // Check InternetConn 0: disconnected, 1: connected
  20250. //====================================================
  20251. if(GetOcppConnStatus() == 0)
  20252. {
  20253. DEBUG_INFO("offline now !!!\n");
  20254. return;
  20255. }
  20256. // Only disable isWebsocketSendable operation initiated by charger
  20257. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20258. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20259. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20260. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20261. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20262. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20263. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20264. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20265. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20266. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20267. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20268. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20269. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20270. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20271. {
  20272. isWebsocketSendable = 0;
  20273. }
  20274. pthread_mutex_lock(&lock_send);
  20275. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20276. sprintf((char *)SendBuffer, "%s", str);
  20277. SendBufLen = strlen(str);
  20278. pthread_mutex_unlock(&lock_send);
  20279. lws_callback_on_writable(wsi_client);
  20280. lws_service(context, 0);
  20281. //sleep(1);
  20282. }