MessageHandler.c 1.0 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224
  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 ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  60. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  61. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  62. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  63. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  64. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  65. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  66. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  67. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  68. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  69. static int TransactionMessageAttemptsValue = 0;
  70. static int TransactionMessageRetryIntervalValue = 0;
  71. static int TempMeterValueInterval = 0;
  72. static struct OCPPAuthLocalElemet
  73. {
  74. int listVersionInt;
  75. char idTagstr[21];
  76. char parentIdTag[21];
  77. char expiryDate[36];
  78. char idTagstatus[16];
  79. }idTagQuery;
  80. //============================================
  81. // OCPP MeterValue request flag
  82. //============================================
  83. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  84. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  85. //============================================
  86. // OCPP HeartBeat Response Not Receive Counts
  87. //============================================
  88. static int HeartBeatWithNOResponse = 0;
  89. //============================================
  90. // OCPP California Pricing Requirements
  91. //============================================
  92. static char dmsVersion[21] = {0};
  93. extern sqlite3 *db;
  94. int TransactionMessageAttemptsGet(void);
  95. int TransactionMessageRetryIntervalGet(void);
  96. int GetOcppConnStatus(void);
  97. void SetOcppConnStatus(uint8_t status);
  98. int setKeyValue(char *key, char *value);
  99. void OCPP_get_TableAuthlocalAllData(void);
  100. void processUnkownKey(void);
  101. struct InterLock
  102. {
  103. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  104. unsigned char isGetDiagnosticGoing:1;
  105. unsigned char isUpdateFirmwareGoing:1;
  106. }interLock;
  107. struct ClientTime
  108. {
  109. struct timespec Heartbeat;
  110. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  111. struct timespec StartTransaction;
  112. struct timespec StopTransaction;
  113. struct timespec MeterValues[CONNECTOR_QUANTITY];
  114. struct timespec RemoteStartWait;
  115. struct timespec TcciQueryDeduct;
  116. struct timespec TcciQueryOccupancyDeduct;
  117. struct timespec CharingProfileRefresh[CONNECTOR_QUANTITY];
  118. }clientTime;
  119. typedef union
  120. {
  121. //Operations Initiated by Central System
  122. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  123. struct
  124. {
  125. //CsMsgValue[0]
  126. unsigned char StatusNotificationReq:1; //bit 0,
  127. unsigned char StatusNotificationConf:1; //bit 1,
  128. unsigned char TriggerMeterValue:1; //bit 2,
  129. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  130. unsigned char isOnCharging:1; //bit 4,
  131. unsigned char :3; //bit5~7
  132. }bits[CONNECTOR_QUANTITY];
  133. }CpinitiateMsg;
  134. CpinitiateMsg cpinitateMsg;
  135. //GetConfiguration Array
  136. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  137. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  138. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  139. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  140. static char *ChargePointErrorCodeStr[] = {
  141. MACROSTR(ConnectorLockFailure),
  142. MACROSTR(EVCommunicationError),
  143. MACROSTR(GroundFailure),
  144. MACROSTR(HighTemperature),
  145. MACROSTR(InternalError),
  146. MACROSTR(LocalListConflict),
  147. MACROSTR(NoError),
  148. MACROSTR(OtherError),
  149. MACROSTR(OverCurrentFailure),
  150. MACROSTR(OverVoltage),
  151. MACROSTR(PowerMeterFailure),
  152. MACROSTR(PowerSwitchFailure),
  153. MACROSTR(ReaderFailure),
  154. MACROSTR(ResetFailure),
  155. MACROSTR(UnderVoltage),
  156. MACROSTR(WeakSignal)
  157. };
  158. static char * ChargePointStatusStr[] = {
  159. MACROSTR(Available),
  160. MACROSTR(Preparing),
  161. MACROSTR(Charging),
  162. MACROSTR(SuspendedEVSE),
  163. MACROSTR(SuspendedEV),
  164. MACROSTR(Finishing),
  165. MACROSTR(Reserved),
  166. MACROSTR(Unavailable),
  167. MACROSTR(Faulted)
  168. };
  169. static char *RegistrationStatusStr[] = {
  170. MACROSTR(Accepted),
  171. MACROSTR(Pending),
  172. MACROSTR(Rejected)
  173. };
  174. static char *AvailabilityTypeStr[] = {
  175. MACROSTR(Inoperative),
  176. MACROSTR(Operative)
  177. };
  178. static char *AvailabilityStatusStr[] = {
  179. MACROSTR(Accepted),
  180. MACROSTR(Rejected),
  181. MACROSTR(Scheduled)
  182. };
  183. static char *ConfigurationStatusStr[] = {
  184. MACROSTR(Accepted),
  185. MACROSTR(Rejected),
  186. MACROSTR(RebootRequired),
  187. MACROSTR(NotSupported)
  188. };
  189. static char *ClearCacheStatusStr[] = {
  190. MACROSTR(Accepted),
  191. MACROSTR(Rejected)
  192. };
  193. static char *ChargingProfilePurposeTypeStr[] = {
  194. MACROSTR(ChargePointMaxProfile),
  195. MACROSTR(TxDefaultProfile),
  196. MACROSTR(TxProfile)
  197. };
  198. static char *ChargingProfileStatusStr[] = {
  199. MACROSTR(Accepted),
  200. MACROSTR(Rejected),
  201. MACROSTR(NotSupported)
  202. };
  203. static char *ClearChargingProfileStatusStr[] = {
  204. MACROSTR(Accepted),
  205. MACROSTR(Unknown)
  206. };
  207. static char *GetCompositeScheduleStatusStr[] = {
  208. MACROSTR(Accepted),
  209. MACROSTR(Rejected)
  210. };
  211. static char *UpdateTypeStr[] = {
  212. MACROSTR(Differential),
  213. MACROSTR(Full)
  214. };
  215. static char *UpdateStatusStr[] = {
  216. MACROSTR(Accepted),
  217. MACROSTR(Failed),
  218. MACROSTR(NotSupported),
  219. MACROSTR(VersionMismatch)
  220. };
  221. static char *RemoteStartStopStatusStr[] = {
  222. MACROSTR(Accepted),
  223. MACROSTR(Rejected)
  224. };
  225. static char *ReservationStatusStr[] = {
  226. MACROSTR(Accepted),
  227. MACROSTR(Faulted),
  228. MACROSTR(Occupied),
  229. MACROSTR(Rejected),
  230. MACROSTR(Unavailable)
  231. };
  232. static char *ResetTypeStr[] = {
  233. MACROSTR(Hard),
  234. MACROSTR(Soft)
  235. };
  236. static char *ResetStatusStr[] = {
  237. MACROSTR(Accepted),
  238. MACROSTR(Rejected)
  239. };
  240. static char * DiagnosticsStatusStr[] = {
  241. MACROSTR(Idle),
  242. MACROSTR(Uploaded),
  243. MACROSTR(UploadFailed),
  244. MACROSTR(Uploading)
  245. };
  246. static char * FirmwareStatusStr[] = {
  247. MACROSTR(Downloaded),
  248. MACROSTR(DownloadFailed),
  249. MACROSTR(Downloading),
  250. MACROSTR(Idle),
  251. MACROSTR(InstallationFailed),
  252. MACROSTR(Installing),
  253. MACROSTR(Installed)
  254. };
  255. static char * MessageTriggerStr[] = {
  256. MACROSTR(BootNotification),
  257. MACROSTR(DiagnosticsStatusNotification),
  258. MACROSTR(FirmwareStatusNotification),
  259. MACROSTR(Heartbeat),
  260. MACROSTR(MeterValues),
  261. MACROSTR(StatusNotification)
  262. };
  263. static char * TriggerMessageStatusStr[] = {
  264. MACROSTR(Accepted),
  265. MACROSTR(Rejected),
  266. MACROSTR(NotImplemented)
  267. };
  268. static char * UnlockStatusStr[] = {
  269. MACROSTR(Unlocked),
  270. MACROSTR(UnlockFailed),
  271. MACROSTR(NotSupported)
  272. };
  273. #if 0
  274. static char * StopTransactionReasonStr[] = {
  275. MACROSTR(EmergencyStop),
  276. MACROSTR(EVDisconnected),
  277. MACROSTR(HardReset),
  278. MACROSTR(Local),
  279. MACROSTR(Other),
  280. MACROSTR(PowerLoss),
  281. MACROSTR(Reboot),
  282. MACROSTR(Remote),
  283. MACROSTR(SoftReset),
  284. MACROSTR(UnlockCommand),
  285. MACROSTR(DeAuthorized)
  286. };
  287. #endif
  288. static char * CancelReservationStatusStr[] = {
  289. MACROSTR(Accepted),
  290. MACROSTR(Rejected)
  291. };
  292. static char * ReadingContextStr[] = {
  293. MACROSTR(Interruption.Begin),
  294. MACROSTR(Interruption.End),
  295. MACROSTR(Other),
  296. MACROSTR(Sample.Clock),
  297. MACROSTR(Sample.Periodic),
  298. MACROSTR(Transaction.Begin),
  299. MACROSTR(Transaction.End),
  300. MACROSTR(Trigger)
  301. };
  302. static char * ValueFormatStr[] = {
  303. MACROSTR(Raw),
  304. MACROSTR(SignedData)
  305. };
  306. static char * MeasurandStr[] = {
  307. MACROSTR(Current.Export),
  308. MACROSTR(Current.Import),
  309. MACROSTR(Current.Offered),
  310. MACROSTR(Energy.Active.Export.Register),
  311. MACROSTR(Energy.Active.Import.Register),
  312. MACROSTR(Energy.Reactive.Export.Register),
  313. MACROSTR(Energy.Reactive.Import.Register),
  314. MACROSTR(Energy.Active.Export.Interval),
  315. MACROSTR(Energy.Active.Import.Interval),
  316. MACROSTR(Energy.Reactive.Export.Interval),
  317. MACROSTR(Energy.Reactive.Import.Interval),
  318. MACROSTR(Frequency),
  319. MACROSTR(Power.Active.Export),
  320. MACROSTR(Power.Active.Import),
  321. MACROSTR(Power.Factor),
  322. MACROSTR(Power.Offered),
  323. MACROSTR(Power.Reactive.ExportMACROSTR),
  324. MACROSTR(Power.Reactive.Import),
  325. MACROSTR(RPM),
  326. MACROSTR(SoC),
  327. MACROSTR(Temperature),
  328. MACROSTR(Voltage)
  329. };
  330. static char * LocationStr[] = {
  331. MACROSTR(Body),
  332. MACROSTR(Cable),
  333. MACROSTR(EV),
  334. MACROSTR(Inlet),
  335. MACROSTR(Outlet)
  336. };
  337. static char * PhaseStr[] = {
  338. MACROSTR(L1),
  339. MACROSTR(L2),
  340. MACROSTR(L3),
  341. MACROSTR(N),
  342. MACROSTR(L1-N),
  343. MACROSTR(L2-N),
  344. MACROSTR(L3-N),
  345. MACROSTR(L1-L2),
  346. MACROSTR(L2-L3),
  347. MACROSTR(L3-L1)
  348. };
  349. static char * UnitOfMeasureStr[] = {
  350. MACROSTR(Wh),
  351. MACROSTR(kWh),
  352. MACROSTR(varh),
  353. MACROSTR(kvarh),
  354. MACROSTR(W),
  355. MACROSTR(kW),
  356. MACROSTR(VA),
  357. MACROSTR(kVA),
  358. MACROSTR(var),
  359. MACROSTR(kvar),
  360. MACROSTR(A),
  361. MACROSTR(V),
  362. MACROSTR(Celsius),
  363. MACROSTR(Fahrenheit),
  364. MACROSTR(K),
  365. MACROSTR(Percent)
  366. };
  367. //=========================================
  368. // Certificate related routine
  369. //=========================================
  370. int certVerify(char *privateKey, char *cert)
  371. {
  372. int result = PASS;
  373. SSL_CTX *ctx = SSL_CTX_new(TLS_method());
  374. // Load certificate file
  375. if(SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM) <= 0)
  376. {
  377. DEBUG_ERROR("Load certificate error!\n");
  378. result = FAIL;
  379. }
  380. // Load private key file
  381. if(SSL_CTX_use_PrivateKey_file(ctx, privateKey, SSL_FILETYPE_PEM) <= 0)
  382. {
  383. DEBUG_ERROR("Load private key error!\n");
  384. result = FAIL;
  385. }
  386. if(!SSL_CTX_check_private_key(ctx))
  387. {
  388. result = FAIL;
  389. }
  390. SSL_CTX_free(ctx);
  391. return result;
  392. }
  393. //=========================================
  394. // TTIA routine
  395. //=========================================
  396. int sendTTIAInfo(uint8_t gun_index)
  397. {
  398. static int sn = 0;
  399. int result = FAIL;
  400. struct hostent *server;
  401. int udp_socket_fd;
  402. struct sockaddr_in dest_addr = {0};
  403. uint8_t tx_buf[80] = {0};
  404. uint8_t logBuf[256]= {0};
  405. uint8_t tx_len, tempIndex, socStart, socEnd;
  406. uint16_t PresentChargedEnergy;
  407. struct tm tmStart, tmEnd;
  408. DEBUG_INFO("sendTTIAInfo...\n");
  409. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  410. {
  411. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  412. {
  413. tempIndex = ((gun_index==2) ? 1: 0);
  414. }
  415. else
  416. {
  417. tempIndex = gun_index;
  418. }
  419. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  420. {
  421. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  422. {
  423. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  424. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  425. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  426. }
  427. }
  428. }
  429. else if(gunType[gun_index] == GUN_TYPE_CCS)
  430. {
  431. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  432. {
  433. tempIndex = ((gun_index==2) ? 1: 0);
  434. }
  435. else
  436. {
  437. tempIndex = gun_index;
  438. }
  439. for (int index = 0; index < CCS_QUANTITY; index++)
  440. {
  441. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  442. {
  443. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  444. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  445. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  446. }
  447. }
  448. }
  449. else if(gunType[gun_index] == GUN_TYPE_GBT)
  450. {
  451. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  452. {
  453. tempIndex = ((gun_index==2) ? 1: 0);
  454. }
  455. else
  456. {
  457. tempIndex = gun_index;
  458. }
  459. for (int index = 0; index < GB_QUANTITY; index++)
  460. {
  461. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  462. {
  463. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  464. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  465. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  466. }
  467. }
  468. }
  469. else if(gunType[gun_index] == GUN_TYPE_DO)
  470. {
  471. tempIndex = gun_index;
  472. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  473. {
  474. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  475. {
  476. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  477. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  478. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  479. }
  480. }
  481. }
  482. else
  483. {
  484. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  485. {
  486. tempIndex = 2;
  487. }
  488. else
  489. {
  490. tempIndex = gun_index;
  491. }
  492. for (int index = 0; index < AC_QUANTITY; index++)
  493. {
  494. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  495. {
  496. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  497. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  498. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  499. }
  500. }// END
  501. }
  502. // Message assembly
  503. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  504. tx_buf[4] = 0x02; // Protocol Version
  505. tx_buf[5] = 0xb0; // Message ID
  506. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  507. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  508. tx_buf[8] = 0x00; // CarID low byte
  509. tx_buf[9] = 0x00; // CarID high byte
  510. tx_buf[10] = 0x00; // ID Storage
  511. tx_buf[11] = 0x00; // Driver lowest byte
  512. tx_buf[12] = 0x00; // Driver 2nd byte
  513. tx_buf[13] = 0x00; // Driver 3rd byte
  514. tx_buf[14] = 0x00; // Driver highest byte
  515. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  516. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  517. tx_buf[17] = 0x00; // Reserve
  518. tx_buf[18] = 60 & 0xff; // Payload length low byte
  519. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  520. // EVSE provider
  521. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  522. // EVSE provider
  523. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  524. // EVSE id
  525. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  526. // Connector id
  527. tx_buf[37] = gun_index;
  528. // EVSE station
  529. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  530. // Vehicle SN
  531. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  532. // Mileage
  533. tx_buf[61] = 0x00; // lowest byte
  534. tx_buf[62] = 0x00; // 2nd byte
  535. tx_buf[63] = 0x00; // highest byte
  536. // Start date time 6 bytes
  537. 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))
  538. {
  539. struct tm *tmTarget;
  540. struct timeb tbTarget;
  541. tmStart.tm_year -= 1900;
  542. tmStart.tm_mon -= 1;
  543. tmStart.tm_gmtoff = 0;
  544. tbTarget.time = mktime(&tmStart);
  545. tbTarget.timezone = 0;
  546. tbTarget.time += (8*3600);
  547. tmTarget = gmtime(&tbTarget.time);
  548. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  549. tx_buf[65] = (tmTarget->tm_mon+1);
  550. tx_buf[66] = tmTarget->tm_mday;
  551. tx_buf[67] = tmTarget->tm_hour;
  552. tx_buf[68] = tmTarget->tm_min;
  553. tx_buf[69] = tmTarget->tm_sec;
  554. }
  555. // Stop date time 6 bytes
  556. 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))
  557. {
  558. struct tm *tmTarget;
  559. struct timeb tbTarget;
  560. tmEnd.tm_year -= 1900;
  561. tmEnd.tm_mon -= 1;
  562. tmEnd.tm_gmtoff = 0;
  563. tbTarget.time = mktime(&tmEnd);
  564. tbTarget.timezone = 0;
  565. tbTarget.time += (8*3600);
  566. tmTarget = gmtime(&tbTarget.time);
  567. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  568. tx_buf[71] = (tmTarget->tm_mon+1);
  569. tx_buf[72] = tmTarget->tm_mday;
  570. tx_buf[73] = tmTarget->tm_hour;
  571. tx_buf[74] = tmTarget->tm_min;
  572. tx_buf[75] = tmTarget->tm_sec;
  573. }
  574. // Session energy 2 bytes
  575. tx_buf[76] = PresentChargedEnergy & 0xff;
  576. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  577. // Start SOC 1 byte
  578. tx_buf[78] = socStart;
  579. // Stop SOC 1 byte
  580. tx_buf[79] = socEnd;
  581. // Open socket
  582. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  583. if(udp_socket_fd == -1)
  584. {
  585. DEBUG_ERROR("UDP socket create failed!\n");
  586. }
  587. else
  588. {
  589. // Get server DNS entry
  590. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  591. if (server == NULL)
  592. {
  593. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  594. }
  595. else
  596. {
  597. // Build the server's Internet address
  598. bzero((char *) &dest_addr, sizeof(dest_addr));
  599. dest_addr.sin_family = AF_INET;
  600. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  601. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  602. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  603. {
  604. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  605. {
  606. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  607. }
  608. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  609. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  610. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  611. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  612. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  613. DEBUG_TTIA_INFO("---------- Header ----------\n");
  614. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  615. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  616. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  617. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  618. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  619. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  620. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  621. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  622. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  623. DEBUG_TTIA_INFO("Len: 0x3C\n");
  624. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  625. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  626. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  627. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  628. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  629. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  630. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  631. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  632. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  633. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  634. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  635. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  636. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  637. DEBUG_TTIA_INFO("=========================================\n");
  638. sn++;
  639. result = PASS;
  640. }
  641. else
  642. {
  643. DEBUG_ERROR("UDP sent out fail.\n");
  644. }
  645. }
  646. }
  647. return result;
  648. }
  649. //=========================================
  650. // Save configuration
  651. //=========================================
  652. int runShellCmd(const char*cmd)
  653. {
  654. int result = FAIL;
  655. char buf[256];
  656. FILE *fp;
  657. fp = popen(cmd, "r");
  658. if(fp != NULL)
  659. {
  660. while(fgets(buf, sizeof(buf), fp) != NULL)
  661. {
  662. DEBUG_INFO("%s\n", buf);
  663. }
  664. result = PASS;
  665. }
  666. pclose(fp);
  667. return result;
  668. }
  669. int StoreUsrConfigData(struct SysConfigData *UsrData)
  670. {
  671. int result = PASS;
  672. int fd,wrd;
  673. unsigned int i,Chk;
  674. unsigned char *ptr, *BufTmp;
  675. int MtdBlockSize = 0x300000;
  676. Chk=0;
  677. ptr=(unsigned char *)UsrData;
  678. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  679. {
  680. memset(BufTmp,0,MtdBlockSize);
  681. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  682. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  683. Chk+=*(BufTmp+i);
  684. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  685. // Output configuration to file.
  686. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  687. if (fd < 0)
  688. {
  689. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  690. free(BufTmp);
  691. return 0;
  692. }
  693. wrd=write(fd, BufTmp, MtdBlockSize);
  694. close(fd);
  695. if(wrd<MtdBlockSize)
  696. {
  697. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  698. free(BufTmp);
  699. return 0;
  700. }
  701. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  702. DEBUG_INFO("Erase /dev/mtd10.\n");
  703. runShellCmd("flash_erase /dev/mtd10 0 0");
  704. DEBUG_INFO("Write /dev/mtd10.\n");
  705. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  706. DEBUG_INFO("Erase /dev/mtd11.\n");
  707. runShellCmd("flash_erase /dev/mtd11 0 0");
  708. DEBUG_INFO("Write /dev/mtd11.\n");
  709. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  710. system("rm -f /mnt/EvseConfig.bin");
  711. DEBUG_INFO("EvseConfig write to flash OK\n");
  712. }
  713. else
  714. {
  715. DEBUG_ERROR("alloc BlockSize NG\r\n");
  716. result = FAIL;
  717. }
  718. if(BufTmp!=NULL)
  719. free(BufTmp);
  720. return result;
  721. }
  722. //=========================================
  723. // Sqlite3 related function
  724. //=========================================
  725. static int selectSqlCount = 0;
  726. static int callback(void *data, int argc, char **argv, char **azColName){
  727. int i;
  728. //printf("%s: ", (const char*)data);
  729. selectSqlCount = argc;
  730. for(i = 0; i<argc; i++){
  731. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  732. }
  733. //printf("\n");
  734. return 0;
  735. }
  736. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  737. //int i;
  738. //printf("%s:\n", (const char*)data);
  739. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  740. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  741. return 0;
  742. }
  743. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  744. //printf("%s:\n", (const char*)data);
  745. //idTag
  746. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  747. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  748. //parentIdTag
  749. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  750. //expir_date
  751. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  752. //status
  753. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  754. //version
  755. if(columenCount > 5)
  756. idTagQuery.listVersionInt = atoi(columnValue[5]);
  757. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  758. return 0;
  759. }
  760. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  761. {
  762. // localversion = argv[5] ? atoi(argv[5]) : 0;
  763. // printf("localversion=%d\n", localversion);
  764. return 0;
  765. }
  766. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  767. {
  768. for (int i = 0; i < n_columns; i++)
  769. {
  770. DEBUG_INFO("%s\t", col_values[i]);
  771. }
  772. DEBUG_INFO("\n");
  773. return 0;
  774. }
  775. int OCPP_cleanLocalCache()
  776. {
  777. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  778. char *errMsg = 0;
  779. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  780. if (SQLITE_OK != rc)
  781. {
  782. DEBUG_INFO("SQL error: %s\n",errMsg);
  783. return FALSE;
  784. }
  785. return TRUE;
  786. }
  787. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  788. {
  789. int isSuccess = TRUE;
  790. int ret = 0;
  791. //const char* data = "Callback function called";
  792. char sql[300];
  793. char zErrMsg[200];
  794. memset(sql, 0, 300);
  795. memset(zErrMsg, 0, 200);
  796. 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);
  797. //* Execute SQL statement */
  798. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  799. if( ret != SQLITE_OK )
  800. {
  801. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  802. isSuccess = FALSE;
  803. }
  804. return isSuccess;
  805. }
  806. void OCPP_getIdTagFromLocalCache(char idTag[])
  807. {
  808. int rc = 0;
  809. char sql[100];
  810. char zErrMsg[100];
  811. memset(sql, 0, 100);
  812. memset(zErrMsg, 0, 100);
  813. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  814. memset(&idTagQuery, 0, sizeof(idTagQuery));
  815. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  816. /* Execute SQL statement */
  817. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  818. if( rc != SQLITE_OK )
  819. {
  820. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  821. }
  822. }
  823. void OCPP_getListVerion()
  824. {
  825. int rc = 0;
  826. // const char* data = "Callback function called";
  827. char sql[100];
  828. char zErrMsg[100];
  829. memset(sql, 0, 100);
  830. memset(zErrMsg, 0, 100);
  831. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  832. /* Execute SQL statement */
  833. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  834. if( rc != SQLITE_OK )
  835. {
  836. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  837. }
  838. }
  839. void OCPP_get_TableAuthlocalAllData(void)
  840. {
  841. int rc = 0;
  842. char sql[100];
  843. char zErrMsg[100];
  844. memset(sql, 0, 100);
  845. memset(zErrMsg, 0, 100);
  846. sprintf(sql,"select * from ocpp_auth_local ");
  847. /* Execute SQL statement */
  848. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  849. if( rc != SQLITE_OK )
  850. {
  851. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  852. }
  853. //return ver;
  854. }
  855. int OCPP_cleanLocalList()
  856. {
  857. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  858. char *errMsg = 0;
  859. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  860. if (SQLITE_OK != rc)
  861. {
  862. DEBUG_INFO("%s\n",errMsg);
  863. return FALSE;
  864. }
  865. return TRUE;
  866. }
  867. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  868. {
  869. int isSuccess = FALSE;
  870. int ret = 0;
  871. //const char* data = "Callback function called";
  872. char sql[300];
  873. char zErrMsg[200];
  874. memset(sql, 0, 300);
  875. memset(zErrMsg, 0, 200);
  876. 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);
  877. //* Execute SQL statement */
  878. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  879. if( ret != SQLITE_OK )
  880. {
  881. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  882. return isSuccess;
  883. }
  884. memset(sql, 0, 300);
  885. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  886. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  887. if( ret != SQLITE_OK )
  888. {
  889. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  890. return isSuccess;
  891. }
  892. isSuccess = TRUE;
  893. return isSuccess;
  894. }
  895. void OCPP_getIdTagFromLocalList(char idTag[])
  896. {
  897. int rc = 0;
  898. // const char* data = "Callback function called";
  899. char sql[100];
  900. char zErrMsg[100];
  901. memset(sql, 0, 100);
  902. memset(zErrMsg, 0, 100);
  903. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  904. memset(&idTagQuery, 0, sizeof(idTagQuery));
  905. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  906. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  907. /* Execute SQL statement */
  908. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  909. if( rc != SQLITE_OK )
  910. {
  911. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  912. }
  913. //return ver;
  914. }
  915. void OCPP_deleteIdTagFromLocalList(char idTag[])
  916. {
  917. //int ver = 0;
  918. //int isSuccess = FALSE;
  919. int rc = 0;
  920. char sql[100];
  921. char zErrMsg[100];
  922. memset(sql, 0, 100);
  923. memset(zErrMsg, 0, 100);
  924. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  925. //* Execute SQL statement */
  926. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  927. if( rc != SQLITE_OK )
  928. {
  929. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  930. }
  931. }
  932. int getCurrentYear()
  933. {
  934. int result = 0;
  935. time_t CurrentTime;
  936. struct tm *tm;
  937. CurrentTime = time(NULL);
  938. tm=localtime(&CurrentTime);
  939. result = (tm->tm_year + 1900);
  940. return result;
  941. }
  942. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  943. {
  944. int result = PASS;
  945. char* errMsg = NULL;
  946. char sqlStr[8192];
  947. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  948. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  949. {
  950. result = FAIL;
  951. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  952. }
  953. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  954. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  955. {
  956. result = FAIL;
  957. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  958. }
  959. return result;
  960. }
  961. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  962. {
  963. int isSuccess = TRUE;
  964. int tempIndex;
  965. json_object *EnergyDataTransfer = json_object_new_object();
  966. json_object *periodEnergys = json_object_new_object();
  967. char sql[1024];
  968. char zErrMsg[200];
  969. memset(sql, 0, ARRAY_SIZE(sql));
  970. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  971. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  972. {
  973. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  974. {
  975. tempIndex = ((gun_index==2) ? 1: 0);
  976. }
  977. else
  978. {
  979. tempIndex = gun_index;
  980. }
  981. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  982. {
  983. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  984. {
  985. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  986. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  987. {
  988. uint8_t period[3];
  989. sprintf((char*)period, "%d", idxPeriod);
  990. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  991. }
  992. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  993. } //end of the same index
  994. }//end of for CHAdeMO_QUANTITY
  995. }
  996. else if(gunType[gun_index] == GUN_TYPE_CCS)
  997. {
  998. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  999. {
  1000. tempIndex = ((gun_index==2) ? 1: 0);
  1001. }
  1002. else
  1003. {
  1004. tempIndex = gun_index;
  1005. }
  1006. for (int index = 0; index < CCS_QUANTITY; index++)
  1007. {
  1008. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1009. {
  1010. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1011. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1012. {
  1013. uint8_t period[3];
  1014. sprintf((char*)period, "%d", idxPeriod);
  1015. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1016. }
  1017. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1018. } //end of the same index
  1019. } // end of for CCS_QUANTITY
  1020. }
  1021. else if(gunType[gun_index] == GUN_TYPE_GBT)
  1022. {
  1023. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1024. {
  1025. tempIndex = ((gun_index==2) ? 1: 0);
  1026. }
  1027. else
  1028. {
  1029. tempIndex = gun_index;
  1030. }
  1031. for (int index = 0; index < GB_QUANTITY; index++)
  1032. {
  1033. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1034. {
  1035. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1036. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1037. {
  1038. uint8_t period[3];
  1039. sprintf((char*)period, "%d", idxPeriod);
  1040. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1041. }
  1042. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1043. } //end of the same index
  1044. } // end of for GB_QUANTITY
  1045. }
  1046. else if(gunType[gun_index] == GUN_TYPE_DO)
  1047. {
  1048. tempIndex = gun_index;
  1049. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1050. {
  1051. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1052. {
  1053. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1054. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1055. {
  1056. uint8_t period[3];
  1057. sprintf((char*)period, "%d", idxPeriod);
  1058. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1059. }
  1060. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1061. } //end of the same index
  1062. }
  1063. }
  1064. else
  1065. {
  1066. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1067. {
  1068. tempIndex = 2;
  1069. }
  1070. else
  1071. {
  1072. tempIndex = gun_index;
  1073. }
  1074. for (int index = 0; index < AC_QUANTITY; index++)
  1075. {
  1076. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1077. {
  1078. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1079. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1080. {
  1081. uint8_t period[3];
  1082. sprintf((char*)period, "%d", idxPeriod);
  1083. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1084. }
  1085. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1086. }//end of the same index
  1087. }//end of for AC_QUANTITY
  1088. }
  1089. 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));
  1090. json_object_put(EnergyDataTransfer);
  1091. //* Execute SQL statement */
  1092. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1093. {
  1094. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1095. isSuccess = FALSE;
  1096. }
  1097. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1098. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1099. {
  1100. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1101. isSuccess = FALSE;
  1102. }
  1103. return isSuccess;
  1104. }
  1105. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1106. {
  1107. int isSuccess = TRUE;
  1108. char sql[512];
  1109. char zErrMsg[200];
  1110. int rows, cols;
  1111. char **resultData;
  1112. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1113. /* Execute SQL statement */
  1114. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1115. {
  1116. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1117. isSuccess = FALSE;
  1118. }
  1119. else
  1120. {
  1121. if((rows > 0) && (atoi(resultData[4]) > 0))
  1122. {
  1123. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1124. }
  1125. else
  1126. {
  1127. DEBUG_WARN("There is not match transaction data.\n");
  1128. isSuccess = FALSE;
  1129. }
  1130. }
  1131. return isSuccess;
  1132. }
  1133. 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)
  1134. {
  1135. int result = PASS;
  1136. char* errMsg = NULL;
  1137. char sqlStr[8192];
  1138. 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');",
  1139. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1140. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1141. {
  1142. result = FAIL;
  1143. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1144. }
  1145. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1146. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1147. {
  1148. result = FAIL;
  1149. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1150. }
  1151. return result;
  1152. }
  1153. int OCPP_update_deduct_info(int txId, char *creditNo)
  1154. {
  1155. int result = PASS;
  1156. char* errMsg = NULL;
  1157. char sqlStr[8192];
  1158. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1159. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1160. {
  1161. result = FAIL;
  1162. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1163. }
  1164. return result;
  1165. }
  1166. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1167. {
  1168. json_object *dataBuf = json_object_new_object();
  1169. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1170. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1171. json_object_object_add(dataBuf, "txId", json_object_new_int(atoi(columnValue[1])));
  1172. json_object_object_add(dataBuf, "creditNo", json_object_new_string(columnValue[2]));
  1173. json_object_object_add(dataBuf, "deductResult", json_object_new_boolean(atoi(columnValue[3])));
  1174. json_object_object_add(dataBuf, "isDonateInvoice", json_object_new_boolean(atoi(columnValue[4])));
  1175. json_object_object_add(dataBuf, "amount", json_object_new_double(atof(columnValue[5])));
  1176. json_object_object_add(dataBuf, "approvalNo", json_object_new_string(columnValue[9]));
  1177. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1178. json_object_put(dataBuf);
  1179. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1180. return 0;
  1181. }
  1182. void OCPP_query_deduct_info()
  1183. {
  1184. int rc = 0;
  1185. char sql[100];
  1186. char zErrMsg[100];
  1187. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1188. /* Execute SQL statement */
  1189. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1190. if( rc != SQLITE_OK )
  1191. {
  1192. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1193. }
  1194. }
  1195. // Occupancy fee deduct queue process
  1196. int OCPP_insert_occupancyDeduct_info(char *occupancySN, char *creditNo, uint8_t deductResult, double amount, char *approvalNo)
  1197. {
  1198. int result = PASS;
  1199. char* errMsg = NULL;
  1200. char sqlStr[8192];
  1201. sprintf(sqlStr, "insert or replace into report_occupancyDeduct_info(occupancySN, creditNo, deductResult, amount, approvalNo, isUploaded) values('%s', '%s', '%d', '%.2f', '%s', '0');",
  1202. occupancySN, creditNo, deductResult, amount, approvalNo);
  1203. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1204. {
  1205. result = FAIL;
  1206. DEBUG_WARN( "Insert local report_occupancyDeduct_info error message: %s\n", errMsg);
  1207. }
  1208. sprintf(sqlStr, "delete from report_occupancyDeduct_info where (idx < (select idx from report_occupancyDeduct_info order by idx desc limit 1)-5000);");
  1209. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1210. {
  1211. result = FAIL;
  1212. DEBUG_WARN( "delete local report_occupancyDeduct_info error message: %s\n", errMsg);
  1213. }
  1214. return result;
  1215. }
  1216. int OCPP_update_occupancyDeduct_info(char *occupancySN)
  1217. {
  1218. int result = PASS;
  1219. char* errMsg = NULL;
  1220. char sqlStr[8192];
  1221. sprintf(sqlStr, "update report_occupancyDeduct_info set isUploaded='1' where occupancySN='%s';", occupancySN);
  1222. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1223. {
  1224. result = FAIL;
  1225. DEBUG_WARN( "Update local report_occupancyDeduct_info error message: %s\n", errMsg);
  1226. }
  1227. return result;
  1228. }
  1229. int queryOccupancyDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1230. {
  1231. json_object *dataBuf = json_object_new_object();
  1232. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1233. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1234. json_object_object_add(dataBuf, "occupancySN", json_object_new_string(columnValue[1]));
  1235. json_object_object_add(dataBuf, "creditNo", json_object_new_string(columnValue[2]));
  1236. json_object_object_add(dataBuf, "deductResult", json_object_new_boolean(atoi(columnValue[3])));
  1237. json_object_object_add(dataBuf, "amount", json_object_new_double(atof(columnValue[4])));
  1238. json_object_object_add(dataBuf, "approvalNo", json_object_new_string(columnValue[5]));
  1239. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1240. json_object_put(dataBuf);
  1241. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1242. return 0;
  1243. }
  1244. void OCPP_query_occupancyDeduct_info()
  1245. {
  1246. int rc = 0;
  1247. char sql[100];
  1248. char zErrMsg[100];
  1249. sprintf(sql,"select * from report_occupancyDeduct_info where isUploaded='0' order by idx limit 1");
  1250. /* Execute SQL statement */
  1251. rc = sqlite3_exec(db, sql, queryOccupancyDeductCallBack, 0, (char **)&zErrMsg);
  1252. if( rc != SQLITE_OK )
  1253. {
  1254. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1255. }
  1256. }
  1257. void reportReaderStatus(int gun_index)
  1258. {
  1259. struct timeval tmnow;
  1260. struct tm *tm;
  1261. char buf[28];//, usec_buf[6];
  1262. gettimeofday(&tmnow, NULL);
  1263. time_t t;
  1264. t = time(NULL);
  1265. /*UTC time and date*/
  1266. tm = gmtime(&t);
  1267. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1268. #if 0 // remove temporally
  1269. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1270. strcat(buf,".");
  1271. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1272. strcat(buf,usec_buf);
  1273. #endif
  1274. json_object *dataBuf = json_object_new_object();
  1275. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1276. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_ReaderStatus");
  1277. json_object_object_add(dataBuf, "ConnectorId", json_object_new_int((gun_index+1)));
  1278. json_object_object_add(dataBuf, "readerStatus", json_object_new_int(ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus));
  1279. json_object_object_add(dataBuf, "timestamp", json_object_new_string(buf));
  1280. json_object_object_add(dataBuf, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  1281. json_object_object_add(dataBuf, "creditNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo));
  1282. json_object_object_add(dataBuf, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  1283. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1284. json_object_put(dataBuf);
  1285. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1286. }
  1287. void getOccupancyFee(int gun_index)
  1288. {
  1289. struct timeval tmnow;
  1290. struct tm *tm;
  1291. char buf[28];//, usec_buf[6];
  1292. gettimeofday(&tmnow, NULL);
  1293. time_t t;
  1294. t = time(NULL);
  1295. /*UTC time and date*/
  1296. tm = gmtime(&t);
  1297. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1298. #if 0 // remove temporally
  1299. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1300. strcat(buf,".");
  1301. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1302. strcat(buf,usec_buf);
  1303. #endif
  1304. json_object *dataBuf = json_object_new_object();
  1305. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1306. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_GetOccupancyFee");
  1307. json_object_object_add(dataBuf, "ConnectorId", json_object_new_int((gun_index+1)));
  1308. json_object_object_add(dataBuf, "occupancySN", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.GetOccupancyFee[gun_index].occupancySN));
  1309. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1310. json_object_put(dataBuf);
  1311. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1312. }
  1313. //==========================================
  1314. // Check time passed since today
  1315. //==========================================
  1316. long long DiffTimebWithNow(struct timeb ST)
  1317. {
  1318. //return milli-second
  1319. struct timeb ET;
  1320. long long StartTime,StopTime;
  1321. ftime(&ET);
  1322. StartTime=(long long)ST.time;
  1323. StopTime=(long long)ET.time;
  1324. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1325. }
  1326. int getTimePassSinceToday(uint8_t gun_index)
  1327. {
  1328. int result = -1;
  1329. static time_t lastTime[4];
  1330. time_t t;
  1331. struct tm *tmStartToday;
  1332. struct timeb tbStartToday;
  1333. t=time(NULL);
  1334. if(difftime(t, lastTime[gun_index])>0)
  1335. {
  1336. tmStartToday=localtime(&t);
  1337. tmStartToday->tm_hour = 0;
  1338. tmStartToday->tm_min = 0;
  1339. tmStartToday->tm_sec = 0;
  1340. tbStartToday.time = mktime(tmStartToday);
  1341. tbStartToday.millitm = 0;
  1342. result = DiffTimebWithNow(tbStartToday)/1000;
  1343. lastTime[gun_index] = t;
  1344. }
  1345. return result;
  1346. }
  1347. void getNowDatetime(uint8_t *data)
  1348. {
  1349. time_t t = time(NULL);
  1350. struct tm tm = *localtime(&t);
  1351. 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);
  1352. }
  1353. int syncDateTimeRTC(uint8_t *data)
  1354. {
  1355. struct ParsingResult
  1356. {
  1357. int result;
  1358. int scanedElement;
  1359. int year;
  1360. int month;
  1361. int mday;
  1362. int hour;
  1363. int min;
  1364. int sec;
  1365. int tz_hour;
  1366. int tz_min;
  1367. float minSec;
  1368. }result;
  1369. struct tm tmOrg;
  1370. struct tm *tmTarget;
  1371. struct timeb tbTarget;
  1372. char buf[128];
  1373. memset(&result, 0x00, sizeof(struct ParsingResult));
  1374. result.result = PASS;
  1375. if(strstr((char*)data, ".") != NULL)
  1376. {
  1377. // Original data with mini second
  1378. if(strstr((char*)data, "Z") != NULL)
  1379. {
  1380. // Original data with Z
  1381. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1382. &result.year,
  1383. &result.month,
  1384. &result.mday,
  1385. &result.hour,
  1386. &result.min,
  1387. &result.sec,
  1388. &result.minSec);
  1389. }
  1390. else
  1391. {
  1392. // Original data without Z
  1393. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1394. &result.year,
  1395. &result.month,
  1396. &result.mday,
  1397. &result.hour,
  1398. &result.min,
  1399. &result.sec,
  1400. &result.minSec,
  1401. &result.tz_hour,
  1402. &result.tz_min);
  1403. }
  1404. }
  1405. else
  1406. {
  1407. // Original data without mini second
  1408. if(strstr((char*)data, "Z") != NULL)
  1409. {
  1410. // Original data with Z
  1411. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1412. &result.year,
  1413. &result.month,
  1414. &result.mday,
  1415. &result.hour,
  1416. &result.min,
  1417. &result.sec);
  1418. }
  1419. else
  1420. {
  1421. // Original data without Z
  1422. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1423. &result.year,
  1424. &result.month,
  1425. &result.mday,
  1426. &result.hour,
  1427. &result.min,
  1428. &result.sec,
  1429. &result.tz_hour,
  1430. &result.tz_min);
  1431. }
  1432. }
  1433. tmOrg.tm_year = result.year - 1900;
  1434. tmOrg.tm_mon = result.month - 1;
  1435. tmOrg.tm_mday = result.mday;
  1436. tmOrg.tm_hour = result.hour;
  1437. tmOrg.tm_min = result.min;
  1438. tmOrg.tm_sec = result.sec;
  1439. tmOrg.tm_gmtoff = 0;
  1440. tbTarget.time = mktime(&tmOrg);
  1441. tbTarget.timezone = 0;
  1442. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1443. tmTarget = gmtime(&tbTarget.time);
  1444. 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);
  1445. //DEBUG_INFO(" org date time: %s\n", data);
  1446. //DEBUG_INFO("parse date time: %s\n", buf);
  1447. system(buf);
  1448. system("/sbin/hwclock -w --systohc");
  1449. if(result.scanedElement < 6)
  1450. result.result = FAIL;
  1451. return result.result;
  1452. }
  1453. //==========================================
  1454. // Parse certificate content
  1455. //==========================================
  1456. int parseCertInfo(char *certPath, int parseType, char *data)
  1457. {
  1458. int result = FAIL;
  1459. memset(data, 0, ARRAY_SIZE(data));
  1460. if(access(certPath,F_OK) != -1)
  1461. {
  1462. char temp[512] = {0};
  1463. char capturedData[256] = {0};
  1464. char hashType[10] = "SHA256";
  1465. FILE *fp;
  1466. // Need to get hash type first
  1467. sprintf(temp ,"openssl x509 -noout -text -in %s", certPath);
  1468. fp = popen(temp, "r");
  1469. if(fp)
  1470. {
  1471. while(fgets(temp, sizeof(temp), fp) != NULL)
  1472. {
  1473. if(strstr(temp, "Signature Algorithm:") != NULL)
  1474. {
  1475. result = PASS;
  1476. if(strstr(temp, "sha256") != NULL || strstr(temp, "SHA256") != NULL)
  1477. sprintf((char*)hashType, "SHA256");
  1478. else if(strstr(temp, "sha384") != NULL || strstr(temp, "SHA384") != NULL)
  1479. sprintf((char*)hashType, "SHA384");
  1480. else if(strstr(temp, "sha512") != NULL || strstr(temp, "SHA512") != NULL)
  1481. sprintf((char*)hashType, "SHA512");
  1482. else
  1483. {
  1484. DEBUG_INFO("Error: hashAlgorithm is illegal or missing.\n");
  1485. result = FAIL;
  1486. }
  1487. break;
  1488. }
  1489. }
  1490. }
  1491. switch(parseType)
  1492. {
  1493. case CERT_PARSE_HashAlgorithm:
  1494. sprintf((char*)data, hashType);
  1495. DEBUG_INFO("hashAlgorithm: %s\n", hashType);
  1496. break;
  1497. case CERT_PARSE_SerialNumber:
  1498. sprintf(temp ,"openssl x509 -noout -serial -in %s", certPath);
  1499. fp = popen(temp, "r");
  1500. if(fp)
  1501. {
  1502. while(fgets(temp, sizeof(temp), fp) != NULL)
  1503. {
  1504. if(strstr(temp, "serial=") != NULL)
  1505. {
  1506. sscanf(temp, "%*[^=]=%s", capturedData);
  1507. result = PASS;
  1508. break;
  1509. }
  1510. }
  1511. DEBUG_INFO("serialNumber: %s\n", capturedData);
  1512. sprintf((char*)data, capturedData);
  1513. }
  1514. break;
  1515. case CERT_PARSE_IssuerNameHash:
  1516. sprintf(temp ,"openssl x509 -noout -issuer -in %s | openssl dgst -%s", certPath, (char*)hashType);
  1517. fp = popen(temp, "r");
  1518. if(fp)
  1519. {
  1520. while(fgets(temp, sizeof(temp), fp) != NULL)
  1521. {
  1522. if(strstr(temp, "(stdin)=") != NULL)
  1523. {
  1524. sscanf(temp, "%*[^=]=%s", capturedData);
  1525. result = PASS;
  1526. break;
  1527. }
  1528. }
  1529. stringtrimspace(capturedData);
  1530. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1531. sprintf((char*)data, capturedData);
  1532. }
  1533. break;
  1534. case CERT_PARSE_IssuerKeyHash:
  1535. sprintf(temp ,"openssl x509 -noout -pubkey -in %s | openssl dgst -%s", certPath, (char*)hashType);
  1536. fp = popen(temp, "r");
  1537. if(fp)
  1538. {
  1539. while(fgets(temp, sizeof(temp), fp) != NULL)
  1540. {
  1541. if(strstr(temp, "(stdin)=") != NULL)
  1542. {
  1543. sscanf(temp, "%*[^=]=%s", capturedData);
  1544. result = PASS;
  1545. break;
  1546. }
  1547. }
  1548. stringtrimspace(capturedData);
  1549. DEBUG_INFO("issuerKeyHash: %s\n", capturedData);
  1550. sprintf((char*)data, capturedData);
  1551. }
  1552. break;
  1553. case CERT_PARSE_OcspUrl:
  1554. //sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", certPath);
  1555. sprintf(temp ,"openssl crl2pkcs7 -nocrl -certfile %s | openssl pkcs7 -print_certs -text -noout", certPath);
  1556. fp = popen(temp, "r");
  1557. if(fp)
  1558. {
  1559. while(fgets(temp, sizeof(temp), fp) != NULL)
  1560. {
  1561. if(strstr(temp, "OCSP - URI:") != NULL)
  1562. {
  1563. //strcpy((char*)data, temp);
  1564. sscanf(temp, "%*[^:]:%s", capturedData);
  1565. sprintf((char*)data, capturedData);
  1566. DEBUG_INFO("OCSP_URI: %s\n", data);
  1567. result = PASS;
  1568. break;
  1569. }
  1570. }
  1571. }
  1572. break;
  1573. default:
  1574. DEBUG_INFO("Parse type is invalid.\n");
  1575. break;
  1576. }
  1577. pclose(fp);
  1578. }
  1579. return result;
  1580. }
  1581. //==========================================
  1582. // GetCompositeSchedule logic related function
  1583. //==========================================
  1584. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1585. {
  1586. //return milli-second
  1587. unsigned int StartTime,StopTime;
  1588. StartTime=(unsigned int)ST.time;
  1589. StopTime=(unsigned int)ET.time;
  1590. return (StopTime-StartTime);
  1591. }
  1592. int DiffTimebWithNowSec(struct timeb ST)
  1593. {
  1594. //return milli-second
  1595. struct timeb ET;
  1596. unsigned int StartTime,StopTime;
  1597. ftime(&ET);
  1598. StartTime=(unsigned int)ST.time;
  1599. StopTime=(unsigned int)ET.time;
  1600. return (StopTime-StartTime);
  1601. }
  1602. int getStartStop(uint8_t *start, uint8_t *stop)
  1603. {
  1604. struct ParsingResult
  1605. {
  1606. int result;
  1607. int scanedElement;
  1608. int year;
  1609. int month;
  1610. int mday;
  1611. int hour;
  1612. int min;
  1613. int sec;
  1614. int tz_hour;
  1615. int tz_min;
  1616. float minSec;
  1617. };
  1618. struct ParsingResult parseStart;
  1619. struct ParsingResult parseStop;
  1620. int result = -1;
  1621. struct tm tmStart;
  1622. struct timeb tbStart;
  1623. struct tm tmStop;
  1624. struct timeb tbStop;
  1625. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1626. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1627. // Scan start & stop date time
  1628. if(strstr((char*)start, ".") != NULL)
  1629. {
  1630. // Original data with mini second
  1631. if(strstr((char*)start, "Z") != NULL)
  1632. {
  1633. // Original data with Z
  1634. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1635. &parseStart.year,
  1636. &parseStart.month,
  1637. &parseStart.mday,
  1638. &parseStart.hour,
  1639. &parseStart.min,
  1640. &parseStart.sec,
  1641. &parseStart.minSec);
  1642. }
  1643. else
  1644. {
  1645. // Original data without Z
  1646. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1647. &parseStart.year,
  1648. &parseStart.month,
  1649. &parseStart.mday,
  1650. &parseStart.hour,
  1651. &parseStart.min,
  1652. &parseStart.sec,
  1653. &parseStart.minSec,
  1654. &parseStart.tz_hour,
  1655. &parseStart.tz_min);
  1656. }
  1657. }
  1658. else
  1659. {
  1660. // Original data without mini second
  1661. if(strstr((char*)start, "Z") != NULL)
  1662. {
  1663. // Original data with Z
  1664. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1665. &parseStart.year,
  1666. &parseStart.month,
  1667. &parseStart.mday,
  1668. &parseStart.hour,
  1669. &parseStart.min,
  1670. &parseStart.sec);
  1671. }
  1672. else
  1673. {
  1674. // Original data without Z
  1675. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1676. &parseStart.year,
  1677. &parseStart.month,
  1678. &parseStart.mday,
  1679. &parseStart.hour,
  1680. &parseStart.min,
  1681. &parseStart.sec,
  1682. &parseStart.tz_hour,
  1683. &parseStart.tz_min);
  1684. }
  1685. }
  1686. if(strstr((char*)stop, ".") != NULL)
  1687. {
  1688. // Original data with mini second
  1689. if(strstr((char*)stop, "Z") != NULL)
  1690. {
  1691. // Original data with Z
  1692. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1693. &parseStop.year,
  1694. &parseStop.month,
  1695. &parseStop.mday,
  1696. &parseStop.hour,
  1697. &parseStop.min,
  1698. &parseStop.sec,
  1699. &parseStop.minSec);
  1700. }
  1701. else
  1702. {
  1703. // Original data without Z
  1704. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1705. &parseStop.year,
  1706. &parseStop.month,
  1707. &parseStop.mday,
  1708. &parseStop.hour,
  1709. &parseStop.min,
  1710. &parseStop.sec,
  1711. &parseStop.minSec,
  1712. &parseStop.tz_hour,
  1713. &parseStop.tz_min);
  1714. }
  1715. }
  1716. else
  1717. {
  1718. // Original data without mini second
  1719. if(strstr((char*)stop, "Z") != NULL)
  1720. {
  1721. // Original data with Z
  1722. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1723. &parseStop.year,
  1724. &parseStop.month,
  1725. &parseStop.mday,
  1726. &parseStop.hour,
  1727. &parseStop.min,
  1728. &parseStop.sec);
  1729. }
  1730. else
  1731. {
  1732. // Original data without Z
  1733. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1734. &parseStop.year,
  1735. &parseStop.month,
  1736. &parseStop.mday,
  1737. &parseStop.hour,
  1738. &parseStop.min,
  1739. &parseStop.sec,
  1740. &parseStop.tz_hour,
  1741. &parseStop.tz_min);
  1742. }
  1743. }
  1744. // Calculate date time difference
  1745. if((parseStart.scanedElement >=6) &&
  1746. (parseStop.scanedElement >=6))
  1747. {
  1748. //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);
  1749. //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);
  1750. tmStart.tm_year = parseStart.year - 1900;
  1751. tmStart.tm_mon = parseStart.month - 1;
  1752. tmStart.tm_mday = parseStart.mday;
  1753. tmStart.tm_hour = parseStart.hour;
  1754. tmStart.tm_min = parseStart.min;
  1755. tmStart.tm_sec = parseStart.sec;
  1756. tmStart.tm_gmtoff = 0;
  1757. tbStart.time = mktime(&tmStart);
  1758. tbStart.timezone = 0;
  1759. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1760. tmStop.tm_year = parseStop.year - 1900;
  1761. tmStop.tm_mon = parseStop.month - 1;
  1762. tmStop.tm_mday = parseStop.mday;
  1763. tmStop.tm_hour = parseStop.hour;
  1764. tmStop.tm_min = parseStop.min;
  1765. tmStop.tm_sec = parseStop.sec;
  1766. tmStop.tm_gmtoff = 0;
  1767. tbStop.time = mktime(&tmStop);
  1768. tbStop.timezone = 0;
  1769. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1770. result = DiffTimebSec(tbStart, tbStop);
  1771. //DEBUG_INFO("getStartStop(): %d\n", result);
  1772. }
  1773. else
  1774. {
  1775. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1776. }
  1777. return result;
  1778. }
  1779. int isOvertNow(uint8_t *start)
  1780. {
  1781. int result = NO;
  1782. struct ParsingResult
  1783. {
  1784. int result;
  1785. int scanedElement;
  1786. int year;
  1787. int month;
  1788. int mday;
  1789. int hour;
  1790. int min;
  1791. int sec;
  1792. int tz_hour;
  1793. int tz_min;
  1794. float minSec;
  1795. }parsingResult;
  1796. struct tm tmStart;
  1797. struct timeb tbStart;
  1798. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1799. if(strstr((char*)start, ".") != NULL)
  1800. {
  1801. // Original data with mini second
  1802. if(strstr((char*)start, "Z") != NULL)
  1803. {
  1804. // Original data with Z
  1805. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1806. &parsingResult.year,
  1807. &parsingResult.month,
  1808. &parsingResult.mday,
  1809. &parsingResult.hour,
  1810. &parsingResult.min,
  1811. &parsingResult.sec,
  1812. &parsingResult.minSec);
  1813. }
  1814. else
  1815. {
  1816. // Original data without Z
  1817. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1818. &parsingResult.year,
  1819. &parsingResult.month,
  1820. &parsingResult.mday,
  1821. &parsingResult.hour,
  1822. &parsingResult.min,
  1823. &parsingResult.sec,
  1824. &parsingResult.minSec,
  1825. &parsingResult.tz_hour,
  1826. &parsingResult.tz_min);
  1827. }
  1828. }
  1829. else
  1830. {
  1831. // Original data without mini second
  1832. if(strstr((char*)start, "Z") != NULL)
  1833. {
  1834. // Original data with Z
  1835. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1836. &parsingResult.year,
  1837. &parsingResult.month,
  1838. &parsingResult.mday,
  1839. &parsingResult.hour,
  1840. &parsingResult.min,
  1841. &parsingResult.sec);
  1842. }
  1843. else
  1844. {
  1845. // Original data without Z
  1846. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1847. &parsingResult.year,
  1848. &parsingResult.month,
  1849. &parsingResult.mday,
  1850. &parsingResult.hour,
  1851. &parsingResult.min,
  1852. &parsingResult.sec,
  1853. &parsingResult.tz_hour,
  1854. &parsingResult.tz_min);
  1855. }
  1856. }
  1857. if(parsingResult.scanedElement >= 6)
  1858. {
  1859. tmStart.tm_year = parsingResult.year - 1900;
  1860. tmStart.tm_mon = parsingResult.month - 1;
  1861. tmStart.tm_mday = parsingResult.mday;
  1862. tmStart.tm_hour = parsingResult.hour;
  1863. tmStart.tm_min = parsingResult.min;
  1864. tmStart.tm_sec = parsingResult.sec;
  1865. tmStart.tm_gmtoff = 0;
  1866. tbStart.time = mktime(&tmStart);
  1867. tbStart.timezone = 0;
  1868. tbStart.millitm = 0;
  1869. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1870. if(DiffTimebWithNowSec(tbStart) <= 0)
  1871. result = NO;
  1872. else
  1873. result = YES;
  1874. }
  1875. else
  1876. {
  1877. DEBUG_WARN("Start date parsing error.\n");
  1878. }
  1879. return result;
  1880. }
  1881. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1882. {
  1883. struct ParsingResult
  1884. {
  1885. int result;
  1886. int scanedElement;
  1887. int year;
  1888. int month;
  1889. int mday;
  1890. int hour;
  1891. int min;
  1892. int sec;
  1893. int tz_hour;
  1894. int tz_min;
  1895. float minSec;
  1896. };
  1897. struct ParsingResult parseStart;
  1898. struct ParsingResult parseStop;
  1899. int result = -1;
  1900. struct tm tmStart;
  1901. struct timeb tbStart;
  1902. struct tm tmStop;
  1903. struct timeb tbStop;
  1904. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1905. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1906. // Scan start & stop date time
  1907. if(strstr((char*)start, ".") != NULL)
  1908. {
  1909. // Original data with mini second
  1910. if(strstr((char*)start, "Z") != NULL)
  1911. {
  1912. // Original data with Z
  1913. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1914. &parseStart.year,
  1915. &parseStart.month,
  1916. &parseStart.mday,
  1917. &parseStart.hour,
  1918. &parseStart.min,
  1919. &parseStart.sec,
  1920. &parseStart.minSec);
  1921. }
  1922. else
  1923. {
  1924. // Original data without Z
  1925. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1926. &parseStart.year,
  1927. &parseStart.month,
  1928. &parseStart.mday,
  1929. &parseStart.hour,
  1930. &parseStart.min,
  1931. &parseStart.sec,
  1932. &parseStart.minSec,
  1933. &parseStart.tz_hour,
  1934. &parseStart.tz_min);
  1935. }
  1936. }
  1937. else
  1938. {
  1939. // Original data without mini second
  1940. if(strstr((char*)start, "Z") != NULL)
  1941. {
  1942. // Original data with Z
  1943. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1944. &parseStart.year,
  1945. &parseStart.month,
  1946. &parseStart.mday,
  1947. &parseStart.hour,
  1948. &parseStart.min,
  1949. &parseStart.sec);
  1950. }
  1951. else
  1952. {
  1953. // Original data without Z
  1954. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1955. &parseStart.year,
  1956. &parseStart.month,
  1957. &parseStart.mday,
  1958. &parseStart.hour,
  1959. &parseStart.min,
  1960. &parseStart.sec,
  1961. &parseStart.tz_hour,
  1962. &parseStart.tz_min);
  1963. }
  1964. }
  1965. if(strstr((char*)stop, ".") != NULL)
  1966. {
  1967. // Original data with mini second
  1968. if(strstr((char*)stop, "Z") != NULL)
  1969. {
  1970. // Original data with Z
  1971. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1972. &parseStop.year,
  1973. &parseStop.month,
  1974. &parseStop.mday,
  1975. &parseStop.hour,
  1976. &parseStop.min,
  1977. &parseStop.sec,
  1978. &parseStop.minSec);
  1979. }
  1980. else
  1981. {
  1982. // Original data without Z
  1983. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1984. &parseStop.year,
  1985. &parseStop.month,
  1986. &parseStop.mday,
  1987. &parseStop.hour,
  1988. &parseStop.min,
  1989. &parseStop.sec,
  1990. &parseStop.minSec,
  1991. &parseStop.tz_hour,
  1992. &parseStop.tz_min);
  1993. }
  1994. }
  1995. else
  1996. {
  1997. // Original data without mini second
  1998. if(strstr((char*)stop, "Z") != NULL)
  1999. {
  2000. // Original data with Z
  2001. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  2002. &parseStop.year,
  2003. &parseStop.month,
  2004. &parseStop.mday,
  2005. &parseStop.hour,
  2006. &parseStop.min,
  2007. &parseStop.sec);
  2008. }
  2009. else
  2010. {
  2011. // Original data without Z
  2012. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  2013. &parseStop.year,
  2014. &parseStop.month,
  2015. &parseStop.mday,
  2016. &parseStop.hour,
  2017. &parseStop.min,
  2018. &parseStop.sec,
  2019. &parseStop.tz_hour,
  2020. &parseStop.tz_min);
  2021. }
  2022. }
  2023. // Calculate date time difference
  2024. if((parseStart.scanedElement >=6) &&
  2025. (parseStop.scanedElement >=6))
  2026. {
  2027. //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);
  2028. //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);
  2029. tmStart.tm_year = parseStart.year - 1900;
  2030. tmStart.tm_mon = parseStart.month - 1;
  2031. tmStart.tm_mday = parseStart.mday;
  2032. tmStart.tm_hour = parseStart.hour;
  2033. tmStart.tm_min = parseStart.min;
  2034. tmStart.tm_sec = parseStart.sec;
  2035. tmStart.tm_gmtoff = 0;
  2036. tbStart.time = mktime(&tmStart);
  2037. tbStart.timezone = 0;
  2038. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  2039. tmStop.tm_year = parseStop.year - 1900;
  2040. tmStop.tm_mon = parseStop.month - 1;
  2041. tmStop.tm_mday = parseStop.mday;
  2042. tmStop.tm_hour = parseStop.hour;
  2043. tmStop.tm_min = parseStop.min;
  2044. tmStop.tm_sec = parseStop.sec;
  2045. tmStop.tm_gmtoff = 0;
  2046. tbStop.time = mktime(&tmStop);
  2047. tbStop.timezone = 0;
  2048. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  2049. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  2050. //DEBUG_INFO("getStartStop(): %d\n", result);
  2051. }
  2052. else
  2053. {
  2054. DEBUG_WARN("Start or stop date parsing error.\r\n");
  2055. }
  2056. return result;
  2057. }
  2058. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2059. {
  2060. FILE *fp;
  2061. char profileFileName[128];
  2062. char *line = NULL;
  2063. size_t len = 0;
  2064. time_t CurrentTime;
  2065. struct tm *tmComposite;
  2066. struct StructChargingProfile maxProfile;
  2067. struct StructChargingProfile compositeProfile;
  2068. uint8_t limitMax=0;
  2069. int compositePeriodIdx = 0;
  2070. //uint8_t isDurationNull = FALSE;
  2071. CurrentTime = time(NULL);
  2072. tmComposite=localtime(&CurrentTime);
  2073. 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);
  2074. if(isUnitA)
  2075. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2076. else
  2077. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2078. compositeProfile.ChargingSchedule.Duration = durationReq;
  2079. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2080. {
  2081. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2082. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2083. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2084. }
  2085. compositeProfile.ChargingProfileId = 0;
  2086. compositeProfile.StackLevel = 99 ;
  2087. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2088. maxProfile.ChargingProfileId = -1;
  2089. maxProfile.ChargingSchedule.Duration = -1;
  2090. system("rm -f /tmp/*.json");
  2091. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2092. // Search max profile
  2093. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2094. if((access(profileFileName, F_OK))!=-1)
  2095. {
  2096. fp = fopen(profileFileName, "r");
  2097. while(getline(&line, &len, fp) != -1)
  2098. {
  2099. json_object *obj = NULL;
  2100. obj = json_tokener_parse(line);
  2101. if(is_error(obj))
  2102. {
  2103. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2104. }
  2105. else
  2106. {
  2107. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2108. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2109. )
  2110. {
  2111. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2112. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2113. )
  2114. {
  2115. struct tm tmFrom, tmTo;
  2116. struct timeb tbFrom, tbTo;
  2117. 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) &&
  2118. (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))
  2119. {
  2120. tmFrom.tm_year -= 1900;
  2121. tmFrom.tm_mon -= 1;
  2122. tbFrom.time = mktime(&tmFrom);
  2123. tmTo.tm_year -= 1900;
  2124. tmTo.tm_mon -= 1;
  2125. tbTo.time = mktime(&tmTo);
  2126. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2127. {
  2128. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2129. {
  2130. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2131. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2132. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2133. }
  2134. if(maxProfile.ChargingProfileId == -1)
  2135. DEBUG_INFO("MaxProfile found.\n");
  2136. else
  2137. DEBUG_INFO("MaxProfile updated.\n");
  2138. // Required item
  2139. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2140. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2141. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2142. if(isUnitA)
  2143. {
  2144. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2145. 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++)
  2146. {
  2147. 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"));
  2148. 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?
  2149. 3:
  2150. 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")));
  2151. 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")));
  2152. }
  2153. }
  2154. else
  2155. {
  2156. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2157. 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++)
  2158. {
  2159. 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"));
  2160. 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?
  2161. 3:
  2162. 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")));
  2163. 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));
  2164. }
  2165. }
  2166. // Optional item
  2167. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2168. {
  2169. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2170. }
  2171. else
  2172. {
  2173. sprintf((char*)maxProfile.ValidFrom, " ");
  2174. }
  2175. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2176. {
  2177. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2178. }
  2179. else
  2180. {
  2181. sprintf((char*)maxProfile.ValidTo, " ");
  2182. }
  2183. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2184. {
  2185. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2186. }
  2187. else
  2188. {
  2189. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2190. }
  2191. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2192. {
  2193. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2194. }
  2195. else
  2196. {
  2197. maxProfile.TransactionId = -1;
  2198. }
  2199. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2200. {
  2201. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2202. }
  2203. else
  2204. {
  2205. maxProfile.ChargingSchedule.Duration = 86400;
  2206. //isDurationNull = TRUE;
  2207. }
  2208. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2209. {
  2210. 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")));
  2211. }
  2212. else
  2213. {
  2214. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2215. }
  2216. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2217. {
  2218. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2219. }
  2220. else
  2221. {
  2222. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2223. }
  2224. }
  2225. }
  2226. }
  2227. else
  2228. {
  2229. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2230. {
  2231. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2232. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2233. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2234. }
  2235. if(maxProfile.ChargingProfileId == -1)
  2236. DEBUG_INFO("MaxProfile found.\n");
  2237. else
  2238. DEBUG_INFO("MaxProfile updated.\n");
  2239. // Required item
  2240. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2241. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2242. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2243. if(isUnitA)
  2244. {
  2245. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2246. 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++)
  2247. {
  2248. 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"));
  2249. 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?
  2250. 3:
  2251. 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")));
  2252. 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")));
  2253. }
  2254. }
  2255. else
  2256. {
  2257. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2258. 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++)
  2259. {
  2260. 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"));
  2261. 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?
  2262. 3:
  2263. 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")));
  2264. 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));
  2265. }
  2266. }
  2267. // Optional item
  2268. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2269. {
  2270. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2271. }
  2272. else
  2273. {
  2274. sprintf((char*)maxProfile.ValidFrom, " ");
  2275. }
  2276. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2277. {
  2278. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2279. }
  2280. else
  2281. {
  2282. sprintf((char*)maxProfile.ValidTo, " ");
  2283. }
  2284. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2285. {
  2286. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2287. }
  2288. else
  2289. {
  2290. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2291. }
  2292. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2293. {
  2294. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2295. }
  2296. else
  2297. {
  2298. maxProfile.TransactionId = -1;
  2299. }
  2300. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2301. {
  2302. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2303. }
  2304. else
  2305. {
  2306. maxProfile.ChargingSchedule.Duration = 86400;
  2307. //isDurationNull = TRUE;
  2308. }
  2309. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2310. {
  2311. 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")));
  2312. }
  2313. else
  2314. {
  2315. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2316. }
  2317. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2318. {
  2319. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2320. }
  2321. else
  2322. {
  2323. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2324. }
  2325. }
  2326. }
  2327. }
  2328. json_object_put(obj);
  2329. }
  2330. fclose(fp);
  2331. /*
  2332. if(maxProfile.ChargingProfileId !=-1)
  2333. {
  2334. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2335. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2336. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2337. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2338. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2339. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2340. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2341. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2342. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2343. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2344. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2345. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2346. {
  2347. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2348. {
  2349. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2350. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2351. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2352. }
  2353. }
  2354. }
  2355. else
  2356. DEBUG_INFO("MaxProfile not found.\n");
  2357. DEBUG_INFO("------------------------------------\n");*/
  2358. }
  2359. if(maxProfile.ChargingProfileId != -1)
  2360. {
  2361. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2362. {
  2363. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  2364. {
  2365. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2366. 0:
  2367. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2368. }
  2369. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2370. {
  2371. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2372. {
  2373. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2374. 0:
  2375. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2376. if(idxPeriod > 0)
  2377. {
  2378. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2379. {
  2380. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2381. }
  2382. }
  2383. }
  2384. }
  2385. }
  2386. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2387. {
  2388. if(maxProfile.ChargingSchedule.Duration != -1)
  2389. {
  2390. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2391. }
  2392. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2393. {
  2394. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2395. {
  2396. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2397. if(idxPeriod > 0)
  2398. {
  2399. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2400. {
  2401. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2402. }
  2403. }
  2404. }
  2405. }
  2406. }
  2407. else
  2408. {
  2409. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2410. {
  2411. if(maxProfile.ChargingSchedule.Duration != -1)
  2412. {
  2413. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2414. 0:
  2415. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2416. }
  2417. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2418. {
  2419. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2420. {
  2421. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2422. 0:
  2423. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2424. if(idxPeriod > 0)
  2425. {
  2426. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2427. {
  2428. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2429. }
  2430. }
  2431. }
  2432. }
  2433. }
  2434. else
  2435. {
  2436. if(maxProfile.ChargingSchedule.Duration != -1)
  2437. {
  2438. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2439. 0:
  2440. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2441. }
  2442. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2443. {
  2444. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2445. {
  2446. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2447. 0:
  2448. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2449. if(idxPeriod > 0)
  2450. {
  2451. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2452. {
  2453. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2454. }
  2455. }
  2456. }
  2457. }
  2458. }
  2459. }
  2460. /*
  2461. DEBUG_INFO("MaxProfile after align.\n");
  2462. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2463. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2464. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2465. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2466. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2467. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2468. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2469. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2470. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2471. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2472. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2473. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2474. {
  2475. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2476. {
  2477. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2478. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2479. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2480. }
  2481. }
  2482. DEBUG_INFO("------------------------------------\n");*/
  2483. }
  2484. // Find each profile period quantity
  2485. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2486. {
  2487. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2488. limitMax = idx+1;
  2489. }
  2490. if(maxProfile.ChargingProfileId != -1)
  2491. {
  2492. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2493. {
  2494. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2495. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2496. (maxProfile.ChargingSchedule.Duration > 0))
  2497. {
  2498. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2499. {
  2500. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2501. compositePeriodIdx++;
  2502. }
  2503. else
  2504. {
  2505. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2506. }
  2507. }
  2508. }
  2509. }
  2510. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2511. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2512. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2513. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2514. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2515. {
  2516. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2517. {
  2518. compositeProfile.ChargingProfileId = 1;
  2519. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2520. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2521. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2522. }
  2523. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2524. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2525. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2526. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2527. }
  2528. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2529. if(line)
  2530. free(line);
  2531. }
  2532. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2533. {
  2534. FILE *fp;
  2535. char profileFileName[128];
  2536. char *line = NULL;
  2537. size_t len = 0;
  2538. time_t CurrentTime;
  2539. struct tm *tmComposite;
  2540. struct StructChargingProfile maxProfile;
  2541. struct StructChargingProfile defaultTxProfile;
  2542. struct StructChargingProfile txProfile;
  2543. struct StructChargingProfile compositeProfile;
  2544. struct StructChargingSchedulePeriod tmpPeriod;
  2545. uint8_t limitMax=0;
  2546. uint8_t limitDef=0;
  2547. uint8_t limitTx=0;
  2548. int compositePeriodIdx = 0;
  2549. CurrentTime = time(NULL);
  2550. tmComposite=localtime(&CurrentTime);
  2551. 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);
  2552. if(isUnitA)
  2553. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2554. else
  2555. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2556. compositeProfile.ChargingSchedule.Duration = durationReq;
  2557. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2558. {
  2559. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2560. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2561. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2562. }
  2563. compositeProfile.ChargingProfileId = 0;
  2564. compositeProfile.StackLevel = 99 ;
  2565. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2566. maxProfile.ChargingProfileId = -1;
  2567. defaultTxProfile.ChargingProfileId = -1;
  2568. txProfile.ChargingProfileId = -1;
  2569. maxProfile.ChargingSchedule.Duration = -1;
  2570. defaultTxProfile.ChargingSchedule.Duration = -1;
  2571. txProfile.ChargingSchedule.Duration = -1;
  2572. system("rm -f /tmp/*.json");
  2573. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2574. /*
  2575. * Search valid charging profile
  2576. */
  2577. //DEBUG_INFO("====================================\n");
  2578. // Search tx profile
  2579. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2580. if((access(profileFileName, F_OK))!=-1)
  2581. {
  2582. fp = fopen(profileFileName, "r");
  2583. while(getline(&line, &len, fp) != -1)
  2584. {
  2585. json_object *obj = NULL;
  2586. obj = json_tokener_parse(line);
  2587. if(is_error(obj))
  2588. {
  2589. DEBUG_ERROR("Parse txProfile from file error.\n");
  2590. }
  2591. else
  2592. {
  2593. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2594. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2595. )
  2596. {
  2597. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2598. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2599. )
  2600. {
  2601. struct tm tmFrom, tmTo;
  2602. struct timeb tbFrom, tbTo;
  2603. 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) &&
  2604. (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))
  2605. {
  2606. tmFrom.tm_year -= 1900;
  2607. tmFrom.tm_mon -= 1;
  2608. tbFrom.time = mktime(&tmFrom);
  2609. tmTo.tm_year -= 1900;
  2610. tmTo.tm_mon -= 1;
  2611. tbTo.time = mktime(&tmTo);
  2612. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2613. {
  2614. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2615. {
  2616. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2617. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2618. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2619. }
  2620. if(txProfile.ChargingProfileId == -1)
  2621. DEBUG_INFO("TxProfile found.\n");
  2622. else
  2623. DEBUG_INFO("TxProfile updated.\n");
  2624. // Required item
  2625. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2626. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2627. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2628. if(isUnitA)
  2629. {
  2630. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2631. 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++)
  2632. {
  2633. 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"));
  2634. 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?
  2635. 3:
  2636. 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")));
  2637. 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")));
  2638. }
  2639. }
  2640. else
  2641. {
  2642. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2643. 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++)
  2644. {
  2645. 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"));
  2646. 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?
  2647. 3:
  2648. 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")));
  2649. 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));
  2650. }
  2651. }
  2652. // Optional item
  2653. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2654. {
  2655. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2656. }
  2657. else
  2658. {
  2659. sprintf((char*)txProfile.ValidFrom, " ");
  2660. }
  2661. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2662. {
  2663. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2664. }
  2665. else
  2666. {
  2667. sprintf((char*)txProfile.ValidTo, " ");
  2668. }
  2669. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2670. {
  2671. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2672. }
  2673. else
  2674. {
  2675. sprintf((char*)txProfile.RecurrencyKind, " ");
  2676. }
  2677. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2678. {
  2679. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2680. }
  2681. else
  2682. {
  2683. txProfile.TransactionId = -1;
  2684. }
  2685. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2686. {
  2687. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2688. }
  2689. else
  2690. {
  2691. txProfile.ChargingSchedule.Duration = 86400;
  2692. }
  2693. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2694. {
  2695. 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")));
  2696. }
  2697. else
  2698. {
  2699. 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));
  2700. }
  2701. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2702. {
  2703. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2704. }
  2705. else
  2706. {
  2707. txProfile.ChargingSchedule.MinChargingRate = -1;
  2708. }
  2709. }
  2710. }
  2711. }
  2712. else
  2713. {
  2714. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2715. {
  2716. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2717. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2718. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2719. }
  2720. if(txProfile.ChargingProfileId == -1)
  2721. DEBUG_INFO("TxProfile found.\n");
  2722. else
  2723. DEBUG_INFO("TxProfile updated.\n");
  2724. // Required item
  2725. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2726. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2727. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2728. if(isUnitA)
  2729. {
  2730. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2731. 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++)
  2732. {
  2733. 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"));
  2734. 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?
  2735. 3:
  2736. 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")));
  2737. 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")));
  2738. }
  2739. }
  2740. else
  2741. {
  2742. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2743. 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++)
  2744. {
  2745. 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"));
  2746. 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?
  2747. 3:
  2748. 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")));
  2749. 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));
  2750. }
  2751. }
  2752. // Optional item
  2753. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2754. {
  2755. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2756. }
  2757. else
  2758. {
  2759. sprintf((char*)txProfile.ValidFrom, " ");
  2760. }
  2761. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2762. {
  2763. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2764. }
  2765. else
  2766. {
  2767. sprintf((char*)txProfile.ValidTo, " ");
  2768. }
  2769. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2770. {
  2771. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2772. }
  2773. else
  2774. {
  2775. sprintf((char*)txProfile.RecurrencyKind, " ");
  2776. }
  2777. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2778. {
  2779. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2780. }
  2781. else
  2782. {
  2783. txProfile.TransactionId = -1;
  2784. }
  2785. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2786. {
  2787. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2788. }
  2789. else
  2790. {
  2791. txProfile.ChargingSchedule.Duration = 86400;
  2792. }
  2793. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2794. {
  2795. 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")));
  2796. }
  2797. else
  2798. {
  2799. 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));
  2800. }
  2801. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2802. {
  2803. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2804. }
  2805. else
  2806. {
  2807. txProfile.ChargingSchedule.MinChargingRate = -1;
  2808. }
  2809. }
  2810. }
  2811. }
  2812. json_object_put(obj);
  2813. }
  2814. fclose(fp);
  2815. /*
  2816. if(txProfile.ChargingProfileId != -1)
  2817. {
  2818. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2819. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2820. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2821. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2822. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2823. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2824. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2825. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2826. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2827. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2828. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2829. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2830. {
  2831. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2832. {
  2833. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2834. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2835. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2836. }
  2837. }
  2838. }
  2839. else
  2840. DEBUG_INFO("TxProfile not found.\n");*/
  2841. }
  2842. // Search default tx profile
  2843. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2844. if((access(profileFileName, F_OK))==-1)
  2845. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2846. if((access(profileFileName, F_OK))!=-1)
  2847. {
  2848. fp = fopen(profileFileName, "r");
  2849. while(getline(&line, &len, fp) != -1)
  2850. {
  2851. json_object *obj = NULL;
  2852. obj = json_tokener_parse(line);
  2853. if(is_error(obj))
  2854. {
  2855. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2856. }
  2857. else
  2858. {
  2859. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2860. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2861. )
  2862. {
  2863. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2864. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2865. )
  2866. {
  2867. struct tm tmFrom, tmTo;
  2868. struct timeb tbFrom, tbTo;
  2869. 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) &&
  2870. (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))
  2871. {
  2872. tmFrom.tm_year -= 1900;
  2873. tmFrom.tm_mon -= 1;
  2874. tbFrom.time = mktime(&tmFrom);
  2875. tmTo.tm_year -= 1900;
  2876. tmTo.tm_mon -= 1;
  2877. tbTo.time = mktime(&tmTo);
  2878. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2879. {
  2880. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2881. {
  2882. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2883. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2884. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2885. }
  2886. if(defaultTxProfile.ChargingProfileId == -1)
  2887. DEBUG_INFO("TxDefaultProfile found.\n");
  2888. else
  2889. DEBUG_INFO("TxDefaultProfile updated.\n");
  2890. // Required item
  2891. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2892. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2893. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2894. if(isUnitA)
  2895. {
  2896. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2897. 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++)
  2898. {
  2899. 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"));
  2900. 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?
  2901. 3:
  2902. 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")));
  2903. 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")));
  2904. }
  2905. }
  2906. else
  2907. {
  2908. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2909. 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++)
  2910. {
  2911. 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"));
  2912. 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?
  2913. 3:
  2914. 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")));
  2915. 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));
  2916. }
  2917. }
  2918. // Optional item
  2919. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2920. {
  2921. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2922. }
  2923. else
  2924. {
  2925. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2926. }
  2927. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2928. {
  2929. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2930. }
  2931. else
  2932. {
  2933. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2934. }
  2935. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2936. {
  2937. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2938. }
  2939. else
  2940. {
  2941. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2942. }
  2943. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2944. {
  2945. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2946. }
  2947. else
  2948. {
  2949. defaultTxProfile.TransactionId = -1;
  2950. }
  2951. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2952. {
  2953. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2954. }
  2955. else
  2956. {
  2957. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2958. }
  2959. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2960. {
  2961. 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")));
  2962. }
  2963. else
  2964. {
  2965. 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));
  2966. }
  2967. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2968. {
  2969. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2970. }
  2971. else
  2972. {
  2973. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2974. }
  2975. }
  2976. }
  2977. }
  2978. else
  2979. {
  2980. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2981. {
  2982. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2983. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2984. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2985. }
  2986. if(defaultTxProfile.ChargingProfileId == -1)
  2987. DEBUG_INFO("TxDefaultProfile found.\n");
  2988. else
  2989. DEBUG_INFO("TxDefaultProfile updated.\n");
  2990. // Required item
  2991. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2992. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2993. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2994. if(isUnitA)
  2995. {
  2996. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2997. 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++)
  2998. {
  2999. 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"));
  3000. 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?
  3001. 3:
  3002. 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")));
  3003. 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")));
  3004. }
  3005. }
  3006. else
  3007. {
  3008. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3009. 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++)
  3010. {
  3011. 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"));
  3012. 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?
  3013. 3:
  3014. 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")));
  3015. 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));
  3016. }
  3017. }
  3018. // Optional item
  3019. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3020. {
  3021. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3022. }
  3023. else
  3024. {
  3025. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  3026. }
  3027. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3028. {
  3029. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3030. }
  3031. else
  3032. {
  3033. sprintf((char*)defaultTxProfile.ValidTo, " ");
  3034. }
  3035. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3036. {
  3037. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3038. }
  3039. else
  3040. {
  3041. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  3042. }
  3043. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3044. {
  3045. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3046. }
  3047. else
  3048. {
  3049. defaultTxProfile.TransactionId = -1;
  3050. }
  3051. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3052. {
  3053. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3054. }
  3055. else
  3056. {
  3057. defaultTxProfile.ChargingSchedule.Duration = 86400;
  3058. }
  3059. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3060. {
  3061. 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")));
  3062. }
  3063. else
  3064. {
  3065. 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));
  3066. }
  3067. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3068. {
  3069. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3070. }
  3071. else
  3072. {
  3073. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  3074. }
  3075. }
  3076. }
  3077. }
  3078. json_object_put(obj);
  3079. }
  3080. fclose(fp);
  3081. /*
  3082. if(defaultTxProfile.ChargingProfileId != -1)
  3083. {
  3084. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3085. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3086. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3087. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3088. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3089. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3090. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3091. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  3092. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3093. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3094. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3095. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3096. {
  3097. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3098. {
  3099. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3100. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3101. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3102. }
  3103. }
  3104. }
  3105. else
  3106. DEBUG_INFO("TxDefaultProfile not found.\n");
  3107. DEBUG_INFO("------------------------------------\n");*/
  3108. }
  3109. // Search max profile
  3110. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  3111. if((access(profileFileName, F_OK))!=-1)
  3112. {
  3113. fp = fopen(profileFileName, "r");
  3114. while(getline(&line, &len, fp) != -1)
  3115. {
  3116. json_object *obj = NULL;
  3117. obj = json_tokener_parse(line);
  3118. if(is_error(obj))
  3119. {
  3120. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  3121. }
  3122. else
  3123. {
  3124. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  3125. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  3126. )
  3127. {
  3128. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3129. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3130. )
  3131. {
  3132. struct tm tmFrom, tmTo;
  3133. struct timeb tbFrom, tbTo;
  3134. 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) &&
  3135. (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))
  3136. {
  3137. tmFrom.tm_year -= 1900;
  3138. tmFrom.tm_mon -= 1;
  3139. tbFrom.time = mktime(&tmFrom);
  3140. tmTo.tm_year -= 1900;
  3141. tmTo.tm_mon -= 1;
  3142. tbTo.time = mktime(&tmTo);
  3143. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3144. {
  3145. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3146. {
  3147. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3148. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3149. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3150. }
  3151. if(maxProfile.ChargingProfileId == -1)
  3152. DEBUG_INFO("MaxProfile found.\n");
  3153. else
  3154. DEBUG_INFO("MaxProfile updated.\n");
  3155. // Required item
  3156. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3157. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3158. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3159. if(isUnitA)
  3160. {
  3161. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3162. 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++)
  3163. {
  3164. 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"));
  3165. 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?
  3166. 3:
  3167. 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")));
  3168. 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")));
  3169. }
  3170. }
  3171. else
  3172. {
  3173. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3174. 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++)
  3175. {
  3176. 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"));
  3177. 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?
  3178. 3:
  3179. 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")));
  3180. 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));
  3181. }
  3182. }
  3183. // Optional item
  3184. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3185. {
  3186. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3187. }
  3188. else
  3189. {
  3190. sprintf((char*)maxProfile.ValidFrom, " ");
  3191. }
  3192. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3193. {
  3194. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3195. }
  3196. else
  3197. {
  3198. sprintf((char*)maxProfile.ValidTo, " ");
  3199. }
  3200. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3201. {
  3202. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3203. }
  3204. else
  3205. {
  3206. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3207. }
  3208. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3209. {
  3210. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3211. }
  3212. else
  3213. {
  3214. maxProfile.TransactionId = -1;
  3215. }
  3216. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3217. {
  3218. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3219. }
  3220. else
  3221. {
  3222. maxProfile.ChargingSchedule.Duration = 86400;
  3223. }
  3224. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3225. {
  3226. 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")));
  3227. }
  3228. else
  3229. {
  3230. 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));
  3231. }
  3232. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3233. {
  3234. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3235. }
  3236. else
  3237. {
  3238. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3239. }
  3240. }
  3241. }
  3242. }
  3243. else
  3244. {
  3245. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3246. {
  3247. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3248. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3249. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3250. }
  3251. if(maxProfile.ChargingProfileId == -1)
  3252. DEBUG_INFO("MaxProfile found.\n");
  3253. else
  3254. DEBUG_INFO("MaxProfile updated.\n");
  3255. // Required item
  3256. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3257. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3258. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3259. if(isUnitA)
  3260. {
  3261. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3262. 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++)
  3263. {
  3264. 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"));
  3265. 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?
  3266. 3:
  3267. 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")));
  3268. 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")));
  3269. }
  3270. }
  3271. else
  3272. {
  3273. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3274. 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++)
  3275. {
  3276. 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"));
  3277. 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?
  3278. 3:
  3279. 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")));
  3280. 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));
  3281. }
  3282. }
  3283. // Optional item
  3284. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3285. {
  3286. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3287. }
  3288. else
  3289. {
  3290. sprintf((char*)maxProfile.ValidFrom, " ");
  3291. }
  3292. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3293. {
  3294. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3295. }
  3296. else
  3297. {
  3298. sprintf((char*)maxProfile.ValidTo, " ");
  3299. }
  3300. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3301. {
  3302. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3303. }
  3304. else
  3305. {
  3306. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3307. }
  3308. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3309. {
  3310. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3311. }
  3312. else
  3313. {
  3314. maxProfile.TransactionId = -1;
  3315. }
  3316. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3317. {
  3318. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3319. }
  3320. else
  3321. {
  3322. maxProfile.ChargingSchedule.Duration = 86400;
  3323. }
  3324. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3325. {
  3326. 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")));
  3327. }
  3328. else
  3329. {
  3330. 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));
  3331. }
  3332. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3333. {
  3334. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3335. }
  3336. else
  3337. {
  3338. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3339. }
  3340. }
  3341. }
  3342. }
  3343. json_object_put(obj);
  3344. }
  3345. fclose(fp);
  3346. /*
  3347. if(maxProfile.ChargingProfileId !=-1)
  3348. {
  3349. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3350. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3351. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3352. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3353. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3354. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3355. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3356. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3357. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3358. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3359. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3360. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3361. {
  3362. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3363. {
  3364. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3365. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3366. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3367. }
  3368. }
  3369. }
  3370. else
  3371. DEBUG_INFO("MaxProfile not found.\n");
  3372. DEBUG_INFO("------------------------------------\n");*/
  3373. }
  3374. /*
  3375. * Align found profile start schedule & periods
  3376. */
  3377. //DEBUG_INFO("====================================\n");
  3378. /*
  3379. // For local test usage, force modify found profile start schedule info
  3380. 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);
  3381. 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);
  3382. 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);
  3383. */
  3384. if(txProfile.ChargingProfileId != -1)
  3385. {
  3386. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3387. {
  3388. if(txProfile.ChargingSchedule.Duration != -1)
  3389. {
  3390. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3391. 0:
  3392. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3393. }
  3394. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3395. {
  3396. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3397. {
  3398. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3399. 0:
  3400. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3401. if(idxPeriod > 0)
  3402. {
  3403. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3404. {
  3405. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3406. }
  3407. }
  3408. }
  3409. }
  3410. }
  3411. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3412. {
  3413. if(txProfile.ChargingSchedule.Duration != -1)
  3414. {
  3415. 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?
  3416. 0:
  3417. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3418. }
  3419. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3420. {
  3421. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3422. {
  3423. 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?
  3424. 0:
  3425. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3426. if(idxPeriod > 0)
  3427. {
  3428. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3429. {
  3430. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3431. }
  3432. }
  3433. }
  3434. }
  3435. }
  3436. else
  3437. {
  3438. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3439. {
  3440. if(txProfile.ChargingSchedule.Duration != -1)
  3441. {
  3442. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3443. 0:
  3444. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3445. }
  3446. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3447. {
  3448. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3449. {
  3450. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3451. 0:
  3452. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3453. if(idxPeriod > 0)
  3454. {
  3455. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3456. {
  3457. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3458. }
  3459. }
  3460. }
  3461. }
  3462. }
  3463. else
  3464. {
  3465. if(txProfile.ChargingSchedule.Duration != -1)
  3466. {
  3467. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3468. 0:
  3469. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3470. }
  3471. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3472. {
  3473. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3474. {
  3475. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3476. 0:
  3477. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3478. if(idxPeriod > 0)
  3479. {
  3480. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3481. {
  3482. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3483. }
  3484. }
  3485. }
  3486. }
  3487. }
  3488. }
  3489. /*
  3490. DEBUG_INFO("txProfile after align.\n");
  3491. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3492. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3493. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3494. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3495. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3496. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3497. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3498. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3499. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3500. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3501. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3502. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3503. {
  3504. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3505. {
  3506. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3507. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3508. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3509. }
  3510. }*/
  3511. }
  3512. if(defaultTxProfile.ChargingProfileId != -1)
  3513. {
  3514. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3515. {
  3516. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3517. {
  3518. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3519. 0:
  3520. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3521. }
  3522. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3523. {
  3524. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3525. {
  3526. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3527. 0:
  3528. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3529. if(idxPeriod > 0)
  3530. {
  3531. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3532. {
  3533. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3534. }
  3535. }
  3536. }
  3537. }
  3538. }
  3539. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3540. {
  3541. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3542. {
  3543. 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?
  3544. 0:
  3545. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3546. }
  3547. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3548. {
  3549. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3550. {
  3551. 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?
  3552. 0:
  3553. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3554. if(idxPeriod > 0)
  3555. {
  3556. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3557. {
  3558. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3559. }
  3560. }
  3561. }
  3562. }
  3563. }
  3564. else
  3565. {
  3566. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3567. {
  3568. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3569. {
  3570. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3571. 0:
  3572. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3573. }
  3574. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3575. {
  3576. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3577. {
  3578. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3579. 0:
  3580. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3581. if(idxPeriod > 0)
  3582. {
  3583. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3584. {
  3585. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3586. }
  3587. }
  3588. }
  3589. }
  3590. }
  3591. else
  3592. {
  3593. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3594. {
  3595. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3596. 0:
  3597. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3598. }
  3599. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3600. {
  3601. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3602. {
  3603. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3604. 0:
  3605. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3606. if(idxPeriod > 0)
  3607. {
  3608. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3609. {
  3610. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3611. }
  3612. }
  3613. }
  3614. }
  3615. }
  3616. }
  3617. /*
  3618. DEBUG_INFO("defaultTxProfile after align.\n");
  3619. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3620. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3621. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3622. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3623. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3624. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3625. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3626. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3627. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3628. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3629. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3630. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3631. {
  3632. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3633. {
  3634. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3635. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3636. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3637. }
  3638. }
  3639. DEBUG_INFO("------------------------------------\n");*/
  3640. }
  3641. if(maxProfile.ChargingProfileId != -1)
  3642. {
  3643. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3644. {
  3645. if(maxProfile.ChargingSchedule.Duration != -1)
  3646. {
  3647. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3648. 0:
  3649. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3650. }
  3651. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3652. {
  3653. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3654. {
  3655. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3656. 0:
  3657. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3658. if(idxPeriod > 0)
  3659. {
  3660. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3661. {
  3662. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3663. }
  3664. }
  3665. }
  3666. }
  3667. }
  3668. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3669. {
  3670. if(maxProfile.ChargingSchedule.Duration != -1)
  3671. {
  3672. 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?
  3673. 0:
  3674. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3675. }
  3676. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3677. {
  3678. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3679. {
  3680. 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?
  3681. 0:
  3682. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3683. if(idxPeriod > 0)
  3684. {
  3685. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3686. {
  3687. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3688. }
  3689. }
  3690. }
  3691. }
  3692. }
  3693. else
  3694. {
  3695. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3696. {
  3697. if(maxProfile.ChargingSchedule.Duration != -1)
  3698. {
  3699. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3700. 0:
  3701. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3702. }
  3703. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3704. {
  3705. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3706. {
  3707. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3708. 0:
  3709. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3710. if(idxPeriod > 0)
  3711. {
  3712. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3713. {
  3714. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3715. }
  3716. }
  3717. }
  3718. }
  3719. }
  3720. else
  3721. {
  3722. if(maxProfile.ChargingSchedule.Duration != -1)
  3723. {
  3724. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3725. 0:
  3726. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3727. }
  3728. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3729. {
  3730. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3731. {
  3732. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3733. 0:
  3734. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3735. if(idxPeriod > 0)
  3736. {
  3737. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3738. {
  3739. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3740. }
  3741. }
  3742. }
  3743. }
  3744. }
  3745. }
  3746. /*
  3747. DEBUG_INFO("MaxProfile after align.\n");
  3748. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3749. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3750. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3751. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3752. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3753. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3754. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3755. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3756. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3757. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3758. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3759. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3760. {
  3761. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3762. {
  3763. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3764. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3765. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3766. }
  3767. }
  3768. DEBUG_INFO("------------------------------------\n");*/
  3769. }
  3770. /*
  3771. * Merge to conposite schedule
  3772. */
  3773. //DEBUG_INFO("====================================\n");
  3774. // Find each profile period quantity
  3775. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3776. {
  3777. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3778. limitMax = idx+1;
  3779. }
  3780. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3781. {
  3782. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3783. limitDef = idx+1;
  3784. }
  3785. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3786. {
  3787. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3788. limitTx = idx+1;
  3789. }
  3790. // TxProfile found, composite schedule based on it
  3791. if(txProfile.ChargingProfileId != -1)
  3792. {
  3793. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3794. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3795. {
  3796. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3797. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3798. (txProfile.ChargingSchedule.Duration > 0))
  3799. {
  3800. if(maxProfile.ChargingProfileId != -1)
  3801. {
  3802. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3803. {
  3804. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3805. {
  3806. if((maxProfile.ChargingSchedule.Duration > 0))
  3807. {
  3808. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3809. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3810. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3811. }
  3812. else
  3813. {
  3814. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3815. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3816. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3817. }
  3818. }
  3819. if(idxMaxPeriod == (limitMax-1))
  3820. {
  3821. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3822. {
  3823. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3824. {
  3825. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3826. compositePeriodIdx++;
  3827. }
  3828. else
  3829. {
  3830. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3831. }
  3832. }
  3833. }
  3834. }
  3835. }
  3836. else
  3837. {
  3838. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3839. {
  3840. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3841. compositePeriodIdx++;
  3842. }
  3843. else
  3844. {
  3845. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3846. }
  3847. }
  3848. }
  3849. if(idxTxPeriod == (limitTx-1))
  3850. {
  3851. if(defaultTxProfile.ChargingProfileId != -1)
  3852. {
  3853. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3854. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3855. {
  3856. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3857. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3858. (defaultTxProfile.ChargingSchedule.Duration>0))
  3859. {
  3860. if(maxProfile.ChargingProfileId != -1)
  3861. {
  3862. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3863. {
  3864. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3865. {
  3866. if((maxProfile.ChargingSchedule.Duration > 0))
  3867. {
  3868. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3869. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3870. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3871. }
  3872. else
  3873. {
  3874. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3875. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3876. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3877. }
  3878. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3879. {
  3880. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3881. {
  3882. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3883. compositePeriodIdx++;
  3884. }
  3885. else
  3886. {
  3887. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3888. }
  3889. }
  3890. // Delete duplicate period
  3891. if(compositePeriodIdx > 1)
  3892. {
  3893. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3894. {
  3895. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3896. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3897. compositePeriodIdx -= 1;
  3898. }
  3899. }
  3900. }
  3901. else
  3902. {
  3903. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3904. {
  3905. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3906. compositePeriodIdx++;
  3907. }
  3908. else
  3909. {
  3910. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3911. }
  3912. break;
  3913. }
  3914. }
  3915. }
  3916. else
  3917. {
  3918. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3919. {
  3920. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3921. compositePeriodIdx++;
  3922. }
  3923. else
  3924. {
  3925. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3926. }
  3927. }
  3928. }
  3929. }
  3930. }
  3931. }
  3932. }
  3933. }
  3934. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3935. else if(defaultTxProfile.ChargingProfileId != -1)
  3936. {
  3937. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3938. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3939. {
  3940. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3941. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3942. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3943. {
  3944. if(maxProfile.ChargingProfileId != -1)
  3945. {
  3946. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3947. {
  3948. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3949. {
  3950. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3951. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3952. if((maxProfile.ChargingSchedule.Duration > 0))
  3953. {
  3954. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3955. }
  3956. else
  3957. {
  3958. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3959. }
  3960. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3961. {
  3962. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3963. {
  3964. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3965. compositePeriodIdx++;
  3966. }
  3967. else
  3968. {
  3969. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3970. }
  3971. }
  3972. // Delete duplicate period
  3973. if(compositePeriodIdx > 1)
  3974. {
  3975. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3976. {
  3977. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3978. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3979. compositePeriodIdx -= 1;
  3980. }
  3981. }
  3982. }
  3983. else
  3984. {
  3985. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3986. {
  3987. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3988. compositePeriodIdx++;
  3989. }
  3990. else
  3991. {
  3992. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3993. }
  3994. break;
  3995. }
  3996. }
  3997. }
  3998. else
  3999. {
  4000. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4001. {
  4002. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4003. compositePeriodIdx++;
  4004. }
  4005. else
  4006. {
  4007. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4008. }
  4009. }
  4010. }
  4011. }
  4012. }
  4013. // Fill other period by MaxProfile
  4014. if(maxProfile.ChargingProfileId != -1)
  4015. {
  4016. if(compositePeriodIdx==0)
  4017. {
  4018. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  4019. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  4020. {
  4021. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  4022. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  4023. (maxProfile.ChargingSchedule.Duration > 0))
  4024. {
  4025. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4026. {
  4027. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  4028. compositePeriodIdx++;
  4029. }
  4030. else
  4031. {
  4032. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  4033. }
  4034. }
  4035. }
  4036. }
  4037. else
  4038. {
  4039. int lastCompositePeriodIdx = compositePeriodIdx;
  4040. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4041. {
  4042. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  4043. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  4044. (maxProfile.ChargingSchedule.Duration > 0))
  4045. {
  4046. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  4047. {
  4048. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  4049. {
  4050. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  4051. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  4052. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  4053. }
  4054. else
  4055. {
  4056. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  4057. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  4058. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  4059. }
  4060. }
  4061. if(tmpPeriod.Limit != -1)
  4062. {
  4063. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  4064. {
  4065. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  4066. {
  4067. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4068. compositePeriodIdx++;
  4069. }
  4070. else
  4071. {
  4072. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4073. }
  4074. }
  4075. // Delete duplicate period
  4076. if(compositePeriodIdx > 1)
  4077. {
  4078. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4079. {
  4080. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4081. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4082. compositePeriodIdx -= 1;
  4083. }
  4084. }
  4085. }
  4086. }
  4087. }
  4088. }
  4089. }
  4090. compositeProfile.ChargingSchedule.Duration = durationReq;
  4091. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  4092. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  4093. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  4094. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  4095. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  4096. {
  4097. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4098. {
  4099. compositeProfile.ChargingProfileId = 1;
  4100. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4101. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  4102. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4103. }
  4104. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  4105. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  4106. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  4107. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  4108. }
  4109. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  4110. if(line)
  4111. free(line);
  4112. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  4113. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  4114. }
  4115. //==========================================
  4116. // Init all share memory
  4117. //==========================================
  4118. int InitShareMemory()
  4119. {
  4120. int result = PASS;
  4121. int MeterSMId;
  4122. //creat ShmSysConfigAndInfo
  4123. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  4124. {
  4125. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  4126. result = FAIL;
  4127. }
  4128. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4129. {
  4130. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  4131. result = FAIL;
  4132. }
  4133. else
  4134. {}
  4135. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  4136. {
  4137. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  4138. result = FAIL;
  4139. }
  4140. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4141. {
  4142. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  4143. result = FAIL;
  4144. }
  4145. else
  4146. {}
  4147. //creat ShmPsuData
  4148. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  4149. {
  4150. DEBUG_ERROR("shmget ShmPsuData NG\n");
  4151. result = FAIL;
  4152. }
  4153. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4154. {
  4155. DEBUG_ERROR("shmat ShmPsuData NG\n");
  4156. result = FAIL;
  4157. }
  4158. else
  4159. {}
  4160. //creat ShmOCPP16Data
  4161. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  4162. {
  4163. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  4164. result = FAIL;
  4165. }
  4166. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4167. {
  4168. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  4169. result = FAIL;
  4170. }
  4171. else
  4172. {}
  4173. /****************************** For Initial Settings************************************************/
  4174. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  4175. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  4176. // allocate Configuration memory address
  4177. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  4178. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  4179. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  4180. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  4181. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  4182. //offline MeterValue Interval
  4183. TempMeterValueInterval = 0;
  4184. return result;
  4185. }
  4186. int ProcessShareMemory()
  4187. {
  4188. int result = PASS;
  4189. if(InitShareMemory() == FAIL)
  4190. {
  4191. DEBUG_ERROR("InitShareMemory NG\n");
  4192. if(ShmStatusCodeData!=NULL)
  4193. {
  4194. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  4195. }
  4196. result = FAIL;
  4197. }
  4198. // Model name parsing
  4199. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  4200. {
  4201. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  4202. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  4203. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  4204. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  4205. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  4206. ) // 'D' means DC
  4207. {
  4208. // DO series
  4209. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  4210. {
  4211. gunTotalNumber += 1;
  4212. gunType[gun_index] = GUN_TYPE_DO;
  4213. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4214. {
  4215. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  4216. {
  4217. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4218. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4219. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  4220. }
  4221. }
  4222. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4223. {
  4224. case Gun_Type_Chademo:
  4225. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  4226. break;
  4227. case Gun_Type_CCS_2:
  4228. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  4229. break;
  4230. case Gun_Type_GB:
  4231. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  4232. break;
  4233. case Gun_Type_AC:
  4234. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  4235. break;
  4236. default:
  4237. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  4238. break;
  4239. }
  4240. }
  4241. }
  4242. else
  4243. {
  4244. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  4245. {
  4246. gunTotalNumber += 1;
  4247. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4248. {
  4249. case Gun_Type_Chademo:
  4250. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  4251. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  4252. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  4253. {
  4254. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4255. {
  4256. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4257. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4258. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4259. }
  4260. }
  4261. break;
  4262. case Gun_Type_CCS_2:
  4263. gunType[gun_index] = GUN_TYPE_CCS;
  4264. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4265. for (int index = 0; index < CCS_QUANTITY; index++)
  4266. {
  4267. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4268. {
  4269. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4270. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4271. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4272. }
  4273. }
  4274. break;
  4275. case Gun_Type_GB:
  4276. gunType[gun_index] = GUN_TYPE_GBT;
  4277. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4278. for (int index = 0; index < GB_QUANTITY; index++)
  4279. {
  4280. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4281. {
  4282. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4283. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4284. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4285. }
  4286. }
  4287. break;
  4288. case Gun_Type_AC:
  4289. gunType[gun_index] = GUN_TYPE_AC;
  4290. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4291. for (int index = 0; index < AC_QUANTITY; index++)
  4292. {
  4293. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4294. {
  4295. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4296. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4297. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4298. }
  4299. }
  4300. break;
  4301. default:
  4302. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4303. break;
  4304. }
  4305. }
  4306. }
  4307. }
  4308. else
  4309. {
  4310. DEBUG_ERROR("Model name parsing fail.\n");
  4311. result = FAIL;
  4312. }
  4313. if(result != PASS)sleep(5);
  4314. return result;
  4315. }
  4316. void checkRemoteStart(uint8_t connectorIdInt)
  4317. {
  4318. uint8_t tempIndex;
  4319. int result = PASS;
  4320. char cmdBuf[512];
  4321. //check Transaction active
  4322. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4323. {
  4324. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4325. {
  4326. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4327. }
  4328. else
  4329. {
  4330. tempIndex = connectorIdInt -1;
  4331. }
  4332. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4333. {
  4334. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4335. {
  4336. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4337. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4338. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4339. {
  4340. //Reserved
  4341. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4342. }
  4343. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4344. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4345. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4346. {
  4347. //Reserved
  4348. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4349. result = FAIL;
  4350. goto end;
  4351. }
  4352. else
  4353. {
  4354. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4355. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4356. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4357. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4358. {
  4359. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4360. result = FAIL;
  4361. goto end;
  4362. }
  4363. }//END FOR ELSE
  4364. }
  4365. }// END FOR CHAdeMO_QUANTITY
  4366. }
  4367. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4368. {
  4369. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4370. {
  4371. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4372. }
  4373. else
  4374. {
  4375. tempIndex = connectorIdInt -1;
  4376. }
  4377. for (int index = 0; index < CCS_QUANTITY; index++)
  4378. {
  4379. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4380. {
  4381. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4382. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4383. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4384. {
  4385. //Reserved
  4386. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4387. }
  4388. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4389. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4390. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4391. {
  4392. //Reserved
  4393. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4394. result = FAIL;
  4395. goto end;
  4396. }
  4397. else
  4398. {
  4399. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4400. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4401. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4402. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4403. {
  4404. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4405. result = FAIL;
  4406. goto end;
  4407. }
  4408. }// END FOR ELSE
  4409. }
  4410. }// END FOR CCS_QUANTITY
  4411. }
  4412. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4413. {
  4414. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4415. {
  4416. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4417. }
  4418. else
  4419. {
  4420. tempIndex = connectorIdInt -1;
  4421. }
  4422. for (int index = 0; index < GB_QUANTITY; index++)
  4423. {
  4424. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4425. {
  4426. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4427. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4428. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4429. {
  4430. //Reserved
  4431. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4432. }
  4433. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4434. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4435. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4436. {
  4437. //Reserved
  4438. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4439. result = FAIL;
  4440. goto end;
  4441. }
  4442. else
  4443. {
  4444. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4445. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4446. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4447. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4448. {
  4449. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4450. result = FAIL;
  4451. goto end;
  4452. }
  4453. }// END FOR ELSE
  4454. }
  4455. } // END FOR GB_QUANTITY
  4456. }
  4457. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4458. {
  4459. tempIndex = connectorIdInt -1;
  4460. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4461. {
  4462. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4463. {
  4464. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4465. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4466. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4467. {
  4468. //Reserved
  4469. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4470. }
  4471. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4472. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4473. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4474. {
  4475. //Reserved
  4476. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4477. result = FAIL;
  4478. goto end;
  4479. }
  4480. else
  4481. {
  4482. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4483. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4484. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4485. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4486. {
  4487. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4488. result = FAIL;
  4489. goto end;
  4490. }
  4491. }// END FOR ELSE
  4492. }
  4493. } // END FOR GB_QUANTITY
  4494. }
  4495. else
  4496. {
  4497. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4498. {
  4499. tempIndex = 2;
  4500. }
  4501. else
  4502. {
  4503. tempIndex = connectorIdInt -1;
  4504. }
  4505. for (int index = 0; index < AC_QUANTITY; index++)
  4506. {
  4507. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4508. {
  4509. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4510. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4511. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4512. {
  4513. //Reserved
  4514. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4515. }
  4516. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4517. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4518. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4519. {
  4520. //Reserved
  4521. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4522. result = FAIL;
  4523. goto end;
  4524. }
  4525. else
  4526. {
  4527. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4528. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4529. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4530. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4531. {
  4532. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4533. result = FAIL;
  4534. goto end;
  4535. }
  4536. }//END FOR ELSE
  4537. }
  4538. }// END FOR AC_QUANTITY
  4539. }
  4540. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4541. {
  4542. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4543. {
  4544. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4545. {
  4546. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4547. system(cmdBuf);
  4548. }
  4549. }
  4550. else
  4551. {
  4552. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4553. result = FAIL;
  4554. }
  4555. }
  4556. end:
  4557. if(result == PASS)
  4558. {
  4559. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4560. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4561. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4562. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4563. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4564. }
  4565. }
  4566. void CheckSystemValue(void)
  4567. {
  4568. char filenmae[100]={0};
  4569. char str[100]={0};
  4570. int tempIndex = 0;
  4571. //===============================
  4572. // send Heartbeat
  4573. //===============================
  4574. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4575. {
  4576. //parameter for test
  4577. sendHeartbeatRequest(0);
  4578. //===========================
  4579. // Reset Waiting Time
  4580. //===========================
  4581. HeartBeatWithNOResponse += 1;
  4582. }
  4583. //===============================
  4584. // Tcci credit deduct report
  4585. //===============================
  4586. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4587. {
  4588. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4589. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4590. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4591. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4592. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4593. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4594. }
  4595. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[0].DataTransferReq != TRUE) && getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4596. {
  4597. OCPP_query_deduct_info();
  4598. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4599. }
  4600. if(ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq)
  4601. {
  4602. OCPP_insert_occupancyDeduct_info((char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.occupancySN, (char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.creditNo,
  4603. ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.deductResult, ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.amount,
  4604. (char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.approvalNo);
  4605. ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq = FALSE;
  4606. }
  4607. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[0].DataTransferReq != TRUE) && getDiffSecNow(clientTime.TcciQueryOccupancyDeduct) > 5)
  4608. {
  4609. OCPP_query_occupancyDeduct_info();
  4610. refreshStartTimer(&clientTime.TcciQueryOccupancyDeduct);
  4611. }
  4612. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4613. {
  4614. // ClockAlign MeterValue
  4615. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4616. {
  4617. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4618. {
  4619. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4620. {
  4621. tempIndex = ((gun_index==2) ? 1: 0);
  4622. }
  4623. else
  4624. {
  4625. tempIndex = gun_index;
  4626. }
  4627. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4628. {
  4629. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4630. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4631. {
  4632. reqClockAlignMeter[gun_index] = 1;
  4633. }
  4634. }// End for CHAdeMO
  4635. }
  4636. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4637. {
  4638. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4639. {
  4640. tempIndex = ((gun_index==2) ? 1: 0);
  4641. }
  4642. else
  4643. {
  4644. tempIndex = gun_index;
  4645. }
  4646. for (int index = 0; index < CCS_QUANTITY; index++)
  4647. {
  4648. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4649. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4650. {
  4651. reqClockAlignMeter[gun_index] = 1;
  4652. }
  4653. } // End for CCS
  4654. }
  4655. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4656. {
  4657. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4658. {
  4659. tempIndex = ((gun_index==2) ? 1: 0);
  4660. }
  4661. else
  4662. {
  4663. tempIndex = gun_index;
  4664. }
  4665. for (int index = 0; index < GB_QUANTITY; index++)
  4666. {
  4667. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4668. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4669. {
  4670. reqClockAlignMeter[gun_index] = 1;
  4671. }
  4672. }// End for GB
  4673. }
  4674. else if(gunType[gun_index] == GUN_TYPE_DO)
  4675. {
  4676. tempIndex = gun_index;
  4677. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4678. {
  4679. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4680. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4681. {
  4682. reqClockAlignMeter[gun_index] = 1;
  4683. }
  4684. }
  4685. }
  4686. else
  4687. {
  4688. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4689. {
  4690. tempIndex = 2;
  4691. }
  4692. else
  4693. {
  4694. tempIndex = gun_index;
  4695. }
  4696. for (int index = 0; index < AC_QUANTITY; index++)
  4697. {
  4698. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4699. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4700. {
  4701. reqClockAlignMeter[gun_index] = 1;
  4702. }
  4703. }//End for AC
  4704. }
  4705. }
  4706. }
  4707. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4708. {
  4709. //==========================================
  4710. // Check remote start without connector id
  4711. //==========================================
  4712. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4713. {
  4714. int connectorIdInt = -1;
  4715. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4716. {
  4717. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4718. {
  4719. connectorIdInt = (gun_index+1);
  4720. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4721. checkRemoteStart(connectorIdInt);
  4722. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4723. break;
  4724. }
  4725. }
  4726. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4727. {
  4728. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4729. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4730. }
  4731. }
  4732. //==========================================
  4733. // csu trigger DataTransferReq
  4734. //==========================================
  4735. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4736. {
  4737. sendDataTransferRequest(gun_index);
  4738. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4739. }
  4740. //==========================================
  4741. // CSU Trigger Authorize Request
  4742. //==========================================
  4743. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4744. {
  4745. sendAuthorizeRequest(0);
  4746. authorizeRetryTimes = authorizeRetryTimes + 1;
  4747. if(authorizeRetryTimes < 3)
  4748. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4749. }
  4750. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4751. {
  4752. authorizeRetryTimes = 0;
  4753. SetOcppConnStatus(FALSE);
  4754. server_sign = FALSE;
  4755. }
  4756. 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))
  4757. {
  4758. sendAuthorizeRequest(0);
  4759. }
  4760. //==========================================
  4761. // Charger start transaction
  4762. //==========================================
  4763. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4764. {
  4765. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4766. sendStartTransactionRequest(gun_index);
  4767. refreshStartTimer(&clientTime.StartTransaction);
  4768. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4769. storeTempStopTransaction(gun_index);
  4770. }
  4771. //==========================================
  4772. // Charger stop transaction
  4773. //==========================================
  4774. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4775. {
  4776. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4777. sendStopTransactionRequest(gun_index);
  4778. OCPP_updatePeriodEnergy(gun_index);
  4779. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4780. refreshStartTimer(&clientTime.StopTransaction);
  4781. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4782. }
  4783. //==========================================
  4784. // Charger OCMF message
  4785. //==========================================
  4786. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq == 1)))
  4787. {
  4788. sendOcmfByDataTransferRequest(gun_index);
  4789. ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq = 0;
  4790. }
  4791. //==========================================
  4792. // Charger status report
  4793. //==========================================
  4794. //--- Check Mode Change ---//
  4795. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4796. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4797. {
  4798. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4799. {
  4800. tempIndex = ((gun_index==2) ? 1: 0);
  4801. }
  4802. else
  4803. {
  4804. tempIndex = gun_index;
  4805. }
  4806. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4807. {
  4808. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4809. {
  4810. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4811. {
  4812. // Sent unplug message for California pricing logic
  4813. 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])
  4814. {
  4815. uint8_t ts[36];
  4816. getNowDatetime(ts);
  4817. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4818. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4819. if(strcmp((char*)dmsVersion, "2.0")==0)
  4820. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4821. else
  4822. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4823. sendUnplugByDataTransferRequest(gun_index);
  4824. interLock.isSentUnplug[gun_index] = 1;
  4825. }
  4826. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4827. {
  4828. interLock.isSentUnplug[gun_index] = 0;
  4829. }
  4830. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4831. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4832. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4833. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4834. {
  4835. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4836. if((access(filenmae,F_OK))!=-1)
  4837. {
  4838. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4839. sprintf(str,"rm -f %s",filenmae);
  4840. system(str);
  4841. }
  4842. }
  4843. }
  4844. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4845. #if 1 // for TempStopTransaction
  4846. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4847. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4848. {
  4849. checkTempStopTransaction(gun_index);
  4850. }
  4851. #endif
  4852. }
  4853. }
  4854. }
  4855. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4856. {
  4857. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4858. {
  4859. tempIndex = ((gun_index==2) ? 1: 0);
  4860. }
  4861. else
  4862. {
  4863. tempIndex = gun_index;
  4864. }
  4865. for (int index = 0; index < CCS_QUANTITY; index++)
  4866. {
  4867. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4868. {
  4869. 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]*/ )
  4870. {
  4871. // Sent unplug message for California pricing logic
  4872. 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])
  4873. {
  4874. uint8_t ts[36];
  4875. getNowDatetime(ts);
  4876. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4877. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4878. if(strcmp((char*)dmsVersion, "2.0")==0)
  4879. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4880. else
  4881. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4882. sendUnplugByDataTransferRequest(gun_index);
  4883. interLock.isSentUnplug[gun_index] = 1;
  4884. }
  4885. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4886. {
  4887. interLock.isSentUnplug[gun_index] = 0;
  4888. }
  4889. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4890. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4891. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4892. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4893. {
  4894. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4895. if((access(filenmae,F_OK))!=-1)
  4896. {
  4897. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4898. sprintf(str,"rm -f %s",filenmae);
  4899. system(str);
  4900. }
  4901. }
  4902. }
  4903. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4904. #if 1 // for TempStopTransaction
  4905. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4906. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4907. {
  4908. checkTempStopTransaction(gun_index);
  4909. }
  4910. #endif
  4911. }
  4912. }
  4913. }
  4914. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4915. {
  4916. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4917. {
  4918. tempIndex = ((gun_index==2) ? 1: 0);
  4919. }
  4920. else
  4921. {
  4922. tempIndex = gun_index;
  4923. }
  4924. for (int index = 0; index < GB_QUANTITY; index++)
  4925. {
  4926. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4927. {
  4928. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4929. {
  4930. // Sent unplug message for California pricing logic
  4931. 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])
  4932. {
  4933. uint8_t ts[36];
  4934. getNowDatetime(ts);
  4935. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4936. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4937. if(strcmp((char*)dmsVersion, "2.0")==0)
  4938. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4939. else
  4940. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4941. sendUnplugByDataTransferRequest(gun_index);
  4942. interLock.isSentUnplug[gun_index] = 1;
  4943. }
  4944. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4945. {
  4946. interLock.isSentUnplug[gun_index] = 0;
  4947. }
  4948. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4949. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4950. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4951. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4952. {
  4953. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4954. if((access(filenmae,F_OK))!=-1)
  4955. {
  4956. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4957. sprintf(str,"rm -f %s",filenmae);
  4958. system(str);
  4959. }
  4960. }
  4961. }
  4962. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4963. #if 1 // for TempStopTransaction
  4964. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4965. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4966. {
  4967. checkTempStopTransaction(gun_index);
  4968. }
  4969. #endif
  4970. }
  4971. }
  4972. }
  4973. else if(gunType[gun_index] == GUN_TYPE_DO)
  4974. {
  4975. tempIndex = gun_index;
  4976. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4977. {
  4978. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4979. {
  4980. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4981. {
  4982. // Sent unplug message for California pricing logic
  4983. 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])
  4984. {
  4985. uint8_t ts[36];
  4986. getNowDatetime(ts);
  4987. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4988. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4989. if(strcmp((char*)dmsVersion, "2.0")==0)
  4990. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4991. else
  4992. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4993. sendUnplugByDataTransferRequest(gun_index);
  4994. interLock.isSentUnplug[gun_index] = 1;
  4995. }
  4996. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4997. {
  4998. interLock.isSentUnplug[gun_index] = 0;
  4999. }
  5000. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  5001. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  5002. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5003. 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
  5004. {
  5005. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5006. if((access(filenmae,F_OK))!=-1)
  5007. {
  5008. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5009. sprintf(str,"rm -f %s",filenmae);
  5010. system(str);
  5011. }
  5012. }
  5013. }
  5014. 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);
  5015. #if 1 // for TempStopTransaction
  5016. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  5017. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5018. {
  5019. checkTempStopTransaction(gun_index);
  5020. }
  5021. #endif
  5022. }
  5023. }
  5024. }
  5025. else
  5026. {
  5027. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5028. {
  5029. tempIndex = 2;
  5030. }
  5031. else
  5032. {
  5033. tempIndex = gun_index;
  5034. }
  5035. for (int index = 0; index < AC_QUANTITY; index++)
  5036. {
  5037. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5038. {
  5039. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  5040. {
  5041. // Sent unplug message for California pricing logic
  5042. 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])
  5043. {
  5044. uint8_t ts[36];
  5045. getNowDatetime(ts);
  5046. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5047. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5048. if(strcmp((char*)dmsVersion, "2.0")==0)
  5049. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5050. else
  5051. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5052. sendUnplugByDataTransferRequest(gun_index);
  5053. interLock.isSentUnplug[gun_index] = 1;
  5054. }
  5055. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5056. {
  5057. interLock.isSentUnplug[gun_index] = 0;
  5058. }
  5059. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  5060. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  5061. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5062. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5063. {
  5064. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5065. if((access(filenmae,F_OK))!=-1)
  5066. {
  5067. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5068. sprintf(str,"rm -f %s",filenmae);
  5069. system(str);
  5070. }
  5071. }
  5072. }
  5073. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5074. #if 1 // for TempStopTransaction
  5075. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5076. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5077. {
  5078. checkTempStopTransaction(gun_index);
  5079. }
  5080. #endif
  5081. }
  5082. }// END
  5083. }
  5084. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf != 1) &&
  5085. (
  5086. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  5087. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  5088. )
  5089. )
  5090. {
  5091. sendStatusNotificationRequest(gun_index);
  5092. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  5093. }
  5094. //==============================================
  5095. // TCCI related DataTransfer messages
  5096. //==============================================
  5097. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  5098. {
  5099. reportReaderStatus(gun_index);
  5100. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  5101. }
  5102. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.GetOccupancyFee[gun_index].GetOccupancyFeeReq == 1))
  5103. {
  5104. getOccupancyFee(gun_index);
  5105. }
  5106. //==============================================
  5107. // CSU Trigger or timer timeout refresh Smart Charging Profile
  5108. //==============================================
  5109. if((ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  5110. ((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))))
  5111. {
  5112. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  5113. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  5114. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  5115. }
  5116. //==============================================
  5117. // Meter report
  5118. //==============================================
  5119. // Trigger MeterValue
  5120. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  5121. {
  5122. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  5123. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  5124. }
  5125. // Clock-aligned Meter value
  5126. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  5127. {
  5128. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  5129. reqClockAlignMeter[gun_index] = 0;
  5130. }
  5131. // Sample period MeterValue
  5132. 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))))
  5133. {
  5134. //check Transaction active
  5135. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5136. {
  5137. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5138. {
  5139. tempIndex = ((gun_index==2) ? 1: 0);
  5140. }
  5141. else
  5142. {
  5143. tempIndex = gun_index;
  5144. }
  5145. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5146. {
  5147. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5148. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5149. {
  5150. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5151. {
  5152. reqSampleMeter[gun_index] = 1;
  5153. }
  5154. }
  5155. }// End for CHAdeMO
  5156. }
  5157. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5158. {
  5159. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5160. {
  5161. tempIndex = ((gun_index==2) ? 1: 0);
  5162. }
  5163. else
  5164. {
  5165. tempIndex = gun_index;
  5166. }
  5167. for (int index = 0; index < CCS_QUANTITY; index++)
  5168. {
  5169. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5170. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5171. {
  5172. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5173. {
  5174. reqSampleMeter[gun_index] = 1;
  5175. }
  5176. }
  5177. } // End for CCS
  5178. }
  5179. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5180. {
  5181. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5182. {
  5183. tempIndex = ((gun_index==2) ? 1: 0);
  5184. }
  5185. else
  5186. {
  5187. tempIndex = gun_index;
  5188. }
  5189. for (int index = 0; index < GB_QUANTITY; index++)
  5190. {
  5191. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5192. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5193. {
  5194. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5195. {
  5196. reqSampleMeter[gun_index] = 1;
  5197. }
  5198. }
  5199. }// End for GB
  5200. }
  5201. else if(gunType[gun_index] == GUN_TYPE_DO)
  5202. {
  5203. tempIndex = gun_index;
  5204. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5205. {
  5206. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5207. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5208. {
  5209. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  5210. {
  5211. reqSampleMeter[gun_index] = 1;
  5212. }
  5213. }
  5214. }
  5215. }
  5216. else
  5217. {
  5218. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5219. {
  5220. tempIndex = 2;
  5221. }
  5222. else
  5223. {
  5224. tempIndex = gun_index;
  5225. }
  5226. for (int index = 0; index < AC_QUANTITY; index++)
  5227. {
  5228. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5229. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5230. {
  5231. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  5232. {
  5233. reqSampleMeter[gun_index] = 1;
  5234. }
  5235. }
  5236. }//End for AC
  5237. }
  5238. if(reqSampleMeter[gun_index] == 1)
  5239. {
  5240. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  5241. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  5242. storeTempStopTransaction(gun_index);
  5243. reqSampleMeter[gun_index] = 0;
  5244. }
  5245. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5246. }
  5247. //==============================================
  5248. // Check Connector reserved
  5249. //==============================================
  5250. //===============================
  5251. // Check if Reserve is expired
  5252. //===============================
  5253. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  5254. {
  5255. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  5256. {
  5257. DEBUG_INFO("reserve expired.\n");
  5258. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  5259. }
  5260. }//END OF Check if Reserve is expired
  5261. //==========================================
  5262. // csu trigger FirmwareStatusNotificationReq
  5263. //==========================================
  5264. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  5265. {
  5266. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  5267. }
  5268. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq == 1))
  5269. {
  5270. sendSignedFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status);
  5271. }
  5272. //==========================================
  5273. // csu trigger DiagnosticsStatusNotificationReq
  5274. //==========================================
  5275. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  5276. {
  5277. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  5278. }
  5279. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq == 1))
  5280. {
  5281. sendLogStatusNotificationRequest((char *)ShmOCPP16Data->LogStatusNotification.status);
  5282. }
  5283. //==========================================
  5284. // csu trigger CancelReservationConf
  5285. //==========================================
  5286. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  5287. {
  5288. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  5289. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  5290. }
  5291. //==========================================
  5292. // csu trigger ChangeAvailabilityConf
  5293. //==========================================
  5294. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  5295. {
  5296. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  5297. }
  5298. //==========================================
  5299. // csu trigger UnlockConnectorConf
  5300. //==========================================
  5301. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  5302. {
  5303. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5304. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5305. }
  5306. //==========================================
  5307. // csu trigger ReserveNowConf
  5308. //==========================================
  5309. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5310. {
  5311. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5312. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5313. }
  5314. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access(CSR_CP,F_OK) != -1))
  5315. {
  5316. sendSignCertificateRequest();
  5317. }
  5318. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq == 1))
  5319. {
  5320. sendSecurityEventNotificationRequest();
  5321. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5322. }
  5323. // Support 15118
  5324. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.SignCertificateReq == 1) && (access(CSR_V2G,F_OK) != -1))
  5325. {
  5326. json_object *data = json_object_new_object();
  5327. // Read csr file content
  5328. memset(ShmOCPP16Data->v2g_extend.SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5329. FILE *fp=fopen(CSR_V2G,"r");
  5330. char *line = NULL;
  5331. size_t len = 0;
  5332. while(getline(&line, &len, fp) != -1)
  5333. {
  5334. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5335. {
  5336. memcpy(&ShmOCPP16Data->v2g_extend.SignCertificate.csr[strlen((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr)], line, (strlen(line)-1));
  5337. }
  5338. }
  5339. fclose(fp);
  5340. json_object_object_add(data, "csr", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5341. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5342. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"SignCertificate");
  5343. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5344. json_object_put(data);
  5345. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5346. ShmOCPP16Data->v2g_extend.SignCertificateReq = 0;
  5347. }
  5348. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.AuthorizeReq == 1))
  5349. {
  5350. memset(&ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo,0,sizeof(struct IdTokenInfoType));
  5351. int parseCertResult = FAIL;
  5352. json_object *data = json_object_new_object();
  5353. json_object *idToken = json_object_new_object();
  5354. json_object *iso15118CertificateHashData = json_object_new_array();
  5355. // Read CERTIFICATE_PnCAuth file content
  5356. if(access(CERTIFICATE_PnCAuth,F_OK) != -1)
  5357. {
  5358. memset(ShmOCPP16Data->v2g_extend.Authorize.certificate, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5359. FILE *fp=fopen(CERTIFICATE_PnCAuth,"r");
  5360. char *line = NULL;
  5361. size_t len = 0;
  5362. while(getline(&line, &len, fp) != -1)
  5363. {
  5364. //memcpy(&ShmOCPP16Data->v2g_extend.Authorize.certificate[strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate)], line, (strlen(line)-1));
  5365. strcat((char *)ShmOCPP16Data->v2g_extend.Authorize.certificate, line);
  5366. }
  5367. fclose(fp);
  5368. }
  5369. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate) > 0)
  5370. json_object_object_add(data, "certificate", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5371. //strcpy((char *)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5372. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken));
  5373. json_object_object_add(data, "idToken", idToken);
  5374. char parseData[512] = {0};
  5375. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  5376. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].hashAlgorithm, parseData);
  5377. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_SerialNumber, parseData) == PASS)
  5378. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].serialNumber, parseData);
  5379. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  5380. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerNameHash, parseData);
  5381. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  5382. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerKeyHash, parseData);
  5383. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_OcspUrl, parseData) == PASS && strlen((char*)parseData) >= 7)
  5384. strcpy((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].responderURL, parseData);
  5385. for(int idx=0; idx < 4; idx++)
  5386. {
  5387. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm) > 0)
  5388. {
  5389. json_object *OCSPRequestDataType = json_object_new_object();
  5390. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm));
  5391. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerNameHash));
  5392. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerKeyHash));
  5393. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].serialNumber));
  5394. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].responderURL));
  5395. json_object_array_add(iso15118CertificateHashData, OCSPRequestDataType);
  5396. parseCertResult = PASS;
  5397. }
  5398. }
  5399. if(parseCertResult == PASS)
  5400. {
  5401. json_object_object_add(data, "iso15118CertificateHashData", iso15118CertificateHashData);
  5402. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5403. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Authorize");
  5404. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5405. json_object_put(data);
  5406. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5407. ShmOCPP16Data->v2g_extend.AuthorizeReq = 0;
  5408. }
  5409. else
  5410. {
  5411. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "NoCertificateAvailable");
  5412. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.status, "Invalid");
  5413. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  5414. }
  5415. }
  5416. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq == 1))
  5417. {
  5418. json_object *data = json_object_new_object();
  5419. json_object_object_add(data, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.iso15118SchemaVersion));
  5420. json_object_object_add(data, "action", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.action));
  5421. json_object_object_add(data, "exiRequest", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.exiRequest));
  5422. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5423. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Get15118EVCertificate");
  5424. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5425. json_object_put(data);
  5426. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5427. ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq = 0;
  5428. }
  5429. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.GetCertificateStatusReq == 1))
  5430. {
  5431. json_object *data = json_object_new_object();
  5432. json_object *OCSPRequestDataType = json_object_new_object();
  5433. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.hashAlgorithm));
  5434. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerNameHash));
  5435. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerKeyHash));
  5436. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.serialNumber));
  5437. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.responderURL));
  5438. json_object_object_add(data, "ocspRequestData", OCSPRequestDataType);
  5439. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5440. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"GetInstalledCertificateIds");
  5441. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5442. json_object_put(data);
  5443. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5444. ShmOCPP16Data->v2g_extend.GetCertificateStatusReq = 0;
  5445. }
  5446. }
  5447. }
  5448. //==========================================
  5449. // send request routine
  5450. //==========================================
  5451. int sendAuthorizeRequest(int gun_index)
  5452. {
  5453. mtrace();
  5454. int result = FAIL;
  5455. char message[100]={0};
  5456. char guid[37];
  5457. char tempdata[65]={0};
  5458. DEBUG_INFO("sendAuthorizeRequest...\n");
  5459. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5460. //Local Authorize
  5461. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5462. {
  5463. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5464. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5465. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5466. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5467. result = PASS;
  5468. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5469. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5470. authorizeRetryTimes = 0;
  5471. return result;
  5472. }
  5473. 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))||
  5474. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5475. {
  5476. // Query from cache
  5477. DEBUG_INFO("Authorize from cache.\n");
  5478. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5479. // Query from list
  5480. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5481. {
  5482. DEBUG_INFO("Authorize from list.\n");
  5483. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5484. }
  5485. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5486. {
  5487. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5488. {
  5489. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5490. }
  5491. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5492. {
  5493. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5494. }
  5495. if(!GetOcppConnStatus())
  5496. {
  5497. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5498. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5499. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5500. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5501. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5502. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5503. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5504. authorizeRetryTimes = 0;
  5505. return result;
  5506. }
  5507. }
  5508. else
  5509. {
  5510. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5511. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5512. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5513. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5514. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5515. else
  5516. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5517. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5518. result = PASS;
  5519. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5520. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5521. authorizeRetryTimes = 0;
  5522. return result;
  5523. }
  5524. }
  5525. //initialize struct Authorize
  5526. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5527. //get data from shared memory
  5528. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5529. random_uuid(guid);
  5530. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5531. LWS_Send(message);
  5532. sprintf(tempdata, "Authorize,%d", gun_index);
  5533. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5534. {
  5535. result = PASS;
  5536. DEBUG_INFO("Authorize mapItem pass\n");
  5537. }
  5538. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5539. return result;
  5540. }
  5541. int sendBootNotificationRequest(void)
  5542. {
  5543. mtrace();
  5544. int result = FAIL;
  5545. char message[500]={0}, payload[700]={0};
  5546. char guid[37]={0};
  5547. char tempdata[65]={0};
  5548. // Fill BootNotification fields
  5549. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5550. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5551. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5552. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5553. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5554. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5555. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5556. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5557. ShmOCPP16Data->ChargeBoxId
  5558. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5559. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5560. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5561. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5562. ,ShmOCPP16Data->BootNotification.CpIccid
  5563. ,ShmOCPP16Data->BootNotification.CpImsi);
  5564. random_uuid(guid);
  5565. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5566. LWS_Send(message);
  5567. sprintf(tempdata, "BootNotification,0");
  5568. 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*/)
  5569. {
  5570. result = PASS;
  5571. }
  5572. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5573. strcpy(queuedata,message);
  5574. return result;
  5575. }
  5576. int sendDataTransferRequest(int gun_index)
  5577. {
  5578. mtrace();
  5579. char message[10240]={0};
  5580. char guid[37]={0};
  5581. char tempdata[65]={0};
  5582. int result = FAIL;
  5583. json_object *DataTransfer = json_object_new_object();
  5584. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5585. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5586. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].Data));
  5587. random_uuid(guid);
  5588. sprintf(message,"[%d,\"%s\",\"DataTransfer\",%s]", MESSAGE_TYPE_CALL,
  5589. guid,
  5590. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5591. json_object_put(DataTransfer);
  5592. LWS_Send(message);
  5593. sprintf(tempdata, "DataTransfer,%d", gun_index);
  5594. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5595. {
  5596. result = PASS;
  5597. DEBUG_INFO("DataTransfer mapItem pass\n");
  5598. }
  5599. return result;
  5600. }
  5601. int sendUnplugByDataTransferRequest(int gun_index)
  5602. {
  5603. mtrace();
  5604. char message[10752]={0};
  5605. char guid[37]={0};
  5606. char tempdata[65]={0};
  5607. int result = FAIL;
  5608. random_uuid(guid);
  5609. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5610. (gun_index+1),
  5611. MESSAGE_TYPE_CALL,
  5612. guid,
  5613. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5614. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5615. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5616. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5617. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5618. {
  5619. result = PASS;
  5620. DEBUG_INFO("DataTransfer mapItem pass\n");
  5621. }
  5622. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5623. return result;
  5624. }
  5625. int sendOcmfByDataTransferRequest(int gun_index)
  5626. {
  5627. mtrace();
  5628. json_object *DataTransfer = json_object_new_object();
  5629. json_object *data = json_object_new_object();
  5630. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5631. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ID_OCMF");
  5632. json_object_object_add(data, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  5633. json_object_object_add(data, "dataString", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].DataString));
  5634. json_object_object_add(data, "publicKey", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].PublicKey));
  5635. json_object_object_add(DataTransfer, "data", data);
  5636. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5637. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5638. char message[3000]={0};
  5639. char guid[37]={0};
  5640. char tempdata[65]={0};
  5641. int result = FAIL;
  5642. random_uuid(guid);
  5643. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",%s]",
  5644. (gun_index+1),
  5645. MESSAGE_TYPE_CALL,
  5646. guid,
  5647. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5648. json_object_put(DataTransfer);
  5649. sprintf(tempdata, "DataTransfer,%d", gun_index );
  5650. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5651. {
  5652. result = PASS;
  5653. DEBUG_INFO("DataTransfer mapItem pass\n");
  5654. }
  5655. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5656. return result;
  5657. }
  5658. int sendDiagnosticsStatusNotificationRequest(char *status)
  5659. {
  5660. mtrace();
  5661. int result = FAIL;
  5662. char message[110]={0};
  5663. char guid[37]={0};
  5664. char tempdata[65]={0};
  5665. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5666. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5667. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5668. random_uuid(guid);
  5669. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5670. LWS_SendNow(message);
  5671. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5672. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5673. {
  5674. result = PASS;
  5675. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5676. }
  5677. //#ifdef SystemLogMessage
  5678. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5679. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5680. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5681. //#endif
  5682. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5683. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5684. //record status
  5685. if(strcmp(status,"Idle")==0)
  5686. {
  5687. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5688. }
  5689. else if(strcmp(status,"Uploaded")==0)
  5690. {
  5691. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5692. }
  5693. else if(strcmp(status,"UploadFailed")==0)
  5694. {
  5695. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5696. }
  5697. else if(strcmp(status,"Uploading")==0)
  5698. {
  5699. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5700. }
  5701. return result;
  5702. }
  5703. int sendFirmwareStatusNotificationRequest(char *status)
  5704. {
  5705. mtrace();
  5706. int result = FAIL;
  5707. char message[110]={0};
  5708. char guid[37]={0};
  5709. char tempdata[65]={0};
  5710. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5711. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5712. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5713. random_uuid(guid);
  5714. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5715. LWS_SendNow(message);
  5716. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5717. 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*/)
  5718. {
  5719. result = PASS;
  5720. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5721. }
  5722. //#ifdef SystemLogMessage
  5723. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5724. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5725. //#endif
  5726. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5727. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5728. //record status
  5729. if(strcmp(status,"Downloaded")==0)
  5730. {
  5731. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  5732. }
  5733. else if(strcmp(status,"DownloadFailed")==0)
  5734. {
  5735. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  5736. }
  5737. else if(strcmp(status,"Downloading")==0)
  5738. {
  5739. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  5740. }
  5741. else if(strcmp(status,"Idle")==0)
  5742. {
  5743. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  5744. }
  5745. else if(strcmp(status,"InstallationFailed")==0)
  5746. {
  5747. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  5748. }
  5749. else if(strcmp(status,"Installing")==0)
  5750. {
  5751. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  5752. }
  5753. else if(strcmp(status,"Installed")==0)
  5754. {
  5755. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  5756. }
  5757. return result;
  5758. }
  5759. int sendHeartbeatRequest(int gun_index)
  5760. {
  5761. mtrace();
  5762. int result = FAIL;
  5763. char message[80]={0};
  5764. char guid[37]={0};
  5765. char tempdata[65]={0};
  5766. random_uuid(guid);
  5767. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  5768. , MESSAGE_TYPE_CALL
  5769. , guid );
  5770. LWS_Send(message);
  5771. sprintf(tempdata, "Heartbeat,%d", 0);
  5772. 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*/)
  5773. {
  5774. result = PASS;
  5775. }
  5776. return result;
  5777. }
  5778. int sendStartTransactionRequest(int gun_index)
  5779. {
  5780. mtrace();
  5781. int result = FAIL;
  5782. char message[250]={0};
  5783. char guid[37]={0};
  5784. struct timeval tmnow;
  5785. struct tm *tm;
  5786. char buf[28];//, usec_buf[6];
  5787. char tempdata[65]={0};
  5788. int tempIndex = 0;
  5789. DEBUG_INFO("sendStartTransactionRequest...\n");
  5790. gettimeofday(&tmnow, NULL);
  5791. time_t t;
  5792. t = time(NULL);
  5793. /*UTC time and date*/
  5794. tm = gmtime(&t);
  5795. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5796. #if 0 // remove temporally
  5797. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5798. strcat(buf,".");
  5799. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5800. strcat(buf,usec_buf);
  5801. #endif
  5802. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  5803. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  5804. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5805. // clear StartTransaction Response
  5806. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  5807. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  5808. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  5809. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  5810. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5811. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5812. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5813. {
  5814. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5815. {
  5816. tempIndex = ((gun_index==2) ? 1: 0);
  5817. }
  5818. else
  5819. {
  5820. tempIndex = gun_index;
  5821. }
  5822. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5823. {
  5824. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5825. {
  5826. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5827. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  5828. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5829. }
  5830. }
  5831. }
  5832. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5833. {
  5834. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5835. {
  5836. tempIndex = ((gun_index==2) ? 1: 0);
  5837. }
  5838. else
  5839. {
  5840. tempIndex = gun_index;
  5841. }
  5842. for (int index = 0; index < CCS_QUANTITY; index++)
  5843. {
  5844. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5845. {
  5846. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5847. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5848. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5849. }
  5850. }
  5851. }
  5852. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5853. {
  5854. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5855. {
  5856. tempIndex = ((gun_index==2) ? 1: 0);
  5857. }
  5858. else
  5859. {
  5860. tempIndex = gun_index;
  5861. }
  5862. for (int index = 0; index < GB_QUANTITY; index++)
  5863. {
  5864. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5865. {
  5866. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5867. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5868. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5869. }
  5870. }
  5871. }
  5872. else if(gunType[gun_index] == GUN_TYPE_DO)
  5873. {
  5874. tempIndex = gun_index;
  5875. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5876. {
  5877. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5878. {
  5879. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5880. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5881. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5882. }
  5883. }
  5884. }
  5885. else
  5886. {
  5887. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5888. {
  5889. tempIndex = 2;
  5890. }
  5891. else
  5892. {
  5893. tempIndex = gun_index;
  5894. }
  5895. for (int index = 0; index < AC_QUANTITY; index++)
  5896. {
  5897. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5898. {
  5899. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5900. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5901. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5902. }
  5903. }
  5904. }
  5905. random_uuid(guid);
  5906. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5907. {
  5908. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5909. , gun_index +1
  5910. , MESSAGE_TYPE_CALL
  5911. , guid
  5912. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5913. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5914. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5915. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5916. }
  5917. else
  5918. {
  5919. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5920. , gun_index +1
  5921. , MESSAGE_TYPE_CALL
  5922. , guid
  5923. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5924. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5925. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5926. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5927. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5928. }
  5929. #if 1
  5930. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5931. 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*/)
  5932. {
  5933. result = PASS;
  5934. }
  5935. #endif
  5936. strcpy(queuedata, message);
  5937. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5938. OCPP_insert_transaction_msg(YES, queuedata);
  5939. return result;
  5940. }
  5941. int sendStatusNotificationRequest(int gun_index)
  5942. {
  5943. mtrace();
  5944. int result = FAIL;
  5945. char message[600]={0};
  5946. char guid[37];
  5947. int currentStatus = 0;
  5948. struct timeval tmnow;
  5949. struct tm *tm;
  5950. char buf[28];//, usec_buf[6];
  5951. char tempdata[65]={0};
  5952. int tempIndex = 0;
  5953. uint8_t isStateChanged = TRUE;
  5954. uint8_t isContentIllegal = TRUE;
  5955. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5956. gettimeofday(&tmnow, NULL);
  5957. time_t t;
  5958. t = time(NULL);
  5959. /*UTC time and date*/
  5960. tm = gmtime(&t);
  5961. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5962. #if 0 // remove temporally
  5963. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5964. strcat(buf,".");
  5965. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5966. strcat(buf,usec_buf);
  5967. #endif
  5968. //printf("%s",buf);
  5969. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5970. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5971. // it's option
  5972. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5973. /*
  5974. enum _SYSTEM_STATUS
  5975. {
  5976. S_BOOTING = 0,
  5977. S_IDLE, = 1
  5978. S_AUTHORIZING, =2
  5979. S_REASSIGN_CHECK, =3
  5980. S_REASSIGN, =4
  5981. S_PRECHARGE, =5
  5982. S_PREPARING_FOR_EV, =6
  5983. S_PREPARING_FOR_EVSE, =7
  5984. S_CHARGING, =8
  5985. S_TERMINATING, =9
  5986. S_COMPLETE, =10
  5987. S_ALARM, =11
  5988. S_FAULT =12
  5989. }
  5990. */
  5991. //check Transaction active
  5992. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5993. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5994. {
  5995. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5996. {
  5997. tempIndex = ((gun_index==2) ? 1: 0);
  5998. }
  5999. else
  6000. {
  6001. tempIndex = gun_index;
  6002. }
  6003. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6004. {
  6005. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  6006. {
  6007. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  6008. {
  6009. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6010. {
  6011. currentStatus = Preparing; //OCPP Status: Preparing
  6012. }
  6013. else
  6014. {
  6015. currentStatus = Available; //OCPP Status: Available
  6016. }
  6017. }
  6018. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6019. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6020. ) //S_PRECHARGE
  6021. {
  6022. currentStatus = Preparing; //OCPP Status: Preparing
  6023. }
  6024. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6025. {
  6026. currentStatus = Charging; //OCPP Status: Charging
  6027. }
  6028. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6029. {
  6030. currentStatus = Finishing; //OCPP Status: Finishing
  6031. }
  6032. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6033. {
  6034. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6035. }
  6036. 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
  6037. {
  6038. currentStatus = Unavailable; //OCPP Status: Unavailable
  6039. }
  6040. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6041. {
  6042. currentStatus = Faulted; //OCPP Status: Faulted
  6043. }
  6044. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6045. {
  6046. currentStatus = Reserved; //OCPP Status: Reserved
  6047. }
  6048. } //end of the same index
  6049. }//end of for CHAdeMO_QUANTITY
  6050. }
  6051. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6052. {
  6053. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6054. {
  6055. tempIndex = ((gun_index==2) ? 1: 0);
  6056. }
  6057. else
  6058. {
  6059. tempIndex = gun_index;
  6060. }
  6061. for (int index = 0; index < CCS_QUANTITY; index++)
  6062. {
  6063. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6064. {
  6065. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6066. {
  6067. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  6068. {
  6069. currentStatus = Preparing; //OCPP Status: Preparing
  6070. }
  6071. else
  6072. {
  6073. currentStatus = Available; //OCPP Status: Available
  6074. }
  6075. }
  6076. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6077. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6078. ) //S_PRECHARGE
  6079. {
  6080. currentStatus = Preparing; //OCPP Status: Preparing
  6081. }
  6082. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6083. {
  6084. currentStatus = Charging; //OCPP Status: Charging
  6085. }
  6086. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6087. {
  6088. currentStatus = Finishing; //OCPP Status: Finishing
  6089. }
  6090. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  6091. {
  6092. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6093. }
  6094. 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
  6095. {
  6096. currentStatus = Unavailable; //OCPP Status : Unavailable
  6097. }
  6098. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6099. {
  6100. currentStatus = Faulted; //OCPP Status: Faulted
  6101. }
  6102. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6103. {
  6104. currentStatus = Reserved; //OCPP Status: Reserved
  6105. }
  6106. } //end of the same index
  6107. } // end of for CCS_QUANTITY
  6108. }
  6109. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6110. {
  6111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6112. {
  6113. tempIndex = ((gun_index==2) ? 1: 0);
  6114. }
  6115. else
  6116. {
  6117. tempIndex = gun_index;
  6118. }
  6119. for (int index = 0; index < GB_QUANTITY; index++)
  6120. {
  6121. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6122. {
  6123. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6124. {
  6125. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6126. {
  6127. currentStatus = Preparing; //OCPP Status: Preparing
  6128. }
  6129. else
  6130. {
  6131. currentStatus = Available; //OCPP Status: Available
  6132. }
  6133. }
  6134. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6135. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6136. ) //S_PRECHARGE
  6137. {
  6138. currentStatus = Preparing; //OCPP Status: Preparing
  6139. }
  6140. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6141. {
  6142. currentStatus = Charging; //OCPP Status: Charging
  6143. }
  6144. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6145. {
  6146. currentStatus = Finishing; //OCPP Status: Finishing
  6147. }
  6148. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6149. {
  6150. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6151. }
  6152. 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
  6153. {
  6154. currentStatus = Unavailable; //OCPP Status: Unavailable
  6155. }
  6156. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6157. {
  6158. currentStatus = Faulted; //OCPP Status: Faulted
  6159. }
  6160. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6161. {
  6162. currentStatus = Reserved; //OCPP Status: Reserved
  6163. }
  6164. } //end of the same index
  6165. } // end of for GB_QUANTITY
  6166. }
  6167. else if(gunType[gun_index] == GUN_TYPE_DO)
  6168. {
  6169. tempIndex = gun_index;
  6170. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6171. {
  6172. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6173. {
  6174. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6175. {
  6176. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6177. {
  6178. currentStatus = Preparing; //OCPP Status: Preparing
  6179. }
  6180. else
  6181. {
  6182. currentStatus = Available; //OCPP Status: Available
  6183. }
  6184. }
  6185. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6186. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6187. ) //S_PRECHARGE
  6188. {
  6189. currentStatus = Preparing; //OCPP Status: Preparing
  6190. }
  6191. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6192. {
  6193. currentStatus = Charging; //OCPP Status: Charging
  6194. }
  6195. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6196. {
  6197. currentStatus = Finishing; //OCPP Status: Finishing
  6198. }
  6199. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6200. {
  6201. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6202. }
  6203. 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
  6204. {
  6205. currentStatus = Unavailable; //OCPP Status: Unavailable
  6206. }
  6207. 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
  6208. {
  6209. currentStatus = Faulted; //OCPP Status: Faulted
  6210. }
  6211. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6212. {
  6213. currentStatus = Reserved; //OCPP Status: Reserved
  6214. }
  6215. } //end of the same index
  6216. }
  6217. }
  6218. else
  6219. {
  6220. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6221. {
  6222. tempIndex = 2;
  6223. }
  6224. else
  6225. {
  6226. tempIndex = gun_index;
  6227. }
  6228. for (int index = 0; index < AC_QUANTITY; index++)
  6229. {
  6230. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6231. {
  6232. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  6233. {
  6234. 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))
  6235. {
  6236. currentStatus = Preparing; //OCPP Status: Preparing
  6237. }
  6238. else
  6239. {
  6240. currentStatus = Available; //OCPP Status: Available
  6241. }
  6242. }
  6243. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  6244. {
  6245. currentStatus = Preparing; //OCPP Status: Preparing
  6246. }
  6247. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  6248. {
  6249. currentStatus = Charging; //OCPP Status: Charging
  6250. }
  6251. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  6252. {
  6253. currentStatus = Finishing; //OCPP Status: Finishing
  6254. }
  6255. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6256. {
  6257. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  6258. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6259. else
  6260. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  6261. }
  6262. 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
  6263. {
  6264. currentStatus = Unavailable; //OCPP Status: Unavailable
  6265. }
  6266. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6267. {
  6268. currentStatus = Faulted; //OCPP Status: Faulted
  6269. }
  6270. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6271. {
  6272. currentStatus = Reserved; //OCPP Status: Reserved
  6273. }
  6274. }//end of the same index
  6275. }//end of for AC_QUANTITY
  6276. }
  6277. //it's option
  6278. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  6279. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  6280. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  6281. {
  6282. isStateChanged = FALSE;
  6283. }
  6284. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6285. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  6286. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6287. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  6288. isContentIllegal = TRUE;
  6289. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  6290. {
  6291. if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  6292. {
  6293. isContentIllegal = FALSE;
  6294. break;
  6295. }
  6296. }
  6297. if(isContentIllegal)
  6298. {
  6299. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  6300. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  6301. }
  6302. random_uuid(guid);
  6303. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6304. , MESSAGE_TYPE_CALL
  6305. , guid
  6306. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  6307. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  6308. , ShmOCPP16Data->StatusNotification[gun_index].Info
  6309. , ShmOCPP16Data->StatusNotification[gun_index].Status
  6310. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  6311. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  6312. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  6313. if((server_sign == TRUE) && isStateChanged)
  6314. {
  6315. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6316. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6317. LWS_Send(message);
  6318. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  6319. 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*/)
  6320. {
  6321. //DEBUG_ERROR("statusNotification mapitem pass");
  6322. result = PASS;
  6323. }
  6324. }
  6325. else
  6326. {
  6327. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6328. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6329. result = PASS;
  6330. }
  6331. return result;
  6332. }
  6333. int sendStopTransactionRequest(int gun_index)
  6334. {
  6335. mtrace();
  6336. int result = FAIL;
  6337. //char message[1500]={0};
  6338. char guid[37]={0};
  6339. char tempdata[65]={0};
  6340. int tempIndex = 0;
  6341. char TempStopTransaction[256];
  6342. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  6343. //int idx_sample=0;
  6344. DEBUG_INFO("sendStopTransactionRequest \n");
  6345. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6346. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  6347. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  6348. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6349. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6350. {
  6351. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6352. {
  6353. tempIndex = ((gun_index==2) ? 1: 0);
  6354. }
  6355. else
  6356. {
  6357. tempIndex = gun_index;
  6358. }
  6359. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6360. {
  6361. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6362. {
  6363. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6364. }
  6365. }// END OF CHAdeMO_QUANTITY
  6366. }
  6367. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6368. {
  6369. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6370. {
  6371. tempIndex = ((gun_index==2) ? 1: 0);
  6372. }
  6373. else
  6374. {
  6375. tempIndex = gun_index;
  6376. }
  6377. for (int index = 0; index < CCS_QUANTITY; index++)
  6378. {
  6379. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6380. {
  6381. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6382. }
  6383. }// END OF CCS_QUANTITY
  6384. }
  6385. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6386. {
  6387. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6388. {
  6389. tempIndex = ((gun_index==2) ? 1: 0);
  6390. }
  6391. else
  6392. {
  6393. tempIndex = gun_index;
  6394. }
  6395. for (int index = 0; index < GB_QUANTITY; index++)
  6396. {
  6397. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6398. {
  6399. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6400. }
  6401. }// END OF GB_QUANTITY
  6402. }
  6403. else if(gunType[gun_index] == GUN_TYPE_DO)
  6404. {
  6405. tempIndex = gun_index;
  6406. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6407. {
  6408. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6409. {
  6410. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6411. }
  6412. }// END OF GB_QUANTITY
  6413. }
  6414. else
  6415. {
  6416. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6417. {
  6418. tempIndex = 2;
  6419. }
  6420. else
  6421. {
  6422. tempIndex = gun_index;
  6423. }
  6424. for (int index = 0; index < AC_QUANTITY; index++)
  6425. {
  6426. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6427. {
  6428. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6429. }
  6430. }// END OF AC_QUANTITY
  6431. }
  6432. //====================================== Stop Transaction Time =====================================================
  6433. struct timeval tmnow;
  6434. struct tm *tm;
  6435. char buf[28];//, usec_buf[6];
  6436. gettimeofday(&tmnow, NULL);
  6437. time_t t;
  6438. t = time(NULL);
  6439. /*UTC time and date*/
  6440. tm = gmtime(&t);
  6441. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6442. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  6443. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  6444. random_uuid(guid);
  6445. /***********************************transactionData******************************************************/
  6446. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  6447. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  6448. //=================================
  6449. // Transaction_Begin
  6450. //=================================
  6451. //=================================
  6452. // Transaction_End
  6453. //=================================
  6454. // ================================= Current.Import L1 ===============================================
  6455. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6456. {
  6457. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  6458. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6459. {
  6460. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6461. {
  6462. tempIndex = ((gun_index==2) ? 1: 0);
  6463. }
  6464. else
  6465. {
  6466. tempIndex = gun_index;
  6467. }
  6468. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6469. {
  6470. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6471. {
  6472. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6473. }
  6474. }// End of for CHAdeMO_QUANTITY
  6475. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6476. }
  6477. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6478. {
  6479. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6480. {
  6481. tempIndex = ((gun_index==2) ? 1: 0);
  6482. }
  6483. else
  6484. {
  6485. tempIndex = gun_index;
  6486. }
  6487. for (int index = 0; index < CCS_QUANTITY; index++)
  6488. {
  6489. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6490. {
  6491. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6492. }
  6493. }// End of for CCS_QUANTITY
  6494. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6495. }
  6496. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6497. {
  6498. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6499. {
  6500. tempIndex = ((gun_index==2) ? 1: 0);
  6501. }
  6502. else
  6503. {
  6504. tempIndex = gun_index;
  6505. }
  6506. for (int index = 0; index < GB_QUANTITY; index++)
  6507. {
  6508. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6509. {
  6510. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6511. }
  6512. }// End of for GB_QUANTITY
  6513. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6514. }
  6515. else if(gunType[gun_index] == GUN_TYPE_DO)
  6516. {
  6517. tempIndex = gun_index;
  6518. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6519. {
  6520. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6521. {
  6522. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6523. }
  6524. }
  6525. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6526. }
  6527. else
  6528. {
  6529. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6530. {
  6531. tempIndex = 2;
  6532. }
  6533. else
  6534. {
  6535. tempIndex = gun_index;
  6536. }
  6537. for (int index = 0; index < AC_QUANTITY; index++)
  6538. {
  6539. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6540. {
  6541. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  6542. }
  6543. }// End of for AC_QUANTITY
  6544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  6545. }
  6546. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  6548. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  6549. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  6550. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6551. }
  6552. // ================================= Energy.Active.Import.Interval ==============================================
  6553. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  6554. {
  6555. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6556. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6557. {
  6558. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6559. {
  6560. tempIndex = ((gun_index==2) ? 1: 0);
  6561. }
  6562. else
  6563. {
  6564. tempIndex = gun_index;
  6565. }
  6566. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6567. {
  6568. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6569. {
  6570. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6571. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6572. }
  6573. }// END OF CHAdeMO_QUANTITY
  6574. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6575. }
  6576. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6577. {
  6578. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6579. {
  6580. tempIndex = ((gun_index==2) ? 1: 0);
  6581. }
  6582. else
  6583. {
  6584. tempIndex = gun_index;
  6585. }
  6586. for (int index = 0; index < CCS_QUANTITY; index++)
  6587. {
  6588. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6589. {
  6590. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6591. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6592. }
  6593. }// END OF CCS_QUANTITY
  6594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6595. }
  6596. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6597. {
  6598. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6599. {
  6600. tempIndex = ((gun_index==2) ? 1: 0);
  6601. }
  6602. else
  6603. {
  6604. tempIndex = gun_index;
  6605. }
  6606. for (int index = 0; index < GB_QUANTITY; index++)
  6607. {
  6608. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6609. {
  6610. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6611. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6612. }
  6613. }// END OF GB_QUANTITY
  6614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6615. }
  6616. else if(gunType[gun_index] == GUN_TYPE_DO)
  6617. {
  6618. tempIndex = gun_index;
  6619. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6620. {
  6621. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6622. {
  6623. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6624. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6625. }
  6626. }
  6627. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6628. }
  6629. else
  6630. {
  6631. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6632. {
  6633. tempIndex = 2;
  6634. }
  6635. else
  6636. {
  6637. tempIndex = gun_index;
  6638. }
  6639. for (int index = 0; index < AC_QUANTITY; index++)
  6640. {
  6641. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6642. {
  6643. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  6644. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6645. }
  6646. }// END OF AC_QUANTITY
  6647. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  6648. }
  6649. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6650. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  6651. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  6652. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  6653. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6654. }
  6655. //=================================== Power.Active.Import ==================================================
  6656. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  6657. {
  6658. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6659. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6660. {
  6661. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6662. {
  6663. tempIndex = ((gun_index==2) ? 1: 0);
  6664. }
  6665. else
  6666. {
  6667. tempIndex = gun_index;
  6668. }
  6669. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6670. {
  6671. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6672. {
  6673. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6674. }
  6675. } // End for CHAdeMO_QUANTITY
  6676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6677. }
  6678. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6679. {
  6680. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6681. {
  6682. tempIndex = ((gun_index==2) ? 1: 0);
  6683. }
  6684. else
  6685. {
  6686. tempIndex = gun_index;
  6687. }
  6688. for (int index = 0; index < CCS_QUANTITY; index++)
  6689. {
  6690. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6691. {
  6692. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6693. }
  6694. } // END for CCS_QUANTITY
  6695. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6696. }
  6697. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6698. {
  6699. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6700. {
  6701. tempIndex = ((gun_index==2) ? 1: 0);
  6702. }
  6703. else
  6704. {
  6705. tempIndex = gun_index;
  6706. }
  6707. for (int index = 0; index < GB_QUANTITY; index++)
  6708. {
  6709. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6710. {
  6711. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6712. }
  6713. }// END for GB_QUANTITY
  6714. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6715. }
  6716. else if(gunType[gun_index] == GUN_TYPE_DO)
  6717. {
  6718. tempIndex = gun_index;
  6719. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6720. {
  6721. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6722. {
  6723. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6724. }
  6725. }
  6726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6727. }
  6728. else
  6729. {
  6730. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6731. {
  6732. tempIndex = 2;
  6733. }
  6734. else
  6735. {
  6736. tempIndex = gun_index;
  6737. }
  6738. for (int index = 0; index < AC_QUANTITY; index++)
  6739. {
  6740. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6741. {
  6742. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6743. }
  6744. } // END for AC_QUANTITY
  6745. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  6746. }
  6747. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6748. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  6749. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  6750. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  6751. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  6752. }
  6753. //============================ Voltage L1 ====================================
  6754. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6755. {
  6756. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6757. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6758. {
  6759. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6760. {
  6761. tempIndex = ((gun_index==2) ? 1: 0);
  6762. }
  6763. else
  6764. {
  6765. tempIndex = gun_index;
  6766. }
  6767. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6768. {
  6769. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6770. {
  6771. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6772. }
  6773. } // END OF FOR CHAdeMO_QUANTITY
  6774. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6775. }
  6776. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6777. {
  6778. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6779. {
  6780. tempIndex = ((gun_index==2) ? 1: 0);
  6781. }
  6782. else
  6783. {
  6784. tempIndex = gun_index;
  6785. }
  6786. for (int index = 0; index < CCS_QUANTITY; index++)
  6787. {
  6788. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6789. {
  6790. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6791. }
  6792. } // END OF FOR CCS_QUANTITY
  6793. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6794. }
  6795. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6796. {
  6797. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6798. {
  6799. tempIndex = ((gun_index==2) ? 1: 0);
  6800. }
  6801. else
  6802. {
  6803. tempIndex = gun_index;
  6804. }
  6805. for (int index = 0; index < GB_QUANTITY; index++)
  6806. {
  6807. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6808. {
  6809. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6810. }
  6811. } // END OF FOR GB_QUANTITY
  6812. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6813. }
  6814. else if(gunType[gun_index] == GUN_TYPE_DO)
  6815. {
  6816. tempIndex = gun_index;
  6817. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6818. {
  6819. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6820. {
  6821. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6822. }
  6823. }
  6824. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6825. }
  6826. else
  6827. {
  6828. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6829. {
  6830. tempIndex = 2;
  6831. }
  6832. else
  6833. {
  6834. tempIndex = gun_index;
  6835. }
  6836. for (int index = 0; index < AC_QUANTITY; index++)
  6837. {
  6838. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6839. {
  6840. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6841. }
  6842. } // END OF FOR AC_QUANTITY
  6843. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6844. }
  6845. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6846. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6847. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6848. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6849. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6850. }
  6851. //====================== End SoC ================================
  6852. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6853. {
  6854. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6855. 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))
  6856. {
  6857. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6858. {
  6859. tempIndex = ((gun_index==2) ? 1: 0);
  6860. }
  6861. else
  6862. {
  6863. tempIndex = gun_index;
  6864. }
  6865. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6866. {
  6867. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6868. {
  6869. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6870. {
  6871. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6872. }
  6873. }
  6874. }
  6875. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6876. {
  6877. for (int index = 0; index < CCS_QUANTITY; index++)
  6878. {
  6879. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6880. {
  6881. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6882. }
  6883. }
  6884. }
  6885. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6886. {
  6887. for (int index = 0; index < GB_QUANTITY; index++)
  6888. {
  6889. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6890. {
  6891. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6892. }
  6893. }
  6894. }
  6895. else if(gunType[gun_index] == GUN_TYPE_DO)
  6896. {
  6897. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6898. {
  6899. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6900. {
  6901. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6902. }
  6903. }
  6904. }
  6905. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6906. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6907. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6908. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6909. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6910. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6911. } // END FOR DC CASE
  6912. }
  6913. // ================================= Current.Import L2 ===============================================
  6914. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6915. {
  6916. // AC 3 phse L2 current
  6917. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6918. {
  6919. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6920. {
  6921. tempIndex = 2;
  6922. }
  6923. else
  6924. {
  6925. tempIndex = gun_index;
  6926. }
  6927. for (int index = 0; index < AC_QUANTITY; index++)
  6928. {
  6929. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6930. {
  6931. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6932. }
  6933. }// End of for AC_QUANTITY
  6934. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6935. }
  6936. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6937. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6938. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6939. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6940. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6941. }
  6942. // ================================= Current.Import L3 ===============================================
  6943. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6944. {
  6945. // AC 3 phse L3 current
  6946. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6947. {
  6948. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6949. {
  6950. tempIndex = 2;
  6951. }
  6952. else
  6953. {
  6954. tempIndex = gun_index;
  6955. }
  6956. for (int index = 0; index < AC_QUANTITY; index++)
  6957. {
  6958. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6959. {
  6960. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6961. }
  6962. }// End of for AC_QUANTITY
  6963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6964. }
  6965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6966. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6967. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6968. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6969. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6970. }
  6971. //============================ Voltage L2 ====================================
  6972. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6973. {
  6974. // AC 3 phse L2 voltage
  6975. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6976. {
  6977. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6978. {
  6979. tempIndex = 2;
  6980. }
  6981. else
  6982. {
  6983. tempIndex = gun_index;
  6984. }
  6985. for (int index = 0; index < AC_QUANTITY; index++)
  6986. {
  6987. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6988. {
  6989. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  6990. }
  6991. } // END OF FOR AC_QUANTITY
  6992. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6993. }
  6994. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6998. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6999. }
  7000. //============================ Voltage L3 ====================================
  7001. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  7002. {
  7003. // AC 3 phse L3 voltage
  7004. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7005. {
  7006. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7007. {
  7008. tempIndex = 2;
  7009. }
  7010. else
  7011. {
  7012. tempIndex = gun_index;
  7013. }
  7014. for (int index = 0; index < AC_QUANTITY; index++)
  7015. {
  7016. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7017. {
  7018. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  7019. }
  7020. } // END OF FOR AC_QUANTITY
  7021. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  7022. }
  7023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  7024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  7025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  7026. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  7027. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7028. }
  7029. //====================== Start SoC ================================
  7030. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  7031. {
  7032. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7033. 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))
  7034. {
  7035. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7036. {
  7037. tempIndex = ((gun_index==2) ? 1: 0);
  7038. }
  7039. else
  7040. {
  7041. tempIndex = gun_index;
  7042. }
  7043. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7044. {
  7045. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7046. {
  7047. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7048. {
  7049. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  7050. }
  7051. }
  7052. }
  7053. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7054. {
  7055. for (int index = 0; index < CCS_QUANTITY; index++)
  7056. {
  7057. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7058. {
  7059. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  7060. }
  7061. }
  7062. }
  7063. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7064. {
  7065. for (int index = 0; index < GB_QUANTITY; index++)
  7066. {
  7067. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7068. {
  7069. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  7070. }
  7071. }
  7072. }
  7073. else if(gunType[gun_index] == GUN_TYPE_DO)
  7074. {
  7075. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7076. {
  7077. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7078. {
  7079. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  7080. }
  7081. }
  7082. }
  7083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  7084. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  7085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  7086. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  7087. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  7088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  7089. } // END FOR DC CASE
  7090. }
  7091. //================================================ Message create ====================================================
  7092. json_object *StopTransaction = json_object_new_object();
  7093. json_object *transactionDatas = json_object_new_array();
  7094. json_object *sampledValues = json_object_new_array();
  7095. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  7096. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  7097. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  7098. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  7099. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  7100. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  7101. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  7102. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  7103. {
  7104. json_object *transactionData = json_object_new_object();
  7105. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  7106. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  7107. {
  7108. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  7109. {
  7110. json_object *sampledValue = json_object_new_object();
  7111. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  7112. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  7113. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  7114. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  7115. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  7116. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  7117. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  7118. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  7119. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  7120. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  7121. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  7122. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  7123. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  7124. json_object_array_add(sampledValues, sampledValue);
  7125. }
  7126. }
  7127. json_object_object_add(transactionData, "sampledValue", sampledValues);
  7128. json_object_array_add(transactionDatas, transactionData);
  7129. }
  7130. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  7131. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  7132. ,MESSAGE_TYPE_CALL
  7133. ,guid
  7134. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  7135. json_object_put(StopTransaction);
  7136. #if 1 // for TempStopTransaction
  7137. //Delete TempStopTransaction
  7138. if((access(TempStopTransaction,F_OK))!=-1)
  7139. {
  7140. remove(TempStopTransaction); // remove file "TempStopTransaction"
  7141. }
  7142. #endif
  7143. #if 1
  7144. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  7145. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  7146. {
  7147. result = PASS;
  7148. //DEBUG_INFO("StopTransaction mapitem pass\n");
  7149. }
  7150. #endif
  7151. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  7152. OCPP_insert_transaction_msg(NO, queuedata);
  7153. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  7154. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  7155. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  7156. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  7157. {
  7158. //SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  7159. }
  7160. //for test
  7161. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  7162. return result;
  7163. }
  7164. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  7165. {
  7166. mtrace();
  7167. int result = FAIL;
  7168. char guid[37]={0};
  7169. char tempdata[65]={0};
  7170. int tempIndex = 0;
  7171. DEBUG_INFO("sendMeterValuesRequest ...\n");
  7172. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  7173. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  7174. //set value
  7175. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  7176. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  7177. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  7178. -1);
  7179. random_uuid(guid);
  7180. //UTC Date time
  7181. struct timeval tmnow;
  7182. struct tm *tm;
  7183. char buf[28];//, usec_buf[6];
  7184. gettimeofday(&tmnow, NULL);
  7185. time_t t;
  7186. t = time(NULL);
  7187. /*UTC time and date*/
  7188. tm = gmtime(&t);
  7189. if(dataType == ReadingContext_Sample_Clock)
  7190. {
  7191. struct tm *tmTarget;
  7192. struct timeb tbTarget;
  7193. tbTarget.time = mktime(tm);
  7194. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  7195. tmTarget = gmtime(&tbTarget.time);
  7196. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  7197. }
  7198. else
  7199. {
  7200. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  7201. }
  7202. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  7203. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  7204. //********************************(1)Current.Import L1************************************************/
  7205. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7206. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7207. (dataType == ReadingContext_Trigger))
  7208. {
  7209. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7210. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7211. {
  7212. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7213. {
  7214. tempIndex = ((gun_index==2) ? 1: 0);
  7215. }
  7216. else
  7217. {
  7218. tempIndex = gun_index;
  7219. }
  7220. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7221. {
  7222. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7223. {
  7224. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  7225. }
  7226. }
  7227. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  7228. }
  7229. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7230. {
  7231. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7232. {
  7233. tempIndex = ((gun_index==2) ? 1: 0);
  7234. }
  7235. else
  7236. {
  7237. tempIndex = gun_index;
  7238. }
  7239. for (int index = 0; index < CCS_QUANTITY; index++)
  7240. {
  7241. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7242. {
  7243. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  7244. }
  7245. }
  7246. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  7247. }
  7248. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7249. {
  7250. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7251. {
  7252. tempIndex = ((gun_index==2) ? 1: 0);
  7253. }
  7254. else
  7255. {
  7256. tempIndex = gun_index;
  7257. }
  7258. for (int index = 0; index < GB_QUANTITY; index++)
  7259. {
  7260. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7261. {
  7262. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  7263. }
  7264. }
  7265. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  7266. }
  7267. else if(gunType[gun_index] == GUN_TYPE_DO)
  7268. {
  7269. tempIndex = gun_index;
  7270. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7271. {
  7272. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7273. {
  7274. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  7275. }
  7276. }
  7277. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  7278. }
  7279. else
  7280. {
  7281. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7282. {
  7283. tempIndex = 2;
  7284. }
  7285. else
  7286. {
  7287. tempIndex = gun_index;
  7288. }
  7289. for (int index = 0; index < AC_QUANTITY; index++)
  7290. {
  7291. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7292. {
  7293. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  7294. }
  7295. }
  7296. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  7297. }
  7298. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  7299. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  7300. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  7301. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  7302. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7303. }
  7304. //********************************(2)Energy.Active.Import.Register ************************************************/
  7305. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  7306. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  7307. (dataType == ReadingContext_Trigger))
  7308. {
  7309. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7310. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7311. {
  7312. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7313. {
  7314. tempIndex = ((gun_index==2) ? 1: 0);
  7315. }
  7316. else
  7317. {
  7318. tempIndex = gun_index;
  7319. }
  7320. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7321. {
  7322. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7323. {
  7324. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  7325. }
  7326. }
  7327. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7328. }
  7329. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7330. {
  7331. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7332. {
  7333. tempIndex = ((gun_index==2) ? 1: 0);
  7334. }
  7335. else
  7336. {
  7337. tempIndex = gun_index;
  7338. }
  7339. for (int index = 0; index < CCS_QUANTITY; index++)
  7340. {
  7341. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7342. {
  7343. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  7344. }
  7345. }
  7346. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7347. }
  7348. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7349. {
  7350. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7351. {
  7352. tempIndex = ((gun_index==2) ? 1: 0);
  7353. }
  7354. else
  7355. {
  7356. tempIndex = gun_index;
  7357. }
  7358. for (int index = 0; index < GB_QUANTITY; index++)
  7359. {
  7360. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7361. {
  7362. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  7363. }
  7364. }
  7365. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7366. }
  7367. else if(gunType[gun_index] == GUN_TYPE_DO)
  7368. {
  7369. tempIndex = gun_index;
  7370. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7371. {
  7372. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7373. {
  7374. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  7375. }
  7376. }
  7377. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7378. }
  7379. else
  7380. {
  7381. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7382. {
  7383. tempIndex = 2;
  7384. }
  7385. else
  7386. {
  7387. tempIndex = gun_index;
  7388. }
  7389. for (int index = 0; index < AC_QUANTITY; index++)
  7390. {
  7391. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7392. {
  7393. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  7394. }
  7395. }
  7396. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  7397. }
  7398. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  7399. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  7400. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  7401. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  7402. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7403. }
  7404. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  7405. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7406. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7407. (dataType == ReadingContext_Trigger))
  7408. {
  7409. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7410. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7411. {
  7412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7413. {
  7414. tempIndex = ((gun_index==2) ? 1: 0);
  7415. }
  7416. else
  7417. {
  7418. tempIndex = gun_index;
  7419. }
  7420. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7421. {
  7422. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7423. {
  7424. if(dataType == ReadingContext_Sample_Clock)
  7425. {
  7426. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7427. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7428. }
  7429. else if(dataType == ReadingContext_Sample_Periodic)
  7430. {
  7431. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7432. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7433. }
  7434. else
  7435. {
  7436. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7437. }
  7438. }
  7439. } // END OF FOR CHAdeMO_QUANTITY
  7440. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7441. }
  7442. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7443. {
  7444. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7445. {
  7446. tempIndex = ((gun_index==2) ? 1: 0);
  7447. }
  7448. else
  7449. {
  7450. tempIndex = gun_index;
  7451. }
  7452. for (int index = 0; index < CCS_QUANTITY; index++)
  7453. {
  7454. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7455. {
  7456. if(dataType == ReadingContext_Sample_Clock)
  7457. {
  7458. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7459. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7460. }
  7461. else if(dataType == ReadingContext_Sample_Periodic)
  7462. {
  7463. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7464. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7465. }
  7466. else
  7467. {
  7468. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7469. }
  7470. }
  7471. } // END OF CCS_QUANTITY
  7472. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7473. }
  7474. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7475. {
  7476. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7477. {
  7478. tempIndex = ((gun_index==2) ? 1: 0);
  7479. }
  7480. else
  7481. {
  7482. tempIndex = gun_index;
  7483. }
  7484. for (int index = 0; index < GB_QUANTITY; index++)
  7485. {
  7486. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7487. {
  7488. if(dataType == ReadingContext_Sample_Clock)
  7489. {
  7490. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7491. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7492. }
  7493. else if(dataType == ReadingContext_Sample_Periodic)
  7494. {
  7495. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7496. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7497. }
  7498. else
  7499. {
  7500. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7501. }
  7502. }
  7503. } // END OF GB_QUANTITY
  7504. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7505. }
  7506. else if(gunType[gun_index] == GUN_TYPE_DO)
  7507. {
  7508. tempIndex = gun_index;
  7509. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7510. {
  7511. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7512. {
  7513. if(dataType == ReadingContext_Sample_Clock)
  7514. {
  7515. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7516. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7517. }
  7518. else if(dataType == ReadingContext_Sample_Periodic)
  7519. {
  7520. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7521. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7522. }
  7523. else
  7524. {
  7525. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7526. }
  7527. }
  7528. }
  7529. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7530. }
  7531. else
  7532. {
  7533. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7534. {
  7535. tempIndex = 2;
  7536. }
  7537. else
  7538. {
  7539. tempIndex = gun_index;
  7540. }
  7541. for (int index = 0; index < AC_QUANTITY; index++)
  7542. {
  7543. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7544. {
  7545. if(dataType == ReadingContext_Sample_Clock)
  7546. {
  7547. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7548. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7549. }
  7550. else if(dataType == ReadingContext_Sample_Periodic)
  7551. {
  7552. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7553. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7554. }
  7555. else
  7556. {
  7557. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7558. }
  7559. }
  7560. }
  7561. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7562. }
  7563. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7564. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7565. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7566. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7567. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7568. }
  7569. //********************************(4)Power.Active.Import************************************************/
  7570. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7571. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7572. (dataType == ReadingContext_Trigger))
  7573. {
  7574. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7575. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7576. {
  7577. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7578. {
  7579. tempIndex = ((gun_index==2) ? 1: 0);
  7580. }
  7581. else
  7582. {
  7583. tempIndex = gun_index;
  7584. }
  7585. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7586. {
  7587. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7588. {
  7589. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7590. }
  7591. } // END OF FOR
  7592. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7593. }
  7594. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7595. {
  7596. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7597. {
  7598. tempIndex = ((gun_index==2) ? 1: 0);
  7599. }
  7600. else
  7601. {
  7602. tempIndex = gun_index;
  7603. }
  7604. for (int index = 0; index < CCS_QUANTITY; index++)
  7605. {
  7606. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7607. {
  7608. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7609. }
  7610. }
  7611. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7612. }
  7613. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7614. {
  7615. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7616. {
  7617. tempIndex = ((gun_index==2) ? 1: 0);
  7618. }
  7619. else
  7620. {
  7621. tempIndex = gun_index;
  7622. }
  7623. for (int index = 0; index < GB_QUANTITY; index++)
  7624. {
  7625. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7626. {
  7627. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7628. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7629. }
  7630. }
  7631. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7632. }
  7633. else if(gunType[gun_index] == GUN_TYPE_DO)
  7634. {
  7635. tempIndex = gun_index;
  7636. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7637. {
  7638. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7639. {
  7640. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7641. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7642. }
  7643. }
  7644. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7645. }
  7646. else
  7647. {
  7648. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7649. {
  7650. tempIndex = 2;
  7651. }
  7652. else
  7653. {
  7654. tempIndex = gun_index;
  7655. }
  7656. for (int index = 0; index < AC_QUANTITY; index++)
  7657. {
  7658. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7659. {
  7660. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7661. }
  7662. }
  7663. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7664. }
  7665. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7666. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7667. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7668. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7669. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7670. }
  7671. //***********************************************(5)VOLTAGE L1******************************************************/
  7672. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7673. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7674. (dataType == ReadingContext_Trigger))
  7675. {
  7676. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7677. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7678. {
  7679. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7680. {
  7681. tempIndex = ((gun_index==2) ? 1: 0);
  7682. }
  7683. else
  7684. {
  7685. tempIndex = gun_index;
  7686. }
  7687. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7688. {
  7689. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7690. {
  7691. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7692. }
  7693. }
  7694. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7695. }
  7696. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7697. {
  7698. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7699. {
  7700. tempIndex = ((gun_index==2) ? 1: 0);
  7701. }
  7702. else
  7703. {
  7704. tempIndex = gun_index;
  7705. }
  7706. for (int index = 0; index < CCS_QUANTITY; index++)
  7707. {
  7708. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7709. {
  7710. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7711. }
  7712. }
  7713. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7714. }
  7715. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7716. {
  7717. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7718. {
  7719. tempIndex = ((gun_index==2) ? 1: 0);
  7720. }
  7721. else
  7722. {
  7723. tempIndex = gun_index;
  7724. }
  7725. for (int index = 0; index < GB_QUANTITY; index++)
  7726. {
  7727. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7728. {
  7729. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7730. }
  7731. }
  7732. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7733. }
  7734. else if(gunType[gun_index] == GUN_TYPE_DO)
  7735. {
  7736. tempIndex = gun_index;
  7737. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7738. {
  7739. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7740. {
  7741. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7742. }
  7743. }
  7744. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7745. }
  7746. else
  7747. {
  7748. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7749. {
  7750. tempIndex = 2;
  7751. }
  7752. else
  7753. {
  7754. tempIndex = gun_index;
  7755. }
  7756. for (int index = 0; index < AC_QUANTITY; index++)
  7757. {
  7758. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7759. {
  7760. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7761. }
  7762. }
  7763. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7764. }
  7765. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7766. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7767. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7768. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7769. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7770. }
  7771. //***********************************************(6)SOC******************************************************/
  7772. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7773. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7774. (dataType == ReadingContext_Trigger))
  7775. {
  7776. 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))
  7777. {
  7778. //idx_sample=5;
  7779. //sampledValue = NULL;
  7780. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7781. {
  7782. tempIndex = ((gun_index==2) ? 1: 0);
  7783. }
  7784. else
  7785. {
  7786. tempIndex = gun_index;
  7787. }
  7788. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7789. {
  7790. //tempIndex = ((gun_index==2) ? 1: 0);
  7791. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7792. {
  7793. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7794. {
  7795. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7796. }
  7797. }
  7798. }
  7799. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7800. {
  7801. //tempIndex = ((gun_index==2) ? 1: 0);
  7802. for (int index = 0; index < CCS_QUANTITY; index++)
  7803. {
  7804. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7805. {
  7806. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7807. }
  7808. }
  7809. }
  7810. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7811. {
  7812. //tempIndex = ((gun_index==2) ? 1: 0);
  7813. for (int index = 0; index < GB_QUANTITY; index++)
  7814. {
  7815. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7816. {
  7817. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7818. }
  7819. }
  7820. }
  7821. else if(gunType[gun_index] == GUN_TYPE_DO)
  7822. {
  7823. //tempIndex = ((gun_index==2) ? 1: 0);
  7824. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7825. {
  7826. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7827. {
  7828. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7829. }
  7830. }
  7831. }
  7832. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7833. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7834. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7835. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7836. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7837. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7838. }
  7839. }
  7840. //********************************(7)Current.Import L2************************************************/
  7841. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7842. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7843. (dataType == ReadingContext_Trigger))
  7844. {
  7845. // Only for AC 3 phase
  7846. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7847. {
  7848. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7849. {
  7850. tempIndex = 2;
  7851. }
  7852. else
  7853. {
  7854. tempIndex = gun_index;
  7855. }
  7856. for (int index = 0; index < AC_QUANTITY; index++)
  7857. {
  7858. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7859. {
  7860. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7861. }
  7862. }
  7863. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7864. }
  7865. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7866. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7867. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7868. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7869. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7870. }
  7871. //********************************(8)Current.Import L3************************************************/
  7872. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7873. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7874. (dataType == ReadingContext_Trigger))
  7875. {
  7876. // Only for AC 3 phase
  7877. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7878. {
  7879. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7880. {
  7881. tempIndex = 2;
  7882. }
  7883. else
  7884. {
  7885. tempIndex = gun_index;
  7886. }
  7887. for (int index = 0; index < AC_QUANTITY; index++)
  7888. {
  7889. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7890. {
  7891. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7892. }
  7893. }
  7894. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7895. }
  7896. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7897. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7898. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7899. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7900. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7901. }
  7902. //***********************************************(9)VOLTAGE L2******************************************************/
  7903. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7904. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7905. (dataType == ReadingContext_Trigger))
  7906. {
  7907. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7908. {
  7909. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7910. {
  7911. tempIndex = 2;
  7912. }
  7913. else
  7914. {
  7915. tempIndex = gun_index;
  7916. }
  7917. for (int index = 0; index < AC_QUANTITY; index++)
  7918. {
  7919. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7920. {
  7921. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7922. }
  7923. }
  7924. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7925. }
  7926. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7927. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7928. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7929. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7930. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7931. }
  7932. //***********************************************(10)VOLTAGE L3******************************************************/
  7933. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7934. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7935. (dataType == ReadingContext_Trigger))
  7936. {
  7937. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7938. {
  7939. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7940. {
  7941. tempIndex = 2;
  7942. }
  7943. else
  7944. {
  7945. tempIndex = gun_index;
  7946. }
  7947. for (int index = 0; index < AC_QUANTITY; index++)
  7948. {
  7949. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7950. {
  7951. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7952. }
  7953. }
  7954. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7955. }
  7956. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7957. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7958. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7959. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7960. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7961. }
  7962. //***********************************************(11)Current.Offered******************************************************/
  7963. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7964. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7965. (dataType == ReadingContext_Trigger))
  7966. {
  7967. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7968. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7969. {
  7970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7971. {
  7972. tempIndex = ((gun_index==2) ? 1: 0);
  7973. }
  7974. else
  7975. {
  7976. tempIndex = gun_index;
  7977. }
  7978. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7979. {
  7980. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7981. {
  7982. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7983. }
  7984. } // END OF FOR CHAdeMO_QUANTITY
  7985. }
  7986. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7987. {
  7988. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7989. {
  7990. tempIndex = ((gun_index==2) ? 1: 0);
  7991. }
  7992. else
  7993. {
  7994. tempIndex = gun_index;
  7995. }
  7996. for (int index = 0; index < CCS_QUANTITY; index++)
  7997. {
  7998. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7999. {
  8000. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  8001. }
  8002. } // END OF CCS_QUANTITY
  8003. }
  8004. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8005. {
  8006. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8007. {
  8008. tempIndex = ((gun_index==2) ? 1: 0);
  8009. }
  8010. else
  8011. {
  8012. tempIndex = gun_index;
  8013. }
  8014. for (int index = 0; index < GB_QUANTITY; index++)
  8015. {
  8016. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8017. {
  8018. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  8019. }
  8020. } // END OF GB_QUANTITY
  8021. }
  8022. else if(gunType[gun_index] == GUN_TYPE_DO)
  8023. {
  8024. tempIndex = gun_index;
  8025. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8026. {
  8027. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8028. {
  8029. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  8030. }
  8031. }
  8032. }
  8033. else
  8034. {
  8035. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8036. {
  8037. tempIndex = 2;
  8038. }
  8039. else
  8040. {
  8041. tempIndex = gun_index;
  8042. }
  8043. for (int index = 0; index < AC_QUANTITY; index++)
  8044. {
  8045. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8046. {
  8047. uint16_t currentOffer;
  8048. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  8049. {
  8050. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  8051. }
  8052. else
  8053. {
  8054. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  8055. }
  8056. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  8057. }
  8058. }
  8059. }
  8060. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  8061. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  8062. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  8063. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  8064. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  8065. }
  8066. //***********************************************(12)Power.Offered******************************************************/
  8067. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  8068. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  8069. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  8070. {
  8071. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8072. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8073. {
  8074. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8075. {
  8076. tempIndex = ((gun_index==2) ? 1: 0);
  8077. }
  8078. else
  8079. {
  8080. tempIndex = gun_index;
  8081. }
  8082. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8083. {
  8084. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8085. {
  8086. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  8087. }
  8088. } // END OF FOR CHAdeMO_QUANTITY
  8089. }
  8090. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8091. {
  8092. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8093. {
  8094. tempIndex = ((gun_index==2) ? 1: 0);
  8095. }
  8096. else
  8097. {
  8098. tempIndex = gun_index;
  8099. }
  8100. for (int index = 0; index < CCS_QUANTITY; index++)
  8101. {
  8102. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8103. {
  8104. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  8105. }
  8106. } // END OF CCS_QUANTITY
  8107. }
  8108. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8109. {
  8110. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8111. {
  8112. tempIndex = ((gun_index==2) ? 1: 0);
  8113. }
  8114. else
  8115. {
  8116. tempIndex = gun_index;
  8117. }
  8118. for (int index = 0; index < GB_QUANTITY; index++)
  8119. {
  8120. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8121. {
  8122. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  8123. }
  8124. } // END OF GB_QUANTITY
  8125. }
  8126. else if(gunType[gun_index] == GUN_TYPE_DO)
  8127. {
  8128. tempIndex = gun_index;
  8129. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8130. {
  8131. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8132. {
  8133. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  8134. }
  8135. }
  8136. }
  8137. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  8138. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  8139. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  8140. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  8141. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  8142. }
  8143. // Message create ====================================================================================================
  8144. if(TRUE)
  8145. {
  8146. json_object *MeterValueReq = json_object_new_object();
  8147. json_object *MeterValues = json_object_new_array();
  8148. json_object *sampledValues = json_object_new_array();
  8149. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  8150. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  8151. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  8152. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  8153. {
  8154. json_object *MeterValue = json_object_new_object();
  8155. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  8156. {
  8157. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  8158. {
  8159. json_object *sampledValue = json_object_new_object();
  8160. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  8161. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  8162. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  8163. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  8164. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  8165. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  8166. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  8167. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  8168. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  8169. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  8170. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  8171. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  8172. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  8173. json_object_array_add(sampledValues, sampledValue);
  8174. }
  8175. }
  8176. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  8177. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  8178. json_object_array_add(MeterValues, MeterValue);
  8179. }
  8180. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  8181. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  8182. ,gun_index + 1
  8183. ,MESSAGE_TYPE_CALL
  8184. ,guid
  8185. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  8186. json_object_put(MeterValueReq);
  8187. }
  8188. // Put request guid to hash map
  8189. sprintf(tempdata, "MeterValues,%d", (gun_index));
  8190. 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*/)
  8191. {
  8192. result = PASS;
  8193. //DEBUG_INFO("MeterValues mapitem pass\n");
  8194. }
  8195. if((dataType != ReadingContext_Trigger) &&
  8196. (dataType != ReadingContext_Sample_Clock) &&
  8197. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  8198. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  8199. else
  8200. {
  8201. if(FirstHeartBeat)
  8202. LWS_Send(queuedata +2);
  8203. }
  8204. return result;
  8205. }
  8206. int sendLogStatusNotificationRequest(char *status)
  8207. {
  8208. mtrace();
  8209. int result = PASS;
  8210. char message[4096]={0};
  8211. char guid[37]={0};
  8212. char tempdata[128]={0};
  8213. json_object *LogStatusNotification = json_object_new_object();
  8214. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  8215. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  8216. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  8217. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  8218. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  8219. random_uuid(guid);
  8220. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  8221. json_object_put(LogStatusNotification);
  8222. LWS_Send(message);
  8223. sprintf(tempdata, "LogStatusNotification,%d", 0);
  8224. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8225. {
  8226. result = PASS;
  8227. }
  8228. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  8229. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  8230. return result;
  8231. }
  8232. int sendSecurityEventNotificationRequest()
  8233. {
  8234. mtrace();
  8235. int result = PASS;
  8236. char message[4096]={0};
  8237. char guid[37]={0};
  8238. char tempdata[128]={0};
  8239. json_object *SecurityEventNotification = json_object_new_object();
  8240. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  8241. //Stop Transaction Time
  8242. struct timeval tmnow;
  8243. struct tm *tm;
  8244. gettimeofday(&tmnow, NULL);
  8245. time_t t;
  8246. t = time(NULL);
  8247. /*UTC time and date*/
  8248. tm = gmtime(&t);
  8249. strftime((char *)ShmOCPP16Data->SecurityEventNotification.timestamp, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.timestamp), "%Y-%m-%dT%H:%M:%SZ", tm);
  8250. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  8251. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  8252. if(strlen((char*)ShmOCPP16Data->SecurityEventNotification.techInfo) > 0)
  8253. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  8254. random_uuid(guid);
  8255. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  8256. json_object_put(SecurityEventNotification);
  8257. LWS_Send(message);
  8258. sprintf(tempdata, "SecurityEventNotification,0");
  8259. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8260. {
  8261. result = PASS;
  8262. }
  8263. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  8264. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  8265. return result;
  8266. }
  8267. int sendSignCertificateRequest()
  8268. {
  8269. mtrace();
  8270. int result = PASS;
  8271. char message[4096]={0};
  8272. char guid[37]={0};
  8273. char tempdata[128]={0};
  8274. json_object *SignCertificate = json_object_new_object();
  8275. DEBUG_INFO("sendSignCertificateRequest...\n");
  8276. // Read csr file content
  8277. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  8278. FILE *fp=fopen(CSR_CP,"r");
  8279. char *line = NULL;
  8280. size_t len = 0;
  8281. while(getline(&line, &len, fp) != -1)
  8282. {
  8283. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  8284. {
  8285. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  8286. }
  8287. }
  8288. fclose(fp);
  8289. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  8290. random_uuid(guid);
  8291. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  8292. json_object_put(SignCertificate);
  8293. LWS_Send(message);
  8294. sprintf(tempdata, "SignCertificate,0");
  8295. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8296. {
  8297. result = PASS;
  8298. }
  8299. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  8300. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  8301. return result;
  8302. }
  8303. int sendSignedFirmwareStatusNotificationRequest(char *status)
  8304. {
  8305. mtrace();
  8306. int result = PASS;
  8307. char message[4096]={0};
  8308. char guid[37]={0};
  8309. char tempdata[128]={0};
  8310. json_object *SignedFirmwareStatusNotification = json_object_new_object();
  8311. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  8312. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  8313. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  8314. json_object_object_add(SignedFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  8315. json_object_object_add(SignedFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  8316. random_uuid(guid);
  8317. sprintf(message,"[%d,\"%s\",\"SignedFirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(SignedFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  8318. json_object_put(SignedFirmwareStatusNotification);
  8319. LWS_Send(message);
  8320. sprintf(tempdata, "SignedFirmwareStatusNotification,%d", 0);
  8321. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8322. {
  8323. result = PASS;
  8324. }
  8325. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  8326. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  8327. return result;
  8328. }
  8329. //==========================================
  8330. // send confirm routine
  8331. //==========================================
  8332. int sendCancelReservationConfirmation(char *uuid,char *payload)
  8333. {
  8334. mtrace();
  8335. int result = FAIL;
  8336. char message[100]={0};
  8337. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  8338. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8339. LWS_Send(message);
  8340. result = TRUE;
  8341. return result;
  8342. }
  8343. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  8344. {
  8345. mtrace();
  8346. int result = FAIL;
  8347. char message[100]={0};
  8348. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  8349. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8350. LWS_Send(message);
  8351. result = TRUE;
  8352. return result;
  8353. }
  8354. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  8355. {
  8356. mtrace();
  8357. int result = FAIL;
  8358. char message[100]={0};
  8359. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  8360. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8361. LWS_Send(message);
  8362. result = TRUE;
  8363. return result;
  8364. }
  8365. int sendClearCacheConfirmation(char *uuid,char *payload)
  8366. {
  8367. mtrace();
  8368. int result = FAIL;
  8369. char message[500]={0};
  8370. DEBUG_INFO("sendClearCacheConfirmation...\n");
  8371. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8372. LWS_Send(message);
  8373. return result;
  8374. }
  8375. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  8376. {
  8377. mtrace();
  8378. int result = FAIL;
  8379. char message[500]={0};
  8380. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  8381. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8382. LWS_Send(message);
  8383. return result;
  8384. }
  8385. int sendDataTransferConfirmation(char *uuid,char *payload)
  8386. {
  8387. mtrace();
  8388. char statusStr[20]={0};
  8389. char dataStr[10]={0};
  8390. char sstr[20]={0};
  8391. int c = 0;
  8392. char *loc;
  8393. int result = FAIL;
  8394. DEBUG_INFO("sendDataTransferConfirmation...\n");
  8395. /**********************status**************************/
  8396. loc = strstr(payload, "status");
  8397. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8398. c = 0;
  8399. while (loc[3+strlen("status")+c] != '\"')
  8400. {
  8401. sstr[c] = loc[3+strlen("status")+c];
  8402. c++;
  8403. }
  8404. sstr[c] = '\0';
  8405. strcpy(statusStr, sstr);
  8406. /**********************data**************************/
  8407. loc = strstr(payload, "data");
  8408. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8409. c = 0;
  8410. while (loc[3+strlen("data")+c] != '\"')
  8411. {
  8412. sstr[c] = loc[3+strlen("data")+c];
  8413. c++;
  8414. }
  8415. sstr[c] = '\0';
  8416. strcpy(dataStr, sstr);
  8417. return result;
  8418. }
  8419. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  8420. {
  8421. mtrace();
  8422. int result = FAIL;
  8423. char message[1000]={0};
  8424. int CompositeScheduleIndex = 0;
  8425. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  8426. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  8427. if(nPeriod == 0)
  8428. {
  8429. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  8430. {
  8431. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  8432. ,MESSAGE_TYPE_CALLRESULT
  8433. ,uuid
  8434. ,payload
  8435. ,connectorIdInt);
  8436. }
  8437. else
  8438. {
  8439. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  8440. ,MESSAGE_TYPE_CALLRESULT
  8441. ,uuid
  8442. ,payload
  8443. ,connectorIdInt
  8444. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8445. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8446. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8447. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  8448. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  8449. }
  8450. }
  8451. else
  8452. {
  8453. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  8454. ,MESSAGE_TYPE_CALLRESULT
  8455. ,uuid
  8456. ,payload
  8457. ,connectorIdInt
  8458. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8459. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8460. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8461. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  8462. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  8463. {
  8464. if (idx_sample == 0)
  8465. {
  8466. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8467. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8468. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8469. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8470. }
  8471. else
  8472. {
  8473. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8474. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8475. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8476. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8477. }
  8478. }
  8479. sprintf(message + strlen(message), "]}}]");
  8480. }
  8481. LWS_Send(message);
  8482. result = TRUE;
  8483. return result;
  8484. }
  8485. int sendGetConfigurationConfirmation(char *uuid)
  8486. {
  8487. mtrace();
  8488. int result = FAIL;
  8489. int MaxKeySupported = 0;
  8490. int sentConfigurationNumber= 0;
  8491. int sentunConfigurationNumber= 0;
  8492. char message[1024*10]={0};
  8493. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  8494. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8495. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  8496. ,MESSAGE_TYPE_CALLRESULT
  8497. ,uuid );
  8498. //configuration key
  8499. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  8500. {
  8501. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  8502. {
  8503. if (sentConfigurationNumber == 0)
  8504. {
  8505. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8506. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8507. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8508. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8509. }
  8510. else
  8511. {
  8512. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8513. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8514. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8515. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8516. }
  8517. sentConfigurationNumber = sentConfigurationNumber + 1;
  8518. }
  8519. }
  8520. sprintf(message + strlen(message), "]");
  8521. if(UnknownKeynum != 0)
  8522. {
  8523. sprintf(message + strlen(message), ",\"unknownKey\":[");
  8524. //unkown key
  8525. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8526. {
  8527. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  8528. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8529. if(sentunConfigurationNumber == 0)
  8530. {
  8531. sprintf(message + strlen(message), "\"%s\""
  8532. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8533. }
  8534. else
  8535. {
  8536. sprintf(message + strlen(message), ",\"%s\""
  8537. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8538. }
  8539. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8540. }
  8541. sprintf(message + strlen(message), "]");
  8542. }
  8543. sprintf(message + strlen(message), "}]");
  8544. LWS_Send(message);
  8545. return result;
  8546. }
  8547. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8548. {
  8549. mtrace();
  8550. int result = FAIL;
  8551. char message[400]={0};
  8552. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8553. if(strcmp(payload,"")==0)
  8554. {
  8555. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8556. }
  8557. else
  8558. {
  8559. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8560. }
  8561. LWS_Send(message);
  8562. result = TRUE;
  8563. return result;
  8564. }
  8565. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8566. {
  8567. mtrace();
  8568. int result = FAIL;
  8569. char message[80]={0};
  8570. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8571. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8572. LWS_Send(message);
  8573. result = TRUE;
  8574. return result;
  8575. }
  8576. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8577. {
  8578. mtrace();
  8579. int result = FAIL;
  8580. char message[80]={0};
  8581. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8582. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8583. LWS_Send(message);
  8584. result = TRUE;
  8585. return result;
  8586. }
  8587. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8588. {
  8589. mtrace();
  8590. int result = FAIL;
  8591. char message[80]={0};
  8592. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8593. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8594. LWS_Send(message);
  8595. result = TRUE;
  8596. return result;
  8597. }
  8598. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8599. {
  8600. mtrace();
  8601. int result = FAIL;
  8602. char message[80]={0};
  8603. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8604. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8605. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8606. LWS_Send(message);
  8607. result = TRUE;
  8608. return result;
  8609. }
  8610. int sendResetConfirmation(char *uuid,char *payload)
  8611. {
  8612. mtrace();
  8613. int result = FAIL;
  8614. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8615. char message[80]={0};
  8616. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8617. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8618. LWS_Send(message);
  8619. result = TRUE;
  8620. return result;
  8621. }
  8622. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8623. {
  8624. mtrace();
  8625. int result = FAIL;
  8626. char message[500]={0};
  8627. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8628. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8629. LWS_Send(message);
  8630. result = TRUE;
  8631. return result;
  8632. }
  8633. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8634. {
  8635. mtrace();
  8636. int result = FAIL;
  8637. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8638. char message[80]={0};
  8639. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8640. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8641. LWS_Send(message);
  8642. result = TRUE;
  8643. return result;
  8644. }
  8645. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8646. {
  8647. mtrace();
  8648. int result = FAIL;
  8649. char message[80]={0};
  8650. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8651. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8652. LWS_Send(message);
  8653. result = TRUE;
  8654. return result;
  8655. }
  8656. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8657. {
  8658. mtrace();
  8659. int result = FAIL;
  8660. char message[80]={0};
  8661. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8662. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8663. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8664. LWS_Send(message);
  8665. result = TRUE;
  8666. return result;
  8667. }
  8668. int sendUpdateFirmwareConfirmation(char *uuid)
  8669. {
  8670. mtrace();
  8671. int result = FAIL;
  8672. char message[60]={0};
  8673. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8674. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8675. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8676. LWS_Send(message);
  8677. result = TRUE;
  8678. return result;
  8679. }
  8680. int sendCertificateSignedConfirmation(char *uuid)
  8681. {
  8682. mtrace();
  8683. int result = PASS;
  8684. char message[4096]={0};
  8685. json_object *CertificateSigned = json_object_new_object();
  8686. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8687. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8688. sprintf(message,"[%d,\"%s\",%s]"
  8689. ,MESSAGE_TYPE_CALLRESULT
  8690. ,uuid
  8691. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8692. json_object_put(CertificateSigned);
  8693. LWS_Send(message);
  8694. return result;
  8695. }
  8696. int sendDeleteCertificateConfirmation(char *uuid)
  8697. {
  8698. mtrace();
  8699. int result = PASS;
  8700. char message[4096]={0};
  8701. json_object *DeleteCertificate = json_object_new_object();
  8702. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8703. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8704. sprintf(message,"[%d,\"%s\",%s]"
  8705. ,MESSAGE_TYPE_CALLRESULT
  8706. ,uuid
  8707. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8708. json_object_put(DeleteCertificate);
  8709. LWS_Send(message);
  8710. return result;
  8711. }
  8712. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8713. {
  8714. mtrace();
  8715. int result = PASS;
  8716. char message[4096]={0};
  8717. json_object *ExtendedTriggerMessage = json_object_new_object();
  8718. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8719. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8720. sprintf(message,"[%d,\"%s\",%s]"
  8721. ,MESSAGE_TYPE_CALLRESULT
  8722. ,uuid
  8723. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8724. json_object_put(ExtendedTriggerMessage);
  8725. LWS_Send(message);
  8726. return result;
  8727. }
  8728. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8729. {
  8730. mtrace();
  8731. int result = PASS;
  8732. char message[4096]={0};
  8733. json_object *GetInstalledCertificateIds = json_object_new_object();
  8734. json_object *certificateHashDataDatas = json_object_new_array();
  8735. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8736. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8737. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8738. {
  8739. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8740. {
  8741. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm) > 0)
  8742. {
  8743. json_object *certificateHashData = json_object_new_object();
  8744. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8745. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8746. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8747. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8748. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8749. }
  8750. }
  8751. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8752. }
  8753. else
  8754. {
  8755. json_object_put(certificateHashDataDatas);
  8756. }
  8757. sprintf(message,"[%d,\"%s\",%s]"
  8758. ,MESSAGE_TYPE_CALLRESULT
  8759. ,uuid
  8760. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8761. json_object_put(GetInstalledCertificateIds);
  8762. LWS_Send(message);
  8763. return result;
  8764. }
  8765. int sendGetLogConfirmation(char *uuid)
  8766. {
  8767. mtrace();
  8768. int result = PASS;
  8769. char message[4096]={0};
  8770. json_object *GetLog = json_object_new_object();
  8771. DEBUG_INFO("sendGetLogConfirmation...\n");
  8772. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8773. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8774. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8775. sprintf(message,"[%d,\"%s\",%s]"
  8776. ,MESSAGE_TYPE_CALLRESULT
  8777. ,uuid
  8778. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8779. json_object_put(GetLog);
  8780. LWS_Send(message);
  8781. return result;
  8782. }
  8783. int sendInstallCertificateConfirmation(char *uuid)
  8784. {
  8785. mtrace();
  8786. int result = PASS;
  8787. char message[4096]={0};
  8788. json_object *InstallCertificate = json_object_new_object();
  8789. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8790. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8791. sprintf(message,"[%d,\"%s\",%s]"
  8792. ,MESSAGE_TYPE_CALLRESULT
  8793. ,uuid
  8794. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8795. json_object_put(InstallCertificate);
  8796. LWS_Send(message);
  8797. return result;
  8798. }
  8799. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8800. {
  8801. mtrace();
  8802. int result = PASS;
  8803. char message[4096]={0};
  8804. json_object *SignedUpdateFirmware = json_object_new_object();
  8805. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8806. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8807. sprintf(message,"[%d,\"%s\",%s]"
  8808. ,MESSAGE_TYPE_CALLRESULT
  8809. ,uuid
  8810. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8811. json_object_put(SignedUpdateFirmware);
  8812. LWS_Send(message);
  8813. return result;
  8814. }
  8815. int sendUnknownConfirmation(char *uuid)
  8816. {
  8817. mtrace();
  8818. int result = PASS;
  8819. char message[256]={0};
  8820. DEBUG_INFO("sendUnknownConfirmation...\n");
  8821. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8822. LWS_Send(message);
  8823. return result;
  8824. }
  8825. //==========================================
  8826. // Handle server request routine Start
  8827. //==========================================
  8828. int handleCancelReservationRequest(char *uuid, char *payload)
  8829. {
  8830. mtrace();
  8831. int result = FAIL;
  8832. int gunNO = 0;
  8833. int reservationIdInt = -1;
  8834. char comfirmstr[20];
  8835. DEBUG_INFO("handleCancelReservationRequest...\n");
  8836. json_object *CancelReservation;
  8837. CancelReservation = json_tokener_parse(payload);
  8838. if(!is_error(CancelReservation))
  8839. {
  8840. // Required data
  8841. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8842. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8843. }
  8844. json_object_put(CancelReservation);
  8845. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8846. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8847. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8848. if(reservationIdInt != -1)
  8849. {
  8850. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8851. //check Transaction active
  8852. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8853. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8854. {
  8855. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8856. {
  8857. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8858. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8859. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8860. {
  8861. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8862. }
  8863. else
  8864. {
  8865. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8866. }
  8867. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8868. goto end;
  8869. }
  8870. }
  8871. for (int index = 0; index < CCS_QUANTITY; index++)
  8872. {
  8873. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8874. {
  8875. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8876. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8877. if(gunType[2] == GUN_TYPE_CCS)
  8878. {
  8879. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8880. }
  8881. else
  8882. {
  8883. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8884. }
  8885. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8886. goto end;
  8887. }
  8888. }
  8889. for (int index = 0; index < GB_QUANTITY; index++)
  8890. {
  8891. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8892. {
  8893. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8894. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8895. if(gunType[2] == GUN_TYPE_GBT)
  8896. {
  8897. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8898. }
  8899. else
  8900. {
  8901. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8902. }
  8903. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8904. goto end;
  8905. }
  8906. }
  8907. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8908. {
  8909. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8910. {
  8911. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8912. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8913. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8914. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8915. goto end;
  8916. }
  8917. }
  8918. for (int index = 0; index < AC_QUANTITY; index++)
  8919. {
  8920. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8921. {
  8922. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8923. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8924. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8925. {
  8926. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8927. }
  8928. else
  8929. {
  8930. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8931. }
  8932. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8933. goto end;
  8934. }
  8935. }
  8936. }
  8937. //The reservationId does NOT match the reservationId
  8938. sendCancelReservationConfirmation(uuid, comfirmstr);
  8939. end:
  8940. // Fill in ocpp packet uuid
  8941. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8942. return result;
  8943. }
  8944. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8945. {
  8946. mtrace();
  8947. int result = FAIL;
  8948. int gunIndex = -1;
  8949. char typeStr[16]={0};
  8950. char comfirmstr[20];
  8951. int specificId = FALSE;
  8952. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8953. json_object *ChangeAvailability;
  8954. ChangeAvailability = json_tokener_parse(payload);
  8955. if(!is_error(ChangeAvailability))
  8956. {
  8957. // Required data
  8958. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8959. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8960. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8961. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8962. }
  8963. json_object_put(ChangeAvailability);
  8964. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8965. {
  8966. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8967. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8968. }
  8969. else if(gunIndex == 0)
  8970. {
  8971. for(int i=0; i < gunTotalNumber; i++)
  8972. {
  8973. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8974. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8975. }
  8976. }
  8977. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8978. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8979. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8980. {
  8981. specificId = TRUE;
  8982. }
  8983. if(specificId == FALSE)
  8984. goto end;
  8985. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8986. {
  8987. //----------------------gunIndex is 0 ------------------------------------------------//
  8988. if(gunIndex == 0)
  8989. {
  8990. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8991. {
  8992. for(int i=0; i < gunTotalNumber; i++)
  8993. {
  8994. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8995. {
  8996. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8997. {
  8998. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8999. {
  9000. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9001. goto end;
  9002. }
  9003. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9004. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9005. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9006. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9007. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9008. {
  9009. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9010. goto end;
  9011. }
  9012. }
  9013. }//END FOR CHAdeMO_QUANTITY
  9014. for (int index = 0; index < CCS_QUANTITY; index++)
  9015. {
  9016. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  9017. {
  9018. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  9019. {
  9020. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9021. goto end;
  9022. }
  9023. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9024. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9025. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9026. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9027. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9028. {
  9029. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9030. goto end;
  9031. }
  9032. }
  9033. }//END FOR CCS_QUANTITY
  9034. for (int index = 0; index < GB_QUANTITY; index++)
  9035. {
  9036. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  9037. {
  9038. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  9039. {
  9040. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9041. goto end;
  9042. }
  9043. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9044. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9045. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9046. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9047. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9048. {
  9049. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9050. goto end;
  9051. }
  9052. }
  9053. }// END FOR GB_QUANTITY
  9054. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9055. {
  9056. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  9057. {
  9058. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  9059. {
  9060. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9061. goto end;
  9062. }
  9063. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  9064. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  9065. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9066. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  9067. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9068. {
  9069. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9070. goto end;
  9071. }
  9072. }
  9073. }// END FOR GENERAL_GUN_QUANTITY
  9074. for (int index = 0; index < AC_QUANTITY; index++)
  9075. {
  9076. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  9077. {
  9078. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  9079. {
  9080. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9081. goto end;
  9082. }
  9083. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9084. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9085. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9086. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9087. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9088. {
  9089. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9090. goto end;
  9091. }
  9092. }
  9093. }//END FOR AC_QUANTITY
  9094. }// END FOR gunTotalNumber
  9095. }
  9096. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  9097. {
  9098. for(int i=0; i < gunTotalNumber; i++)
  9099. {
  9100. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  9101. {
  9102. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9103. goto end;
  9104. }
  9105. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9106. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  9107. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  9108. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  9109. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9110. {
  9111. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9112. goto end;
  9113. }
  9114. }
  9115. }
  9116. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9117. goto end;
  9118. }
  9119. //----------------------gunIndex is not 0 ------------------------------------------------//
  9120. //check Transaction active
  9121. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9122. {
  9123. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  9124. {
  9125. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  9126. {
  9127. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9128. goto end;
  9129. }
  9130. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9131. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9132. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9133. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9134. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9135. {
  9136. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9137. goto end;
  9138. }
  9139. else
  9140. {
  9141. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  9142. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9143. goto end;
  9144. }
  9145. }
  9146. }//END FOR CHAdeMO_QUANTITY
  9147. for (int index = 0; index < CCS_QUANTITY; index++)
  9148. {
  9149. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  9150. {
  9151. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  9152. {
  9153. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9154. goto end;
  9155. }
  9156. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9157. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9158. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9159. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9160. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9161. {
  9162. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9163. goto end;
  9164. }
  9165. else
  9166. {
  9167. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  9168. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9169. goto end;
  9170. }
  9171. }
  9172. }//END FOR CCS_QUANTITY
  9173. for (int index = 0; index < GB_QUANTITY; index++)
  9174. {
  9175. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  9176. {
  9177. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  9178. {
  9179. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9180. goto end;
  9181. }
  9182. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9183. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9184. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9185. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9186. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9187. {
  9188. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9189. goto end;
  9190. }
  9191. else
  9192. {
  9193. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  9194. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9195. goto end;
  9196. }
  9197. }
  9198. }// END FOR GB_QUANTITY
  9199. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9200. {
  9201. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  9202. {
  9203. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  9204. {
  9205. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9206. goto end;
  9207. }
  9208. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  9209. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  9210. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9211. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  9212. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9213. {
  9214. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9215. goto end;
  9216. }
  9217. else
  9218. {
  9219. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  9220. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9221. goto end;
  9222. }
  9223. }
  9224. }// END FOR GENERAL_GUN_QUANTITY
  9225. for (int index = 0; index < AC_QUANTITY; index++)
  9226. {
  9227. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  9228. {
  9229. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  9230. {
  9231. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9232. goto end;
  9233. }
  9234. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9235. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9236. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9237. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9238. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9239. {
  9240. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9241. goto end;
  9242. }
  9243. else
  9244. {
  9245. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  9246. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9247. goto end;
  9248. }
  9249. }
  9250. }//END FOR AC_QUANTITY
  9251. }//END FOR AvailabilityTypeStr[Inoperative]
  9252. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  9253. {
  9254. //----------------------gunIndex is 0 ------------------------------------------------//
  9255. if(gunIndex == 0)
  9256. {
  9257. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9258. {
  9259. for(int i=0; i < gunTotalNumber; i++)
  9260. {
  9261. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9262. {
  9263. 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
  9264. {
  9265. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9266. goto end;
  9267. }
  9268. }//END FOR CHAdeMO_QUANTITY
  9269. for (int index = 0; index < CCS_QUANTITY; index++)
  9270. {
  9271. 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
  9272. {
  9273. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9274. goto end;
  9275. }
  9276. }//END FOR CCS_QUANTITY
  9277. for (int index = 0; index < GB_QUANTITY; index++)
  9278. {
  9279. 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
  9280. {
  9281. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9282. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9283. goto end;
  9284. }
  9285. }// END FOR GB_QUANTITY
  9286. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9287. {
  9288. 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
  9289. {
  9290. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9291. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9292. goto end;
  9293. }
  9294. }// END FOR GENERAL_GUN_QUANTITY
  9295. for (int index = 0; index < AC_QUANTITY; index++)
  9296. {
  9297. 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
  9298. {
  9299. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9300. goto end;
  9301. }
  9302. }//END FOR CHAdeMO_QUANTITY
  9303. }// END FOR gunTotalNumber
  9304. }
  9305. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  9306. {
  9307. for(int i=0; i < gunTotalNumber; i++)
  9308. {
  9309. for (int index = 0; index < AC_QUANTITY; index++)
  9310. {
  9311. 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
  9312. {
  9313. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9314. goto end;
  9315. }
  9316. }//END FOR CHAdeMO_QUANTITY
  9317. } // END FOR gunTotalNumber
  9318. }
  9319. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9320. goto end;
  9321. }
  9322. //----------------------gunIndex is not 0 ------------------------------------------------//
  9323. //check Transaction active
  9324. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9325. {
  9326. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9327. {
  9328. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9329. goto end;
  9330. }
  9331. }//END FOR CHAdeMO_QUANTITY
  9332. for (int index = 0; index < CCS_QUANTITY; index++)
  9333. {
  9334. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9335. {
  9336. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9337. goto end;
  9338. }
  9339. }//END FOR CCS_QUANTITY
  9340. for (int index = 0; index < GB_QUANTITY; index++)
  9341. {
  9342. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9343. {
  9344. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9345. goto end;
  9346. }
  9347. }// END FOR GB_QUANTITY
  9348. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9349. {
  9350. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9351. {
  9352. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9353. goto end;
  9354. }
  9355. }// END FOR GENERAL_GUN_QUANTITY
  9356. for (int index = 0; index < AC_QUANTITY; index++)
  9357. {
  9358. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9359. {
  9360. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9361. goto end;
  9362. }
  9363. }//END FOR AC_QUANTITY
  9364. }//END FOR AvailabilityTypeStr[Operative]
  9365. end:
  9366. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9367. {
  9368. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  9369. }
  9370. else
  9371. {
  9372. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  9373. }
  9374. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9375. {
  9376. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9377. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9378. }
  9379. else if(gunIndex == 0)
  9380. {
  9381. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9382. {
  9383. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  9384. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  9385. }
  9386. }
  9387. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  9388. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9389. return result;
  9390. }
  9391. int handleChangeConfigurationRequest(char *uuid, char *payload)
  9392. {
  9393. mtrace();
  9394. int valueInvalid = NO;
  9395. int result = FAIL;
  9396. char keystr[40]={0};
  9397. char valuestr[501]={0}; //value should be limited in 500 bytes
  9398. char comfirmstr[20]={0};
  9399. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  9400. json_object *ChangeConfiguration;
  9401. ChangeConfiguration = json_tokener_parse(payload);
  9402. if(!is_error(ChangeConfiguration))
  9403. {
  9404. // Required data
  9405. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  9406. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  9407. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  9408. {
  9409. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  9410. }
  9411. else
  9412. {
  9413. valueInvalid = YES;
  9414. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  9415. }
  9416. }
  9417. json_object_put(ChangeConfiguration);
  9418. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  9419. {
  9420. DEBUG_ERROR("Payload is null or value is invalid.\n");
  9421. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9422. }
  9423. else
  9424. {
  9425. int status = setKeyValue(keystr, valuestr);
  9426. switch(status)
  9427. {
  9428. case ConfigurationStatus_Accepted:
  9429. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  9430. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  9431. StoreConfigurationTable();
  9432. break;
  9433. case RebootRequired:
  9434. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  9435. StoreConfigurationTable();
  9436. break;
  9437. case NotSupported:
  9438. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  9439. break;
  9440. case ConfigurationStatus_Rejected:
  9441. default:
  9442. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9443. break;
  9444. }
  9445. }
  9446. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  9447. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  9448. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9449. {
  9450. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9451. SetOcppConnStatus(FALSE);
  9452. }
  9453. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9454. {
  9455. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9456. }
  9457. return result;
  9458. }
  9459. int handleClearCacheRequest(char *uuid, char *payload)
  9460. {
  9461. mtrace();
  9462. int result = FAIL;
  9463. char comfirmstr[20];
  9464. char rmFileCmd[100]={0};
  9465. struct stat stats;
  9466. DEBUG_INFO("handleClearCacheRequest...\n");
  9467. stat("/Storage/OCPP", &stats);
  9468. // Check for directory existence
  9469. if (S_ISDIR(stats.st_mode) == 1)
  9470. {}
  9471. else
  9472. {
  9473. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  9474. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  9475. system(rmFileCmd);
  9476. }
  9477. if(OCPP_cleanLocalCache())
  9478. {
  9479. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  9480. }
  9481. else
  9482. {
  9483. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  9484. }
  9485. sendClearCacheConfirmation(uuid, comfirmstr);
  9486. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9487. return result;
  9488. }
  9489. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9490. {
  9491. mtrace();
  9492. int result = FAIL;
  9493. int resultRename;
  9494. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9495. char chargingProfilePurposeStr[26]={0};
  9496. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9497. char tempchargingProfilePurposeStr[26]={0};
  9498. char str[100]={0};
  9499. char fname[200]={0};
  9500. char comfirmstr[20]={0};
  9501. char word[1600]={0};
  9502. int clearflag = FALSE;
  9503. int chargingProfileIdIsNULL = FALSE;
  9504. int connectorIsNULL = FALSE;
  9505. int chargingProfilePurposeIsNULL = FALSE;
  9506. int stackLevelIsNULL = FALSE;
  9507. //int GotoEnd = FALSE;
  9508. FILE *fptr1, *fptr2;
  9509. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9510. int n_chargingProfile=0;
  9511. int isEmptyFile = FALSE;
  9512. char sLineWord[1600]={0};
  9513. char chargingProfiles[10][100]={0};
  9514. int ChargeProfileCount = 0;
  9515. int ch;
  9516. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9517. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9518. json_object *ClearChargingProfile;
  9519. ClearChargingProfile = json_tokener_parse(payload);
  9520. if(!is_error(ClearChargingProfile))
  9521. {
  9522. // Optional data
  9523. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9524. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9525. else
  9526. chargingProfileIdIsNULL = TRUE;
  9527. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9528. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9529. else
  9530. connectorIsNULL = TRUE;
  9531. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9532. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9533. else
  9534. chargingProfilePurposeIsNULL = TRUE;
  9535. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9536. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9537. else
  9538. stackLevelIsNULL = TRUE;
  9539. }
  9540. json_object_put(ClearChargingProfile);
  9541. if(connectorIsNULL == FALSE)
  9542. {
  9543. switch(connectorIdInt)
  9544. {
  9545. case 0:
  9546. if(chargingProfilePurposeIsNULL == TRUE)
  9547. {
  9548. int l = 0;
  9549. strcpy(fname, ChargePointMaxProfile_JSON);
  9550. if((access(fname,F_OK))!=-1)
  9551. {
  9552. strcpy(chargingProfiles[l], fname);
  9553. l = l + 1;
  9554. }
  9555. strcpy(fname, TxDefaultProfile_0_JSON);
  9556. if((access(fname,F_OK))!=-1)
  9557. {
  9558. strcpy(chargingProfiles[l], fname);
  9559. l = l + 1;
  9560. }
  9561. ChargeProfileCount = l;
  9562. }
  9563. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  9564. {
  9565. strcpy(fname, ChargePointMaxProfile_JSON);
  9566. if((access(fname,F_OK))!=-1)
  9567. {
  9568. strcpy(chargingProfiles[0], fname);
  9569. ChargeProfileCount = 1;
  9570. }
  9571. }
  9572. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9573. {
  9574. strcpy(fname, TxDefaultProfile_0_JSON);
  9575. if((access(fname,F_OK))!=-1)
  9576. {
  9577. strcpy(chargingProfiles[0], fname);
  9578. ChargeProfileCount = 1;
  9579. }
  9580. }
  9581. break;
  9582. default:
  9583. if(chargingProfilePurposeIsNULL == TRUE)
  9584. {
  9585. int m = 0;
  9586. memset(fname, 0, ARRAY_SIZE(fname));
  9587. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9588. if((access(fname,F_OK))!=-1)
  9589. {
  9590. strcpy(chargingProfiles[m], fname);
  9591. m = m + 1;
  9592. }
  9593. memset(fname, 0, ARRAY_SIZE(fname));
  9594. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9595. if((access(fname,F_OK))!=-1)
  9596. {
  9597. strcpy(chargingProfiles[m], fname);
  9598. m = m + 1;
  9599. }
  9600. ChargeProfileCount = m;
  9601. }
  9602. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9603. {
  9604. //strcpy(fname, TxDefaultProfile_1_JSON);
  9605. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9606. if((access(fname,F_OK))!=-1)
  9607. {
  9608. strcpy(chargingProfiles[0], fname);
  9609. ChargeProfileCount = 1;
  9610. }
  9611. }
  9612. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9613. {
  9614. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9615. if((access(fname,F_OK))!=-1)
  9616. {
  9617. strcpy(chargingProfiles[0], fname);
  9618. ChargeProfileCount = 1;
  9619. }
  9620. //strcpy(fname, TxProfile_1_JSON);
  9621. }
  9622. //strcpy(fname, ChargePointMaxProfile_JSON );
  9623. break;
  9624. }
  9625. }
  9626. else // Check all Charging Profiles
  9627. {
  9628. int i = 0;
  9629. char fnametemp[200]={0};
  9630. ChargeProfileCount = 0;
  9631. //Check ChargePointMaxProfile.json exit
  9632. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9633. {
  9634. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9635. i = i + 1;
  9636. }
  9637. //Check TxDefaultProfile_0.json exit
  9638. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9639. {
  9640. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9641. i = i + 1;
  9642. }
  9643. //Check TxDefaultProfile_%d.json
  9644. for(int j=1; j <= gunTotalNumber; j++)
  9645. {
  9646. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9647. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9648. if((access(fnametemp,F_OK))!=-1)
  9649. {
  9650. strcpy(chargingProfiles[i], fnametemp);
  9651. i = i + 1;
  9652. }
  9653. }
  9654. //Check TxProfile_%d.json
  9655. for(int j=1; j <= gunTotalNumber; j++)
  9656. {
  9657. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9658. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9659. if((access(fnametemp,F_OK))!=-1)
  9660. {
  9661. strcpy(chargingProfiles[i], fnametemp);
  9662. i = i + 1;
  9663. }
  9664. }
  9665. ChargeProfileCount = i;
  9666. }// End connectorIsNULL is TRUE
  9667. if(ChargeProfileCount == 0)
  9668. {
  9669. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9670. goto end;
  9671. }
  9672. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9673. {
  9674. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9675. goto end;
  9676. }
  9677. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9678. {
  9679. memset(str, 0, ARRAY_SIZE(str));
  9680. // clear temp file
  9681. sprintf(str,"rm -f %s",temp);
  9682. system(str);
  9683. for(int k=0; k < ChargeProfileCount; k++)
  9684. {
  9685. memset(str, 0, ARRAY_SIZE(str));
  9686. //clear file in C
  9687. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9688. system(str);
  9689. }
  9690. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9691. goto end;
  9692. }
  9693. else if(connectorIsNULL == TRUE)
  9694. {
  9695. for(int k=0; k < ChargeProfileCount; k++)
  9696. {
  9697. fptr1 = fopen(chargingProfiles[k], "r");
  9698. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9699. //Check Charging Profile Count
  9700. while(fscanf(fptr1, "%s", word) != EOF)
  9701. {
  9702. //DEBUG_INFO("word=%s\n",word);
  9703. if(strstr(word, "chargingProfileId")!= NULL)
  9704. {
  9705. //DEBUG_INFO("test chargingProfileId \n");
  9706. n_chargingProfile = n_chargingProfile + 1;
  9707. //DEBUG_INFO("chargingProfileId Found\n");
  9708. }
  9709. }
  9710. rewind(fptr1);
  9711. //search Charging Profile Element
  9712. //int i= 0;
  9713. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9714. {
  9715. json_object *tmpProfilee;
  9716. tmpProfilee = json_tokener_parse(sLineWord);
  9717. if(!is_error(tmpProfilee))
  9718. {
  9719. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9720. {
  9721. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9722. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9723. }
  9724. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9725. {
  9726. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9727. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9728. }
  9729. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9730. {
  9731. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9732. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9733. }
  9734. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9735. {
  9736. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9737. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9738. }
  9739. }
  9740. json_object_put(tmpProfilee);
  9741. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9742. {
  9743. //------- not write to fptr2-------//
  9744. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9745. //clearflag = TRUE;
  9746. }
  9747. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9748. {
  9749. //------- not write to fptr2-------//
  9750. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9751. }
  9752. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9753. {
  9754. //------- not write to fptr2-------//
  9755. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9756. }
  9757. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9758. {
  9759. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9760. }
  9761. else
  9762. {
  9763. fprintf(fptr2, sLineWord);//writing data into file
  9764. }
  9765. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9766. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9767. if(clearflag == TRUE)
  9768. {
  9769. fclose(fptr1);
  9770. fclose(fptr2);
  9771. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9772. system(str);
  9773. // clear temp file
  9774. sprintf(str,"rm -f %s",temp);
  9775. system(str);
  9776. }
  9777. else
  9778. {
  9779. fclose(fptr1);
  9780. fclose(fptr2);
  9781. memset(str, 0, ARRAY_SIZE(str));
  9782. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9783. system(str);
  9784. resultRename = rename(temp, chargingProfiles[k]);
  9785. if(resultRename == 0)
  9786. {
  9787. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9788. }
  9789. else
  9790. {
  9791. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9792. }
  9793. if(comfirmstr[0]== 0)
  9794. {
  9795. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9796. }
  9797. //Check chargingProfile is empty file
  9798. /*------ Read the file ----------------*/
  9799. fptr1=fopen(chargingProfiles[k],"r");
  9800. ch=fgetc(fptr1);
  9801. rewind(fptr1);
  9802. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9803. if(ch!=EOF)
  9804. {
  9805. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9806. {
  9807. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9808. if(sLineWord[0]=='\0')
  9809. {
  9810. isEmptyFile = TRUE;
  9811. break;
  9812. }
  9813. else
  9814. {
  9815. isEmptyFile = FALSE;
  9816. break;
  9817. }
  9818. }
  9819. }
  9820. else
  9821. isEmptyFile = TRUE;
  9822. fclose(fptr1);
  9823. if(isEmptyFile == TRUE)
  9824. {
  9825. memset(str, 0, ARRAY_SIZE(str));
  9826. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9827. system(str);
  9828. }
  9829. }
  9830. }// End of while(int k=0; k < ChargePointCount; k++)
  9831. }
  9832. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9833. {
  9834. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9835. for(int k=0; k < ChargeProfileCount; k++)
  9836. {
  9837. fptr1 = fopen(chargingProfiles[k], "r");
  9838. fptr2 = fopen(temp, "w+");
  9839. //Check Charging Profile Count
  9840. while(fscanf(fptr1, "%s", word) != EOF)
  9841. {
  9842. //DEBUG_INFO("word=%s\n",word);
  9843. if(strstr(word, "chargingProfileId")!= NULL)
  9844. {
  9845. n_chargingProfile = n_chargingProfile + 1;
  9846. }
  9847. }
  9848. rewind(fptr1);
  9849. //search Charging Profile Element
  9850. //int i= 0;
  9851. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9852. {
  9853. json_object *tmpProfilee;
  9854. tmpProfilee = json_tokener_parse(sLineWord);
  9855. if(!is_error(tmpProfilee))
  9856. {
  9857. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9858. {
  9859. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9860. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9861. }
  9862. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9863. {
  9864. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9865. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9866. }
  9867. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9868. {
  9869. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9870. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9871. }
  9872. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9873. {
  9874. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9875. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9876. }
  9877. }
  9878. json_object_put(tmpProfilee);
  9879. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9880. {
  9881. //------- not write to fptr2-------//
  9882. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9883. //clearflag = TRUE;
  9884. }
  9885. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9886. {
  9887. //------- not write to fptr2-------//
  9888. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9889. }
  9890. else if(stackLevelIsNULL == TRUE)
  9891. {
  9892. //Clear Whole File
  9893. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9894. clearflag = TRUE;
  9895. break;
  9896. }
  9897. else
  9898. {
  9899. fprintf(fptr2, sLineWord);//writing data into file
  9900. }
  9901. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9902. }
  9903. if(clearflag == TRUE)
  9904. {
  9905. fclose(fptr1);
  9906. fclose(fptr2);
  9907. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9908. system(str);
  9909. // clear temp file
  9910. sprintf(str,"rm -f %s",temp);
  9911. system(str);
  9912. }
  9913. else
  9914. {
  9915. fclose(fptr1);
  9916. fclose(fptr2);
  9917. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9918. system(str);
  9919. resultRename = rename(temp, chargingProfiles[k]);
  9920. if(resultRename == 0)
  9921. {
  9922. DEBUG_INFO("File ChargingProfile renamed successfully");
  9923. }
  9924. else
  9925. {
  9926. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9927. }
  9928. if(comfirmstr[0]== 0)
  9929. {
  9930. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9931. }
  9932. //Check chargingProfile is empty file
  9933. /*------ Read the file ----------------*/
  9934. fptr1=fopen(chargingProfiles[k],"r");
  9935. ch=fgetc(fptr1);
  9936. rewind(fptr1);
  9937. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9938. if(ch!=EOF)
  9939. {
  9940. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9941. {
  9942. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9943. if(sLineWord[0]=='\0')
  9944. {
  9945. isEmptyFile = TRUE;
  9946. break;
  9947. }
  9948. else
  9949. {
  9950. isEmptyFile = FALSE;
  9951. break;
  9952. }
  9953. }
  9954. }
  9955. else
  9956. isEmptyFile = TRUE;
  9957. fclose(fptr1);
  9958. if(isEmptyFile == TRUE)
  9959. {
  9960. memset(str, 0, ARRAY_SIZE(str));
  9961. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9962. system(str);
  9963. }
  9964. /*------- End of reading ---------------*/
  9965. }
  9966. } // while(int k=0; k < ChargeProfileCount; k++)
  9967. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9968. end:
  9969. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9970. {
  9971. if(connectorIdInt == 0)
  9972. {
  9973. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9974. {
  9975. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9976. }
  9977. }
  9978. else
  9979. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9980. }
  9981. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9982. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9983. return result;
  9984. }
  9985. void createFirmwareVersionByDataTransfer(void)
  9986. {
  9987. json_object *FirmwareDataTransfer = json_object_new_object();
  9988. // AC & DC model
  9989. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9990. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9991. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9992. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9993. // DC model
  9994. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9995. {
  9996. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9997. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9998. (gunType[3] != GUN_TYPE_UNKNOWN))
  9999. {
  10000. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  10001. }
  10002. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  10003. {
  10004. // DS DM DW
  10005. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  10006. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  10007. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  10008. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  10009. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  10010. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  10011. }
  10012. else
  10013. {
  10014. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  10015. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  10016. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  10017. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  10018. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  10019. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  10020. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  10021. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  10022. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  10023. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  10024. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  10025. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  10026. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  10027. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  10028. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  10029. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  10030. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  10031. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  10032. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  10033. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  10034. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  10035. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  10036. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  10037. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  10038. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  10039. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  10040. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  10041. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  10042. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  10043. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  10044. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  10045. }
  10046. }
  10047. // 4G model
  10048. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  10049. {
  10050. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  10051. }
  10052. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  10053. json_object_put(FirmwareDataTransfer);
  10054. }
  10055. int handleDataTransferRequest(char *uuid, char *payload)
  10056. {
  10057. mtrace();
  10058. json_object *response = json_object_new_object();
  10059. int result = FAIL;
  10060. char tempvendorId[255]={0};
  10061. char tempmessageId[50]={0};
  10062. char tempdata[10240]={0};
  10063. char message[20480]={0};
  10064. DEBUG_INFO("handleDataTransferRequest...\n");
  10065. if((uuid != NULL) && (payload != NULL))
  10066. {
  10067. json_object *DataTransfer;
  10068. DataTransfer = json_tokener_parse(payload);
  10069. if(!is_error(DataTransfer))
  10070. {
  10071. // Required data
  10072. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  10073. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  10074. // Optional data
  10075. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  10076. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  10077. if(json_object_object_get(DataTransfer, "data") != NULL)
  10078. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  10079. result = PASS;
  10080. }
  10081. json_object_put(DataTransfer);
  10082. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  10083. {
  10084. // Send all moudle firmware version on EVSE
  10085. createFirmwareVersionByDataTransfer();
  10086. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10087. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10088. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10089. json_object_put(response);
  10090. }
  10091. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  10092. {
  10093. system("/usr/bin/run_tmate_restart.sh &");
  10094. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10095. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10096. json_object_put(response);
  10097. }
  10098. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  10099. {
  10100. json_object *data;
  10101. data = json_tokener_parse(tempdata);
  10102. if(!is_error(data))
  10103. {
  10104. 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))
  10105. {
  10106. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10107. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  10108. if(json_object_object_get(data, "SOC") != NULL)
  10109. {
  10110. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  10111. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  10112. }
  10113. if(json_object_object_get(data, "Energy") != NULL)
  10114. {
  10115. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  10116. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  10117. }
  10118. if(json_object_object_get(data, "Duration") != NULL)
  10119. {
  10120. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  10121. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  10122. }
  10123. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10124. }
  10125. else
  10126. {
  10127. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10128. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  10129. }
  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, "SetLEDBar") != NULL)
  10141. {
  10142. json_object *data;
  10143. data = json_tokener_parse(tempdata);
  10144. if(!is_error(data))
  10145. {
  10146. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  10147. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  10148. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  10149. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  10150. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  10151. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  10152. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  10153. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  10154. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  10155. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  10156. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10157. }
  10158. else
  10159. {
  10160. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10161. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10162. }
  10163. json_object_put(data);
  10164. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10165. json_object_put(response);
  10166. }
  10167. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  10168. {
  10169. json_object *data;
  10170. data = json_tokener_parse(tempdata);
  10171. if(!is_error(data))
  10172. {
  10173. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  10174. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10175. if(json_object_object_get(data, "idToken") != NULL)
  10176. {
  10177. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  10178. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  10179. }
  10180. else
  10181. {
  10182. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10183. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  10184. }
  10185. if(json_object_object_get(data, "price") != NULL) //v1.0
  10186. {
  10187. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  10188. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  10189. }
  10190. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  10191. {
  10192. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10193. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10194. }
  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("price or priceText not found."));
  10199. }
  10200. }
  10201. else
  10202. {
  10203. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10204. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10205. }
  10206. json_object_put(data);
  10207. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10208. json_object_put(response);
  10209. }
  10210. else if(strstr(tempmessageId, "RunningCost") != NULL)
  10211. {
  10212. json_object *data;
  10213. data = json_tokener_parse(tempdata);
  10214. if(!is_error(data))
  10215. {
  10216. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10217. if(json_object_object_get(data, "txId") != NULL)
  10218. {
  10219. // California pricing V1.0
  10220. DEBUG_INFO("California pricing V1.0\n");
  10221. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  10222. sprintf((char*)dmsVersion, "1.0");
  10223. for(int idx = 0;idx<gunTotalNumber;idx++)
  10224. {
  10225. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10226. {
  10227. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  10228. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  10229. if(json_object_object_get(data, "description") != NULL)
  10230. {
  10231. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  10232. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  10233. }
  10234. else
  10235. {
  10236. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10237. json_object_object_add(response, "data", json_object_new_string("description not found."));
  10238. }
  10239. }
  10240. }
  10241. }
  10242. else if(json_object_object_get(data, "transactionId") != NULL)
  10243. {
  10244. // California pricing V2.0
  10245. DEBUG_INFO("California pricing V2.0\n");
  10246. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  10247. sprintf((char*)dmsVersion, "2.0");
  10248. for(int idx=0;idx<gunTotalNumber;idx++)
  10249. {
  10250. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  10251. {
  10252. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10253. if(json_object_object_get(data, "timestamp") != NULL)
  10254. {
  10255. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  10256. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  10257. }
  10258. else
  10259. {
  10260. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10261. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  10262. }
  10263. if(json_object_object_get(data, "meterValue") != NULL)
  10264. {
  10265. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  10266. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  10267. }
  10268. else
  10269. {
  10270. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10271. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  10272. }
  10273. if(json_object_object_get(data, "cost") != NULL)
  10274. {
  10275. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  10276. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10277. }
  10278. else
  10279. {
  10280. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10281. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10282. }
  10283. if(json_object_object_get(data, "state") != NULL)
  10284. {
  10285. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  10286. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  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("state not found."));
  10292. }
  10293. if(json_object_object_get(data, "chargingPrice") != NULL)
  10294. {
  10295. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  10296. {
  10297. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  10298. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  10299. }
  10300. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  10301. {
  10302. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  10303. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  10304. }
  10305. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  10306. {
  10307. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  10308. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  10309. }
  10310. }
  10311. else
  10312. {
  10313. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10314. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  10315. }
  10316. if(json_object_object_get(data, "idlePrice") != NULL)
  10317. {
  10318. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  10319. {
  10320. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  10321. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  10322. }
  10323. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  10324. {
  10325. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  10326. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  10327. }
  10328. }
  10329. if(json_object_object_get(data, "nextPeriod") != NULL)
  10330. {
  10331. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  10332. {
  10333. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  10334. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  10335. }
  10336. else
  10337. {
  10338. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10339. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  10340. }
  10341. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  10342. {
  10343. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  10344. {
  10345. 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")));
  10346. 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"));
  10347. }
  10348. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  10349. {
  10350. 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")));
  10351. 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"));
  10352. }
  10353. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  10354. {
  10355. 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")));
  10356. 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"));
  10357. }
  10358. }
  10359. else
  10360. {
  10361. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10362. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  10363. }
  10364. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  10365. {
  10366. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  10367. {
  10368. 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")));
  10369. 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"));
  10370. }
  10371. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  10372. {
  10373. 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")));
  10374. 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"));
  10375. }
  10376. }
  10377. }
  10378. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  10379. {
  10380. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  10381. {
  10382. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10383. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10384. }
  10385. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  10386. {
  10387. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  10388. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  10389. }
  10390. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  10391. {
  10392. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  10393. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  10394. }
  10395. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  10396. {
  10397. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10398. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10399. }
  10400. }
  10401. }
  10402. }
  10403. }
  10404. else
  10405. {
  10406. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10407. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10408. }
  10409. }
  10410. else
  10411. {
  10412. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10413. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10414. }
  10415. json_object_put(data);
  10416. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10417. json_object_put(response);
  10418. }
  10419. else if(strstr(tempmessageId, "FinalCost") != NULL)
  10420. {
  10421. json_object *data;
  10422. data = json_tokener_parse(tempdata);
  10423. if(!is_error(data))
  10424. {
  10425. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10426. if(json_object_object_get(data, "txId") != NULL)
  10427. {
  10428. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  10429. for(int idx = 0;idx<gunTotalNumber;idx++)
  10430. {
  10431. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10432. {
  10433. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10434. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  10435. if(json_object_object_get(data, "description") != NULL)
  10436. {
  10437. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  10438. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  10439. }
  10440. else
  10441. {
  10442. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10443. json_object_object_add(response, "data", json_object_new_string("description not found."));
  10444. }
  10445. }
  10446. }
  10447. }
  10448. else if(json_object_object_get(data, "transactionId") != NULL)
  10449. {
  10450. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  10451. for(int idx = 0;idx<gunTotalNumber;idx++)
  10452. {
  10453. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  10454. {
  10455. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10456. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10457. if(json_object_object_get(data, "cost") != NULL)
  10458. {
  10459. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  10460. ShmOCPP16Data->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10461. }
  10462. else
  10463. {
  10464. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10465. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10466. }
  10467. if(json_object_object_get(data, "priceText") != NULL)
  10468. {
  10469. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10470. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10471. }
  10472. else
  10473. {
  10474. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10475. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  10476. }
  10477. if(json_object_object_get(data, "qrCodeText") != NULL)
  10478. {
  10479. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10480. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10481. }
  10482. }
  10483. }
  10484. }
  10485. else
  10486. {
  10487. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10488. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10489. }
  10490. }
  10491. else
  10492. {
  10493. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10494. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10495. }
  10496. json_object_put(data);
  10497. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10498. json_object_put(response);
  10499. }
  10500. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  10501. {
  10502. json_object *data;
  10503. data = json_tokener_parse(tempdata);
  10504. if(!is_error(data))
  10505. {
  10506. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10507. if(json_object_object_get(data, "Content_Type") != NULL)
  10508. {
  10509. 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))
  10510. {
  10511. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10512. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10513. {
  10514. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10515. }
  10516. }
  10517. else
  10518. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10519. }
  10520. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10521. }
  10522. else
  10523. {
  10524. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10525. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10526. }
  10527. json_object_put(data);
  10528. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10529. json_object_put(response);
  10530. }
  10531. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  10532. {
  10533. json_object *data;
  10534. data = json_tokener_parse(tempdata);
  10535. if(!is_error(data))
  10536. {
  10537. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10538. if(json_object_object_get(data, "ConnectorId") != NULL)
  10539. {
  10540. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  10541. }
  10542. if(json_object_object_get(data, "SerialNo") != NULL)
  10543. {
  10544. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  10545. }
  10546. if(json_object_object_get(data, "Page_Index") != NULL)
  10547. {
  10548. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10549. }
  10550. if(json_object_object_get(data, "Duration") != NULL)
  10551. {
  10552. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10553. }
  10554. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  10555. }
  10556. else
  10557. {
  10558. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10559. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10560. }
  10561. json_object_put(data);
  10562. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10563. json_object_put(response);
  10564. }
  10565. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  10566. {
  10567. json_object *data;
  10568. data = json_tokener_parse(tempdata);
  10569. if(!is_error(data))
  10570. {
  10571. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10572. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10573. {
  10574. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10575. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10576. else
  10577. {
  10578. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10579. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10580. }
  10581. }
  10582. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10583. {
  10584. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10585. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10586. else
  10587. {
  10588. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10589. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10590. }
  10591. }
  10592. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  10593. {
  10594. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  10595. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  10596. else
  10597. {
  10598. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10599. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10600. }
  10601. }
  10602. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  10603. {
  10604. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  10605. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  10606. else
  10607. {
  10608. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10609. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10610. }
  10611. }
  10612. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10613. {
  10614. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10615. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10616. else
  10617. {
  10618. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10619. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10620. }
  10621. }
  10622. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10623. {
  10624. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10625. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10626. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10627. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10628. else
  10629. {
  10630. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10631. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10632. }
  10633. }
  10634. if(json_object_object_get(data, "isAuthentication") != NULL)
  10635. {
  10636. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10637. {
  10638. case 0:
  10639. case 1:
  10640. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10641. break;
  10642. default:
  10643. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10644. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10645. break;
  10646. }
  10647. }
  10648. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10649. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10650. }
  10651. else
  10652. {
  10653. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10654. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10655. }
  10656. json_object_put(data);
  10657. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10658. json_object_put(response);
  10659. }
  10660. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10661. {
  10662. json_object *data;
  10663. data = json_tokener_parse(tempdata);
  10664. if(!is_error(data))
  10665. {
  10666. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10667. {
  10668. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10669. {
  10670. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10671. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10672. }
  10673. else
  10674. {
  10675. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10676. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10677. }
  10678. }
  10679. else
  10680. {
  10681. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10682. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10683. }
  10684. }
  10685. else
  10686. {
  10687. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10688. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10689. }
  10690. json_object_put(data);
  10691. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10692. json_object_put(response);
  10693. }
  10694. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10695. {
  10696. json_object *data;
  10697. data = json_tokener_parse(tempdata);
  10698. if(!is_error(data))
  10699. {
  10700. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10701. if(json_object_object_get(data, "stationName") != NULL)
  10702. {
  10703. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10704. }
  10705. else
  10706. {
  10707. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10708. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10709. }
  10710. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10711. {
  10712. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10713. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10714. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10715. }
  10716. }
  10717. else
  10718. {
  10719. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10720. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10721. }
  10722. json_object_put(data);
  10723. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10724. json_object_put(response);
  10725. }
  10726. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10727. {
  10728. json_object *data;
  10729. data = json_tokener_parse(tempdata);
  10730. if(!is_error(data))
  10731. {
  10732. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10733. if(json_object_object_get(data, "weatherId") != NULL)
  10734. {
  10735. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10736. }
  10737. else
  10738. {
  10739. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10740. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10741. }
  10742. if(json_object_object_get(data, "Temperature") != NULL)
  10743. {
  10744. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10745. }
  10746. else
  10747. {
  10748. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10749. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10750. }
  10751. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10752. {
  10753. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10754. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10755. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10756. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10757. );
  10758. }
  10759. }
  10760. else
  10761. {
  10762. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10763. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10764. }
  10765. json_object_put(data);
  10766. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10767. json_object_put(response);
  10768. }
  10769. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10770. {
  10771. json_object *data;
  10772. data = json_tokener_parse(tempdata);
  10773. if(!is_error(data))
  10774. {
  10775. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10776. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10777. {
  10778. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10779. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10780. }
  10781. else
  10782. {
  10783. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10784. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10785. }
  10786. }
  10787. else
  10788. {
  10789. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10790. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10791. }
  10792. json_object_put(data);
  10793. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10794. json_object_put(response);
  10795. }
  10796. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10797. {
  10798. json_object *data;
  10799. data = json_tokener_parse(tempdata);
  10800. if(!is_error(data))
  10801. {
  10802. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10803. {
  10804. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10805. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10806. if(gun_index < gunTotalNumber)
  10807. {
  10808. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10809. {
  10810. json_object *responsedata = json_object_new_object();
  10811. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10812. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10813. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10814. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10815. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10816. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10817. }
  10818. else
  10819. {
  10820. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10821. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10822. }
  10823. }
  10824. else
  10825. {
  10826. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10827. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10828. }
  10829. }
  10830. else
  10831. {
  10832. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10833. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10834. }
  10835. }
  10836. else
  10837. {
  10838. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10839. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10840. }
  10841. json_object_put(data);
  10842. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10843. json_object_put(response);
  10844. }
  10845. else if(strstr(tempmessageId, "ID_OccupancyFeeDisplay") != NULL)
  10846. {
  10847. json_object *data;
  10848. data = json_tokener_parse(tempdata);
  10849. if(!is_error(data))
  10850. {
  10851. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10852. int gun_index = 0;
  10853. if(json_object_object_get(data, "ConnectorId") != NULL)
  10854. {
  10855. gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  10856. if(json_object_object_get(data, "occupancySN") != NULL)
  10857. {
  10858. sprintf((char *)ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].occupancySN, "%s", json_object_get_string(json_object_object_get(data,"occupancySN")));
  10859. }
  10860. else
  10861. {
  10862. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10863. json_object_object_add(response, "data", json_object_new_string("occupancySN data can not get."));
  10864. }
  10865. if(json_object_object_get(data, "actionId") != NULL)
  10866. {
  10867. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].actionId = json_object_get_int(json_object_object_get(data,"actionId"));
  10868. }
  10869. else
  10870. {
  10871. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10872. json_object_object_add(response, "data", json_object_new_string("actionId data can not get."));
  10873. }
  10874. }
  10875. else
  10876. {
  10877. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10878. json_object_object_add(response, "data", json_object_new_string("ConnectorId data can not get."));
  10879. }
  10880. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10881. {
  10882. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].OccupancyFeeDisplayReq = 1;
  10883. }
  10884. }
  10885. else
  10886. {
  10887. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10888. json_object_object_add(response, "data", json_object_new_string("OccupancyFeeDisplay content got something wrong."));
  10889. }
  10890. json_object_put(data);
  10891. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10892. json_object_put(response);
  10893. }
  10894. else if(strstr(tempmessageId, "ID_SetOccupancyPrice") != NULL)
  10895. {
  10896. json_object *data;
  10897. data = json_tokener_parse(tempdata);
  10898. if(!is_error(data))
  10899. {
  10900. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10901. if(json_object_object_get(data, "price") != NULL)
  10902. {
  10903. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.price = json_object_get_double(json_object_object_get(data,"price"));
  10904. }
  10905. else
  10906. {
  10907. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10908. json_object_object_add(response, "data", json_object_new_string("price data can not get."));
  10909. }
  10910. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10911. {
  10912. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.SetOccupancyPriceReq = 1;
  10913. }
  10914. }
  10915. else
  10916. {
  10917. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10918. json_object_object_add(response, "data", json_object_new_string("SetOccupancyPrice content got something wrong."));
  10919. }
  10920. json_object_put(data);
  10921. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10922. json_object_put(response);
  10923. }
  10924. // Support ISO-15118 related message
  10925. else if(strstr(tempmessageId, "TriggerMessage") != NULL)
  10926. {
  10927. char cmdBuf[1024]={0};
  10928. 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);
  10929. system(cmdBuf);
  10930. ShmOCPP16Data->v2g_extend.SignCertificateReq = 1;
  10931. json_object *responsedata = json_object_new_object();
  10932. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10933. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10934. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10935. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10936. json_object_put(response);
  10937. }
  10938. else if(strstr(tempmessageId, "CertificateSigned") != NULL)
  10939. {
  10940. json_object *data;
  10941. data = json_tokener_parse(tempdata);
  10942. if(!is_error(data))
  10943. {
  10944. FILE *fp = fopen(CERTIFICATE_V2G, "w");
  10945. fprintf(fp, "%s", json_object_get_string(json_object_object_get(data, "certificateChain")));
  10946. fclose(fp);
  10947. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10948. json_object *responsedata = json_object_new_object();
  10949. if(certVerify(PRIVATE_KEY_V2G, CERTIFICATE_V2G) == PASS)
  10950. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10951. else
  10952. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10953. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10954. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10955. }
  10956. else
  10957. {
  10958. json_object *responsedata = json_object_new_object();
  10959. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10960. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10961. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10962. }
  10963. json_object_put(data);
  10964. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10965. json_object_put(response);
  10966. }
  10967. else if(strstr(tempmessageId, "DeleteCertificate") != NULL)
  10968. {
  10969. json_object *data;
  10970. data = json_tokener_parse(tempdata);
  10971. DEBUG_INFO("DeleteCertificate processing...\n");
  10972. if(!is_error(data))
  10973. {
  10974. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm") != NULL)
  10975. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm")));
  10976. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash") != NULL)
  10977. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash")));
  10978. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash") != NULL)
  10979. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash")));
  10980. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber") != NULL)
  10981. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber")));
  10982. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm);
  10983. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash);
  10984. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash);
  10985. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber);
  10986. char temp[256] = {0};
  10987. char compareData[256] = {0};
  10988. int isMatch = TRUE;
  10989. // Check certV2G
  10990. if(access(CERTIFICATE_V2G,F_OK) != -1)
  10991. {
  10992. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_SerialNumber, compareData);
  10993. if(strcmp(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber) != 0)
  10994. isMatch = FALSE;
  10995. if(isMatch == TRUE)
  10996. {
  10997. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerNameHash, compareData);
  10998. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  10999. isMatch = FALSE;
  11000. }
  11001. if(isMatch == TRUE)
  11002. {
  11003. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerKeyHash, compareData);
  11004. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  11005. isMatch = FALSE;
  11006. }
  11007. if(isMatch == TRUE)
  11008. {
  11009. sprintf(temp, "rm -f %s", CERTIFICATE_V2G);
  11010. system(temp);
  11011. json_object *responsedata = json_object_new_object();
  11012. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  11013. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11014. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  11015. }
  11016. else
  11017. {
  11018. json_object *responsedata = json_object_new_object();
  11019. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  11020. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11021. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  11022. }
  11023. }
  11024. else
  11025. {
  11026. json_object *responsedata = json_object_new_object();
  11027. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  11028. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11029. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  11030. }
  11031. }
  11032. else
  11033. {
  11034. json_object *responsedata = json_object_new_object();
  11035. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  11036. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11037. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  11038. }
  11039. json_object_put(data);
  11040. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  11041. json_object_put(response);
  11042. }
  11043. else if(strstr(tempmessageId, "GetInstalledCertificateIds") != NULL)
  11044. {
  11045. json_object *data;
  11046. data = json_tokener_parse(tempdata);
  11047. if(!is_error(data))
  11048. {
  11049. /*
  11050. * TODO:
  11051. * 1. Query certificate to response
  11052. */
  11053. json_object *responsedata = json_object_new_object();
  11054. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  11055. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11056. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  11057. }
  11058. else
  11059. {
  11060. json_object *responsedata = json_object_new_object();
  11061. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  11062. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11063. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  11064. }
  11065. json_object_put(data);
  11066. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  11067. json_object_put(response);
  11068. }
  11069. else if(strstr(tempmessageId, "InstallCertificate") != NULL)
  11070. {
  11071. json_object *data;
  11072. data = json_tokener_parse(tempdata);
  11073. if(!is_error(data))
  11074. {
  11075. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  11076. if(json_object_object_get(data, "certificateType") != NULL)
  11077. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(data, "certificateType")));
  11078. if(json_object_object_get(data, "certificate") != NULL)
  11079. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(data, "certificate")));
  11080. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType);
  11081. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  11082. char temp[1024];
  11083. FILE *fp = fopen(tempCert, "w");
  11084. fprintf(fp, "%s", ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  11085. fclose(fp);
  11086. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  11087. char strExpDate[30];
  11088. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  11089. fp = popen(temp, "r");
  11090. if(fp)
  11091. {
  11092. while(fgets(temp, sizeof(temp), fp) != NULL)
  11093. {
  11094. if(strstr(temp, "notAfter=") != NULL)
  11095. {
  11096. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  11097. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  11098. break;
  11099. }
  11100. }
  11101. }
  11102. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  11103. struct tm tmExpDate;
  11104. struct timeb tbExpDate;
  11105. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  11106. tbExpDate.time = mktime(&tmExpDate);
  11107. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  11108. {
  11109. DEBUG_INFO("The enddate is already expired...\n");
  11110. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Rejected");
  11111. }
  11112. else
  11113. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted");
  11114. if(strcmp((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted") == 0)
  11115. {
  11116. if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "V2GRootCertificate") != NULL)
  11117. {
  11118. if(access(ROOTCA_V2G,F_OK) != -1)
  11119. {
  11120. DEBUG_INFO("Existed V2GRootCertificate is found. Replacing...\n");
  11121. rename(ROOTCA_V2G, "/Storage/OCPP/rootCaV2g_fallback.pem");
  11122. rename(tempCert, ROOTCA_V2G);
  11123. }
  11124. else
  11125. {
  11126. DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
  11127. rename(tempCert, ROOTCA_V2G);
  11128. }
  11129. json_object *responsedata = json_object_new_object();
  11130. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  11131. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11132. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  11133. }
  11134. else if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "MORootCertificate") != NULL)
  11135. {
  11136. if(access(ROOTCA_MO,F_OK) != -1)
  11137. {
  11138. DEBUG_INFO("Existed MORootCertificate is found. Replacing...\n");
  11139. rename(ROOTCA_MO, "/Storage/OCPP/rootCaMo_fallback.pem");
  11140. rename(tempCert, ROOTCA_MO);
  11141. }
  11142. else
  11143. {
  11144. DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
  11145. rename(tempCert, ROOTCA_MO);
  11146. }
  11147. json_object *responsedata = json_object_new_object();
  11148. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  11149. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11150. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  11151. }
  11152. else
  11153. {
  11154. json_object *responsedata = json_object_new_object();
  11155. json_object_object_add(responsedata, "status", json_object_new_string("Failed"));
  11156. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11157. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  11158. }
  11159. }
  11160. else
  11161. {
  11162. json_object *responsedata = json_object_new_object();
  11163. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  11164. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11165. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  11166. }
  11167. }
  11168. else
  11169. {
  11170. json_object *responsedata = json_object_new_object();
  11171. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  11172. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11173. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  11174. }
  11175. json_object_put(data);
  11176. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  11177. json_object_put(response);
  11178. }
  11179. else
  11180. {
  11181. // Can not find valid message id
  11182. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  11183. }
  11184. }
  11185. else
  11186. {
  11187. // Payload is null
  11188. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  11189. }
  11190. LWS_Send(message);
  11191. return result;
  11192. }
  11193. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  11194. {
  11195. mtrace();
  11196. int result = FAIL;
  11197. int connectorIdInt, durationInt;
  11198. char chargingRateUnitStr[4]={0};
  11199. char comfirmstr[20];
  11200. int confirmPeriods = 0;
  11201. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  11202. json_object *GetCompositeSchedule;
  11203. GetCompositeSchedule = json_tokener_parse(payload);
  11204. if(!is_error(GetCompositeSchedule))
  11205. {
  11206. // Required data
  11207. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  11208. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  11209. else
  11210. connectorIdInt = -1;
  11211. if(json_object_object_get(GetCompositeSchedule, "duration"))
  11212. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  11213. else
  11214. durationInt = 86400;
  11215. // Optional data
  11216. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  11217. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  11218. }
  11219. json_object_put(GetCompositeSchedule);
  11220. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  11221. if((connectorIdInt == 0) ||
  11222. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  11223. {
  11224. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  11225. struct StructChargingProfile tmpProfile[1];
  11226. if(strstr(chargingRateUnitStr, "W") != NULL)
  11227. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  11228. else
  11229. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  11230. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  11231. {
  11232. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  11233. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  11234. }
  11235. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  11236. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  11237. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  11238. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  11239. {
  11240. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  11241. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  11242. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  11243. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  11244. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  11245. {
  11246. confirmPeriods = idx;
  11247. break;
  11248. }
  11249. }
  11250. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  11251. {
  11252. confirmPeriods += 1;
  11253. }
  11254. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  11255. }
  11256. else
  11257. {
  11258. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  11259. }
  11260. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  11261. return result;
  11262. }
  11263. int handleGetConfigurationRequest(char *uuid, char *payload)
  11264. {
  11265. mtrace();
  11266. int result = FAIL;
  11267. int MaxKeySupported = 0;
  11268. int n_keys = 0;
  11269. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  11270. DEBUG_INFO("handleGetConfigurationRequest...\n");
  11271. json_object *GetConfiguration;
  11272. GetConfiguration = json_tokener_parse(payload);
  11273. if(!is_error(GetConfiguration))
  11274. {
  11275. // Optional data
  11276. if(json_object_object_get(GetConfiguration, "key") != NULL)
  11277. {
  11278. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  11279. {
  11280. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  11281. n_keys = idx + 1;
  11282. }
  11283. }
  11284. }
  11285. json_object_put(GetConfiguration);
  11286. UnknownKeynum = 0;
  11287. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  11288. MaxKeySupported = GetConfigurationMaxKeysNUM;
  11289. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  11290. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  11291. if(n_keys != 0)
  11292. {
  11293. for(int i=0;i<n_keys;i++)
  11294. {
  11295. getKeyValue(requestKey[i]);
  11296. }
  11297. }
  11298. else
  11299. {
  11300. DEBUG_INFO("There is no key in Message, get all configuration\n");
  11301. getKeyValue("");
  11302. }
  11303. processUnkownKey();
  11304. sendGetConfigurationConfirmation(uuid);
  11305. return result;
  11306. }
  11307. static char fnamePlusPath[100]={0};
  11308. static char fnamePWithNoPath[60]={0};
  11309. void checkUploadLog(void)
  11310. {
  11311. FILE *fp;
  11312. /* Open the command for reading. */
  11313. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  11314. if (fp == NULL) {
  11315. DEBUG_WARN("Failed to run command\n" );
  11316. exit(1);
  11317. }
  11318. int ftppathlen = 0;
  11319. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  11320. int i = 0;
  11321. /* Read the output a line at a time - output it. */
  11322. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  11323. if(i==0)
  11324. {
  11325. ftppathlen = strlen(fnamePlusPath);
  11326. DEBUG_INFO("%s\n", fnamePlusPath);
  11327. fnamePlusPath[ftppathlen]='\0';
  11328. break;
  11329. }
  11330. i= i+1;
  11331. }
  11332. /* close */
  11333. pclose(fp);
  11334. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  11335. {
  11336. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  11337. {
  11338. fnamePlusPath[k]='\0';
  11339. }
  11340. }
  11341. i=1;
  11342. //char fname[60]={0};
  11343. while(i < ftppathlen)
  11344. {
  11345. int len=ftppathlen-i;
  11346. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  11347. {
  11348. DEBUG_INFO("compare '/' all right\n");
  11349. break;
  11350. }
  11351. i=i+1;
  11352. }
  11353. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  11354. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  11355. fnamePWithNoPath[i+1] = '\0';
  11356. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  11357. {
  11358. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  11359. {
  11360. fnamePWithNoPath[j]='\0';
  11361. }
  11362. }
  11363. FILE* fp1 = fopen(fnamePlusPath, "r");
  11364. if (fp1)
  11365. {
  11366. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  11367. // file exists
  11368. fclose(fp1);
  11369. }
  11370. else
  11371. {
  11372. // file doesn't exist
  11373. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  11374. }
  11375. }
  11376. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  11377. {
  11378. mtrace();
  11379. int result = FAIL;
  11380. time_t CurrentTime;
  11381. struct tm *tm;
  11382. pthread_t th_Status;
  11383. CurrentTime = time(NULL);
  11384. tm = localtime(&CurrentTime);
  11385. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  11386. 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);
  11387. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11388. if(!interLock.isGetDiagnosticGoing)
  11389. {
  11390. interLock.isGetDiagnosticGoing = 1;
  11391. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, payload);
  11392. sleep(1);
  11393. }
  11394. else
  11395. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  11396. return result;
  11397. }
  11398. void* GetDiagnosticsProcess(void* data)
  11399. {
  11400. pthread_detach(pthread_self());
  11401. mtrace();
  11402. int retriesInt=0, retryIntervalInt=0;
  11403. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  11404. 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};
  11405. int port=0;
  11406. int isSuccess = FALSE;
  11407. char cmdBuf[2048];
  11408. struct tm *tmNow;
  11409. time_t CurrentTime;
  11410. struct tm tmStart;
  11411. struct tm tmStop;
  11412. CurrentTime = time(NULL);
  11413. tmNow=localtime(&CurrentTime);
  11414. uint16_t targetYear, targetMonth;
  11415. json_object *GetDiagnostics;
  11416. DEBUG_INFO("GetDiagnosticsProcess...\n");
  11417. GetDiagnostics = json_tokener_parse(data);
  11418. if(!is_error(GetDiagnostics))
  11419. {
  11420. // Required data
  11421. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  11422. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  11423. // Optional data
  11424. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  11425. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  11426. else
  11427. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  11428. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  11429. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  11430. else
  11431. retryIntervalInt = 30;
  11432. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  11433. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  11434. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  11435. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  11436. }
  11437. json_object_put(GetDiagnostics);
  11438. // Pack log to compress file
  11439. 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) &&
  11440. (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))
  11441. {
  11442. // Pack system log
  11443. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11444. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  11445. targetYear = tmStart.tm_year;
  11446. targetMonth = tmStart.tm_mon;
  11447. do
  11448. {
  11449. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11450. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  11451. if(targetMonth+1>=13)
  11452. {
  11453. targetYear += 1;
  11454. targetMonth = 1;
  11455. }
  11456. else
  11457. {
  11458. targetMonth += 1;
  11459. }
  11460. }while((targetYear < (tmNow->tm_year+1900)) ||
  11461. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11462. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  11463. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  11464. system(cmdBuf);
  11465. // Pack charging & event log
  11466. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11467. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  11468. targetYear = tmStart.tm_year;
  11469. targetMonth = tmStart.tm_mon;
  11470. do
  11471. {
  11472. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11473. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  11474. if(targetMonth+1>=13)
  11475. {
  11476. targetYear += 1;
  11477. targetMonth = 1;
  11478. }
  11479. else
  11480. {
  11481. targetMonth += 1;
  11482. }
  11483. }while((targetYear < (tmNow->tm_year+1900)) ||
  11484. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11485. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  11486. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  11487. system(cmdBuf);
  11488. // Combine log file
  11489. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  11490. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  11491. }
  11492. else
  11493. {
  11494. system("exec /root/logPackTools 'log' 6");
  11495. }
  11496. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11497. system(cmdBuf);
  11498. checkUploadLog();
  11499. //****************location*******************/
  11500. if(strcmp(locationstr,"")==0)
  11501. {
  11502. DEBUG_INFO("location is <Empty>!\n");
  11503. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11504. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11505. goto end;
  11506. }
  11507. memset(protocol, 0, ARRAY_SIZE(protocol));
  11508. memset(user, 0, ARRAY_SIZE(user) );
  11509. memset(password, 0, ARRAY_SIZE(password));
  11510. memset(host, 0, ARRAY_SIZE(host));
  11511. memset(path, 0, ARRAY_SIZE(path));
  11512. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11513. memset(host1, 0, ARRAY_SIZE(host1));
  11514. memset(path1, 0, ARRAY_SIZE(path1));
  11515. /*location: ftp://user:password@host:port/path*/
  11516. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  11517. if((access(fnamePlusPath,F_OK))!=-1)
  11518. {
  11519. DEBUG_INFO("fnamePlusPath exist.\n");
  11520. }
  11521. else
  11522. {
  11523. DEBUG_INFO("fnamePlusPath not exist!\n");
  11524. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11525. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11526. goto end;
  11527. }
  11528. if(strchr(locationstr,'@')==NULL)
  11529. {
  11530. sscanf(locationstr,
  11531. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11532. protocol, host, &port, path);
  11533. strcpy(user,"anonymous");
  11534. strcpy(password,"");
  11535. }
  11536. else
  11537. {
  11538. //DEBUG_INFO("pch=%s\n", pch);
  11539. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11540. protocol, user, password, host, &port, path);
  11541. }
  11542. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  11543. {
  11544. DEBUG_INFO("protocol is not ftp/http ! \n");
  11545. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11546. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11547. goto end;
  11548. }
  11549. if(strncmp(locationstr,"http", 4) == 0)
  11550. {
  11551. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11552. sprintf(ftppath,"/%s", path);
  11553. do
  11554. {
  11555. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11556. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11557. sleep(3);
  11558. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  11559. if(!isSuccess)
  11560. {
  11561. DEBUG_INFO("Diagnostics fail.\n");
  11562. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11563. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11564. sleep(retryIntervalInt);
  11565. }
  11566. else
  11567. {
  11568. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11569. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11570. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11571. }
  11572. retriesInt--;
  11573. }while((isSuccess == 0)&&(retriesInt >= 0));
  11574. }
  11575. else
  11576. {
  11577. sscanf(host,"%[^/]%s",host1, path1);
  11578. if(strlen(path) > 0)
  11579. sprintf(ftppath,"/%s", path);
  11580. else
  11581. sprintf(ftppath,"/%s", path1);
  11582. int ftppathlen=strlen(ftppath);
  11583. int i=1;
  11584. char filenametemp[50];
  11585. while(i < ftppathlen)
  11586. {
  11587. int len=ftppathlen-i;
  11588. if(ftppath[len]== 47) // '/' ascll code: 47
  11589. {
  11590. DEBUG_INFO("find '/' all right\n");
  11591. break;
  11592. }
  11593. i=i+1;
  11594. }
  11595. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11596. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11597. filenametemp[i+1] = 0;
  11598. if(port == 0)
  11599. port = 21;
  11600. do
  11601. {
  11602. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11603. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11604. sleep(3);
  11605. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  11606. if(!isSuccess)
  11607. {
  11608. DEBUG_INFO("Diagnostics fail.\n");
  11609. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11610. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11611. sleep(retryIntervalInt);
  11612. }
  11613. else
  11614. {
  11615. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11616. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11617. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11618. }
  11619. retriesInt--;
  11620. }while((!isSuccess)&&(retriesInt >= 0));
  11621. }
  11622. end:
  11623. system("rm -f /mnt/*");
  11624. sleep(5);
  11625. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11626. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11627. interLock.isGetDiagnosticGoing = 0;
  11628. pthread_exit(NULL);
  11629. }
  11630. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  11631. {
  11632. mtrace();
  11633. int result = FAIL;
  11634. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  11635. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  11636. {
  11637. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  11638. locallistVersion = -1;
  11639. }
  11640. else
  11641. {
  11642. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  11643. locallistVersion = 0;
  11644. OCPP_getListVerion();
  11645. }
  11646. //from db.OCPP_getListVerion
  11647. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  11648. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  11649. sendGetLocalListVersionConfirmation(uuid,"");
  11650. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  11651. return result;
  11652. }
  11653. int handleRemoteStartRequest(char *uuid, char *payload)
  11654. {
  11655. mtrace();
  11656. int result = PASS;
  11657. int connectorIdInt=-1;
  11658. int tempIndex = 0;
  11659. char comfirmstr[20]={0};
  11660. char cmdBuf[512];
  11661. json_object *RemoteStartTransaction;
  11662. FILE *fp;
  11663. DEBUG_INFO("handleRemoteStartRequest ...\n");
  11664. if(server_pending == TRUE)
  11665. {
  11666. result = FAIL;
  11667. }
  11668. RemoteStartTransaction = json_tokener_parse(payload);
  11669. if(!is_error(RemoteStartTransaction))
  11670. {
  11671. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  11672. {
  11673. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  11674. }
  11675. else
  11676. {
  11677. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11678. {
  11679. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  11680. {
  11681. connectorIdInt = (gun_index+1);
  11682. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  11683. break;
  11684. }
  11685. }
  11686. }
  11687. if(connectorIdInt == 0)
  11688. {
  11689. DEBUG_WARN("Connector id shall not equal 0.\n");
  11690. result = FAIL;
  11691. }
  11692. else if(json_object_object_get(RemoteStartTransaction, "idTag") == NULL)
  11693. {
  11694. DEBUG_WARN("idTag should not be NULL.\n");
  11695. result = FAIL;
  11696. }
  11697. else if(connectorIdInt == -1)
  11698. {
  11699. DEBUG_INFO("Connector id does not specific.\n");
  11700. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11701. {
  11702. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11703. // Required data
  11704. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11705. // Optional data
  11706. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11707. {
  11708. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11709. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11710. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11711. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11712. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11713. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11714. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11715. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11716. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11717. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11718. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11719. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11720. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11721. {
  11722. 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")));
  11723. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11724. 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"));
  11725. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11726. 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"));
  11727. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11728. 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")));
  11729. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11730. {
  11731. 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++)
  11732. {
  11733. 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"));
  11734. 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"));
  11735. 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)
  11736. 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"));
  11737. }
  11738. }
  11739. }
  11740. }
  11741. else
  11742. {
  11743. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11744. }
  11745. }
  11746. }
  11747. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11748. {
  11749. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11750. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11751. // Required data
  11752. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11753. // Optional data
  11754. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11755. {
  11756. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11757. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11758. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11759. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11760. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11761. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11762. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11763. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11764. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11765. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11766. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11767. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11768. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11769. {
  11770. 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")));
  11771. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11772. 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"));
  11773. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11774. 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"));
  11775. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11776. 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")));
  11777. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11778. {
  11779. 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++)
  11780. {
  11781. 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"));
  11782. 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"));
  11783. 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)
  11784. 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"));
  11785. }
  11786. }
  11787. }
  11788. }
  11789. else
  11790. {
  11791. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11792. }
  11793. }
  11794. else
  11795. {
  11796. DEBUG_WARN("Connector id is over maximun value.\n");
  11797. result = FAIL;
  11798. }
  11799. }
  11800. if(result == PASS)
  11801. {
  11802. if(connectorIdInt > 0)
  11803. {
  11804. //check Transaction active
  11805. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11806. {
  11807. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11808. {
  11809. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11810. }
  11811. else
  11812. {
  11813. tempIndex = connectorIdInt -1;
  11814. }
  11815. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11816. {
  11817. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11818. {
  11819. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11820. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11821. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11822. {
  11823. //Reserved
  11824. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11825. }
  11826. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11827. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11828. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11829. {
  11830. //Reserved
  11831. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11832. {
  11833. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11834. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11835. goto end;
  11836. }
  11837. }
  11838. else
  11839. {
  11840. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11841. {
  11842. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11843. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11844. goto end;
  11845. }
  11846. }//END FOR ELSE
  11847. }
  11848. }// END FOR CHAdeMO_QUANTITY
  11849. }
  11850. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11851. {
  11852. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11853. {
  11854. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11855. }
  11856. else
  11857. {
  11858. tempIndex = connectorIdInt -1;
  11859. }
  11860. for (int index = 0; index < CCS_QUANTITY; index++)
  11861. {
  11862. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11863. {
  11864. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11865. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11866. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11867. {
  11868. //Reserved
  11869. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11870. }
  11871. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11872. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11873. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11874. {
  11875. //Reserved
  11876. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11877. {
  11878. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11879. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11880. goto end;
  11881. }
  11882. }
  11883. else
  11884. {
  11885. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11886. {
  11887. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11888. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11889. goto end;
  11890. }
  11891. }// END FOR ELSE
  11892. }
  11893. }// END FOR CCS_QUANTITY
  11894. }
  11895. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11896. {
  11897. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11898. {
  11899. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11900. }
  11901. else
  11902. {
  11903. tempIndex = connectorIdInt -1;
  11904. }
  11905. for (int index = 0; index < GB_QUANTITY; index++)
  11906. {
  11907. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11908. {
  11909. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11910. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11911. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11912. {
  11913. //Reserved
  11914. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11915. }
  11916. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11917. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11918. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11919. {
  11920. //Reserved
  11921. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11922. {
  11923. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11924. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11925. goto end;
  11926. }
  11927. }
  11928. else
  11929. {
  11930. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11931. {
  11932. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11933. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11934. goto end;
  11935. }
  11936. }// END FOR ELSE
  11937. }
  11938. } // END FOR GB_QUANTITY
  11939. }
  11940. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11941. {
  11942. tempIndex = connectorIdInt -1;
  11943. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11944. {
  11945. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11946. {
  11947. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11948. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11949. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11950. {
  11951. //Reserved
  11952. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11953. }
  11954. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11955. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11956. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11957. {
  11958. //Reserved
  11959. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11960. {
  11961. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11962. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11963. goto end;
  11964. }
  11965. }
  11966. else
  11967. {
  11968. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11969. {
  11970. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11971. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11972. goto end;
  11973. }
  11974. }// END FOR ELSE
  11975. }
  11976. } // END FOR GB_QUANTITY
  11977. }
  11978. else
  11979. {
  11980. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11981. {
  11982. tempIndex = 2;
  11983. }
  11984. else
  11985. {
  11986. tempIndex = connectorIdInt -1;
  11987. }
  11988. for (int index = 0; index < AC_QUANTITY; index++)
  11989. {
  11990. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11991. {
  11992. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11993. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11994. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11995. {
  11996. //Reserved
  11997. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11998. }
  11999. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  12000. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  12001. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  12002. {
  12003. //Reserved
  12004. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  12005. {
  12006. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  12007. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12008. goto end;
  12009. }
  12010. }
  12011. else
  12012. {
  12013. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  12014. {
  12015. DEBUG_WARN("AC connector not allow start cause busy.\n");
  12016. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12017. goto end;
  12018. }
  12019. }//END FOR ELSE
  12020. }
  12021. }// END FOR AC_QUANTITY
  12022. }
  12023. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  12024. {
  12025. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12026. {
  12027. // Save profile to file
  12028. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  12029. system(cmdBuf);
  12030. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  12031. fp = fopen(cmdBuf, "w");
  12032. 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));
  12033. fclose(fp);
  12034. }
  12035. else
  12036. {
  12037. DEBUG_WARN("Profile purpose not TxProfile.\n");
  12038. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12039. goto end;
  12040. }
  12041. }
  12042. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  12043. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  12044. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  12045. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  12046. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  12047. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  12048. }
  12049. else
  12050. {
  12051. uint8_t isHasIdleConnector = FALSE;
  12052. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  12053. {
  12054. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  12055. {
  12056. isHasIdleConnector = TRUE;
  12057. break;
  12058. }
  12059. }
  12060. if((isHasIdleConnector == TRUE) && !ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  12061. {
  12062. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12063. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  12064. {
  12065. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12066. {
  12067. // Save profile to file
  12068. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  12069. system(cmdBuf);
  12070. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  12071. fp = fopen(cmdBuf, "w");
  12072. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  12073. fclose(fp);
  12074. refreshStartTimer(&clientTime.RemoteStartWait);
  12075. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  12076. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  12077. }
  12078. else
  12079. {
  12080. DEBUG_WARN("Profile purpose not TxProfile.\n");
  12081. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12082. }
  12083. }
  12084. else
  12085. {
  12086. refreshStartTimer(&clientTime.RemoteStartWait);
  12087. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  12088. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  12089. }
  12090. }
  12091. else
  12092. {
  12093. DEBUG_INFO("There is not any connector is idle.\n");
  12094. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12095. }
  12096. }
  12097. }
  12098. else
  12099. {
  12100. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12101. }
  12102. end:
  12103. json_object_put(RemoteStartTransaction);
  12104. sendRemoteStartConfirmation(uuid, comfirmstr);
  12105. return result;
  12106. }
  12107. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  12108. {
  12109. mtrace();
  12110. int result = FAIL;
  12111. int match = FALSE;
  12112. int GunNO = 0;
  12113. int tempIndex = 0;
  12114. int transactionIdInt=0;
  12115. int transactionIdIsNULL= TRUE;
  12116. char comfirmstr[20];
  12117. json_object *RemoteStopTransaction;
  12118. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  12119. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  12120. if(server_pending == TRUE)
  12121. {
  12122. return 0;
  12123. }
  12124. RemoteStopTransaction = json_tokener_parse(payload);
  12125. if(!is_error(RemoteStopTransaction))
  12126. {
  12127. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  12128. {
  12129. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  12130. transactionIdIsNULL = FALSE;
  12131. }
  12132. }
  12133. json_object_put(RemoteStopTransaction);
  12134. if(transactionIdIsNULL == FALSE)
  12135. {
  12136. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  12137. {
  12138. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  12139. {
  12140. //check Transaction active
  12141. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  12142. {
  12143. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12144. {
  12145. tempIndex = ((gun_index==2) ? 1: 0);
  12146. }
  12147. else
  12148. {
  12149. tempIndex = gun_index;
  12150. }
  12151. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12152. {
  12153. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12154. {
  12155. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  12156. {
  12157. match = TRUE;
  12158. GunNO = gun_index;
  12159. }
  12160. }
  12161. }// END FOR CHAdeMO_QUANTITY
  12162. }
  12163. else if(gunType[gun_index] == GUN_TYPE_CCS)
  12164. {
  12165. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12166. {
  12167. tempIndex = ((gun_index==2) ? 1: 0);
  12168. }
  12169. else
  12170. {
  12171. tempIndex = gun_index;
  12172. }
  12173. for (int index = 0; index < CCS_QUANTITY; index++)
  12174. {
  12175. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12176. {
  12177. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  12178. {
  12179. match = TRUE;
  12180. GunNO = gun_index;
  12181. }
  12182. }
  12183. }// END FOR CCS_QUANTITY
  12184. }
  12185. else if(gunType[gun_index] == GUN_TYPE_GBT)
  12186. {
  12187. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12188. {
  12189. tempIndex = ((gun_index==2) ? 1: 0);
  12190. }
  12191. else
  12192. {
  12193. tempIndex = gun_index;
  12194. }
  12195. for (int index = 0; index < GB_QUANTITY; index++)
  12196. {
  12197. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12198. {
  12199. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  12200. {
  12201. match = TRUE;
  12202. GunNO = gun_index;
  12203. }
  12204. }
  12205. }// END FOR GB_QUANTITY
  12206. }
  12207. else if(gunType[gun_index] == GUN_TYPE_DO)
  12208. {
  12209. tempIndex = gun_index;
  12210. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12211. {
  12212. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12213. {
  12214. 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
  12215. {
  12216. match = TRUE;
  12217. GunNO = gun_index;
  12218. }
  12219. }
  12220. }// END FOR GB_QUANTITY
  12221. }
  12222. else
  12223. {
  12224. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12225. {
  12226. tempIndex = 2;
  12227. }
  12228. else
  12229. {
  12230. tempIndex = gun_index;
  12231. }
  12232. for (int index = 0; index < AC_QUANTITY; index++)
  12233. {
  12234. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12235. {
  12236. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  12237. {
  12238. match = TRUE;
  12239. GunNO = gun_index;
  12240. }
  12241. }
  12242. }// END FOR CHAdeMO_QUANTITY
  12243. } // END FOR AC ELSE
  12244. }// CHECK IF ResponseTransactionId == transactionIdInt
  12245. }//END FOR
  12246. if( match == TRUE)
  12247. {
  12248. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  12249. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  12250. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  12251. }
  12252. else
  12253. {
  12254. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12255. }
  12256. }
  12257. else
  12258. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12259. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  12260. return result;
  12261. }
  12262. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  12263. {
  12264. mtrace();
  12265. int result = FAIL;
  12266. int connectorIdInt=0, reservationIdInt=0;
  12267. int tempIndex = 0;
  12268. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  12269. char comfirmstr[20]={0};
  12270. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  12271. int c = 0;
  12272. char *loc;
  12273. //char *ptr;
  12274. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  12275. strcpy(sstrtemp, stringtrimspace(payload));
  12276. //***(1)connectorId ****/
  12277. c=0;
  12278. loc = strstr(sstrtemp, "connectorId");
  12279. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12280. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  12281. {
  12282. sstr[c] = loc[strlen("connectorId")+2+c];
  12283. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12284. c++;
  12285. }
  12286. sstr[c] = '\0';
  12287. connectorIdInt = atoi(sstr);
  12288. //***(2)expiryDate ****/
  12289. loc = strstr(sstrtemp, "expiryDate");
  12290. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12291. c = 0;
  12292. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  12293. {
  12294. sstr[c] = loc[3+strlen("expiryDate")+c];
  12295. c++;
  12296. }
  12297. sstr[c] = '\0';
  12298. strcpy(expiryDatestr, sstr);
  12299. //***(3)idTag ****/
  12300. loc = strstr(sstrtemp, "idTag");
  12301. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12302. c = 0;
  12303. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  12304. {
  12305. sstr[c] = loc[3+strlen("idTag")+c];
  12306. c++;
  12307. }
  12308. sstr[c] = '\0';
  12309. strcpy(idTagstr, sstr);
  12310. //***(4)parentIdTag ****/
  12311. loc = strstr(sstrtemp, "parentIdTag");
  12312. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12313. c = 0;
  12314. if(loc == NULL)
  12315. {
  12316. strcpy(parentIdTagstr, "");
  12317. }
  12318. else
  12319. {
  12320. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  12321. {
  12322. sstr[c] = loc[3+strlen("parentIdTag")+c];
  12323. c++;
  12324. }
  12325. sstr[c] = '\0';
  12326. strcpy(parentIdTagstr, sstr);
  12327. }
  12328. //***(5)reservationId ****/
  12329. c=0;
  12330. loc = strstr(sstrtemp, "reservationId");
  12331. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12332. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  12333. {
  12334. sstr[c] = loc[strlen("reservationId")+2+c];
  12335. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12336. c++;
  12337. }
  12338. sstr[c] = '\0';
  12339. reservationIdInt = atoi(sstr);
  12340. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12341. /*
  12342. enum SYSTEM_STATUS
  12343. {
  12344. SYS_MODE_BOOTING = 0,
  12345. SYS_MODE_IDLE = 1,
  12346. SYS_MODE_AUTHORIZING = 2,
  12347. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  12348. SYS_MODE_REASSIGN = 4,
  12349. SYS_MODE_PREPARING = 5,
  12350. SYS_MODE_PREPARE_FOR_EV = 6,
  12351. SYS_MODE_PREPARE_FOR_EVSE = 7,
  12352. SYS_MODE_CHARGING = 8,
  12353. SYS_MODE_TERMINATING = 9,
  12354. SYS_MODE_COMPLETE = 10,
  12355. SYS_MODE_ALARM = 11,
  12356. SYS_MODE_FAULT = 12,
  12357. SYS_MODE_RESERVATION = 13,
  12358. SYS_MODE_BOOKING = 14,
  12359. SYS_MODE_MAINTAIN = 15,
  12360. SYS_MODE_DEBUG = 16,
  12361. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  12362. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  12363. SYS_MODE_UPDATE = 19
  12364. };
  12365. */
  12366. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  12367. {
  12368. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12369. goto end;
  12370. }
  12371. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  12372. {
  12373. //check Transaction active
  12374. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  12375. {
  12376. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12377. {
  12378. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12379. }
  12380. else
  12381. {
  12382. tempIndex = connectorIdInt -1;
  12383. }
  12384. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12385. {
  12386. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12387. {
  12388. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12389. {
  12390. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12391. {
  12392. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12393. {
  12394. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  12395. {
  12396. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12397. }
  12398. else
  12399. {
  12400. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12401. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12402. }
  12403. }
  12404. 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'))
  12405. {
  12406. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12407. }
  12408. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12409. {
  12410. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12411. }
  12412. else
  12413. {
  12414. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12415. }
  12416. }
  12417. 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
  12418. {
  12419. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12420. }
  12421. }
  12422. else
  12423. {
  12424. //replace reservation
  12425. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12426. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12427. }
  12428. }
  12429. } // END FOR CHAdeMO_QUANTITY
  12430. }
  12431. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  12432. {
  12433. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12434. {
  12435. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12436. }
  12437. else
  12438. {
  12439. tempIndex = connectorIdInt -1;
  12440. }
  12441. for (int index = 0; index < CCS_QUANTITY; index++)
  12442. {
  12443. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12444. {
  12445. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12446. {
  12447. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12448. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12449. {
  12450. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12451. {
  12452. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  12453. {
  12454. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12455. }
  12456. else
  12457. {
  12458. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12459. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12460. }
  12461. }
  12462. 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'))
  12463. {
  12464. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12465. }
  12466. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  12467. {
  12468. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12469. }
  12470. else
  12471. {
  12472. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12473. }
  12474. }
  12475. 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
  12476. {
  12477. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12478. }
  12479. }
  12480. else
  12481. {
  12482. //replace reservation
  12483. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12484. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12485. }
  12486. }
  12487. } // END FOR CCS_QUANTITY
  12488. }
  12489. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  12490. {
  12491. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12492. {
  12493. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12494. }
  12495. else
  12496. {
  12497. tempIndex = connectorIdInt -1;
  12498. }
  12499. for (int index = 0; index < GB_QUANTITY; index++)
  12500. {
  12501. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12502. {
  12503. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12504. {
  12505. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12506. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12507. {
  12508. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12509. {
  12510. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  12511. {
  12512. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12513. }
  12514. else
  12515. {
  12516. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12517. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12518. }
  12519. }
  12520. 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'))
  12521. {
  12522. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12523. }
  12524. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12525. {
  12526. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12527. }
  12528. else
  12529. {
  12530. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12531. }
  12532. }
  12533. 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
  12534. {
  12535. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12536. }
  12537. }
  12538. else
  12539. {
  12540. //replace reservation
  12541. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12542. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12543. }
  12544. }
  12545. }// END FOR GB_QUANTITY
  12546. }
  12547. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  12548. {
  12549. tempIndex = connectorIdInt -1;
  12550. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12551. {
  12552. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12553. {
  12554. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  12555. {
  12556. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12557. 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
  12558. {
  12559. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12560. {
  12561. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  12562. {
  12563. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12564. }
  12565. else
  12566. {
  12567. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12568. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12569. }
  12570. }
  12571. 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'))
  12572. {
  12573. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12574. }
  12575. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12576. {
  12577. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12578. }
  12579. else
  12580. {
  12581. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12582. }
  12583. }
  12584. 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
  12585. {
  12586. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12587. }
  12588. }
  12589. else
  12590. {
  12591. //replace reservation
  12592. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12593. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12594. }
  12595. }
  12596. }// END FOR GB_QUANTITY
  12597. }
  12598. else
  12599. {
  12600. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12601. {
  12602. tempIndex = 2;
  12603. }
  12604. else
  12605. {
  12606. tempIndex = (connectorIdInt -1);
  12607. }
  12608. for (int index = 0; index < AC_QUANTITY; index++)
  12609. {
  12610. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12611. {
  12612. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12613. {
  12614. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12615. {
  12616. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12617. {
  12618. 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))
  12619. {
  12620. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12621. }
  12622. else
  12623. {
  12624. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12625. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12626. }
  12627. }
  12628. 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'))
  12629. {
  12630. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12631. }
  12632. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12633. {
  12634. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12635. }
  12636. else
  12637. {
  12638. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12639. }
  12640. }
  12641. 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
  12642. {
  12643. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12644. }
  12645. }
  12646. else
  12647. {
  12648. //replace reservation
  12649. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12650. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12651. }
  12652. }
  12653. } // END FOR AC_QUANTITY
  12654. }
  12655. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12656. }
  12657. else if(connectorIdInt == 0)
  12658. {
  12659. //check Transaction active
  12660. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12661. {
  12662. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12663. {
  12664. 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'))
  12665. {
  12666. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12667. goto end;
  12668. }
  12669. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12670. {
  12671. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12672. goto end;
  12673. }
  12674. 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
  12675. {
  12676. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12677. goto end;
  12678. }
  12679. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12680. {
  12681. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12682. goto end;
  12683. }
  12684. }
  12685. }// END FOR CHAdeMO_QUANTITY
  12686. for (int index = 0; index < CCS_QUANTITY; index++)
  12687. {
  12688. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12689. {
  12690. 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'))
  12691. {
  12692. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12693. goto end;
  12694. }
  12695. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12696. {
  12697. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12698. goto end;
  12699. }
  12700. 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
  12701. {
  12702. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12703. goto end;
  12704. }
  12705. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12706. {
  12707. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12708. goto end;
  12709. }
  12710. }
  12711. } // END FOR CCS_QUANTITY
  12712. for (int index = 0; index < GB_QUANTITY; index++)
  12713. {
  12714. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12715. {
  12716. 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'))
  12717. {
  12718. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12719. goto end;
  12720. }
  12721. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12722. {
  12723. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12724. goto end;
  12725. }
  12726. 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
  12727. {
  12728. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12729. goto end;
  12730. }
  12731. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12732. {
  12733. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12734. goto end;
  12735. }
  12736. }
  12737. } // END FOR GB_QUANTITY
  12738. for (int index = 0; index < AC_QUANTITY; index++)
  12739. {
  12740. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12741. {
  12742. 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'))
  12743. {
  12744. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12745. goto end;
  12746. }
  12747. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12748. {
  12749. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12750. goto end;
  12751. }
  12752. 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
  12753. {
  12754. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12755. goto end;
  12756. }
  12757. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12758. {
  12759. 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))
  12760. {
  12761. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12762. goto end;
  12763. }
  12764. }
  12765. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12766. {
  12767. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12768. goto end;
  12769. }
  12770. }
  12771. }// END FOR AC_QUANTITY
  12772. //The connectorId is 0
  12773. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12774. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12775. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12776. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12777. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12778. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12779. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12780. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12781. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12782. result = TRUE;
  12783. return result;
  12784. }
  12785. else
  12786. {
  12787. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12788. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12789. }
  12790. if(strcmp(comfirmstr,"Accepted") == 0)
  12791. {
  12792. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12793. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12794. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12795. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12796. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12797. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12798. result = TRUE;
  12799. return result;
  12800. }
  12801. end:
  12802. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12803. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12804. return result;
  12805. }
  12806. int handleResetRequest(char *uuid, char *payload)
  12807. {
  12808. mtrace();
  12809. int result = FAIL;
  12810. char sstr[10]={0},sstrtemp[30]={ 0 };
  12811. char typestr[10]={0};
  12812. char comfirmstr[20]={0};
  12813. int c = 0;
  12814. char *loc;
  12815. DEBUG_INFO("handleResetRequest...\n");
  12816. strcpy(sstrtemp, stringtrimspace(payload));
  12817. loc = strstr(sstrtemp, "type");
  12818. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12819. c = 0;
  12820. while (loc[3+strlen("type")+c] != '\"')
  12821. {
  12822. sstr[c] = loc[3+strlen("type")+c];
  12823. c++;
  12824. }
  12825. sstr[c] = '\0';
  12826. strcpy(typestr,sstr);
  12827. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12828. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12829. {
  12830. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12831. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12832. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12833. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12834. }
  12835. else
  12836. {
  12837. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12838. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12839. result = PASS;
  12840. }
  12841. sendResetConfirmation(uuid, comfirmstr);
  12842. return result;
  12843. }
  12844. int handleSendLocalListRequest(char *uuid, char *payload)
  12845. {
  12846. mtrace();
  12847. int result = FAIL;
  12848. char comfirmstr[20];
  12849. int checkState_Faulted = FALSE;
  12850. json_object *SendLocalList;
  12851. DEBUG_INFO("handleSendLocalListRequest...\n");
  12852. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12853. {
  12854. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12855. goto end;
  12856. }
  12857. //check Charge Point state
  12858. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12859. {
  12860. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12861. {
  12862. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12863. }
  12864. }
  12865. for (int index = 0; index < CCS_QUANTITY; index++)
  12866. {
  12867. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12868. {
  12869. checkState_Faulted = TRUE; //OCPP Status
  12870. }
  12871. }
  12872. for (int index = 0; index < GB_QUANTITY; index++)
  12873. {
  12874. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12875. {
  12876. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12877. }
  12878. }
  12879. //check Charge Point state
  12880. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12881. {
  12882. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12883. {
  12884. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12885. }
  12886. }
  12887. //check Charge Point state
  12888. for (int index = 0; index < AC_QUANTITY; index++)
  12889. {
  12890. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12891. {
  12892. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12893. }
  12894. }
  12895. if(checkState_Faulted == TRUE)
  12896. {
  12897. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12898. goto end;
  12899. }
  12900. // Parsing payload
  12901. SendLocalList = json_tokener_parse(payload);
  12902. if(!is_error(SendLocalList))
  12903. {
  12904. // Required data
  12905. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12906. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12907. // Optional data
  12908. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12909. {
  12910. //Check UpdateType
  12911. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12912. {
  12913. //Local list full update
  12914. DEBUG_INFO("Local list full update.\n");
  12915. locallistVersion = 0;
  12916. OCPP_getListVerion();
  12917. if((ShmOCPP16Data->SendLocalList.ListVersion > 0) && (ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion))
  12918. {
  12919. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12920. goto end;
  12921. }
  12922. OCPP_cleanLocalList();
  12923. }
  12924. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12925. {
  12926. //Local list different update
  12927. DEBUG_INFO("Local list different update.\n");
  12928. locallistVersion = 0;
  12929. OCPP_getListVerion();
  12930. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12931. {
  12932. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12933. goto end;
  12934. }
  12935. }
  12936. else
  12937. {
  12938. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12939. goto end;
  12940. }
  12941. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  12942. {
  12943. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  12944. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12945. goto end;
  12946. }
  12947. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12948. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12949. {
  12950. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  12951. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12952. {
  12953. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status, "%s", 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")));
  12954. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12955. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate, "%s", 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")));
  12956. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12957. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag, "%s", 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")));
  12958. }
  12959. // Add to db
  12960. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12961. {
  12962. //Local list full update
  12963. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12964. idx,
  12965. ShmOCPP16Data->SendLocalList.ListVersion,
  12966. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12967. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12968. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12969. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12970. // update list
  12971. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12972. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12973. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12974. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12975. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12976. }
  12977. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12978. {
  12979. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12980. idx,
  12981. ShmOCPP16Data->SendLocalList.ListVersion,
  12982. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12983. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12984. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12985. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12986. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12987. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12988. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12989. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12990. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12991. }
  12992. }
  12993. }
  12994. else
  12995. {
  12996. //Check UpdateType
  12997. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12998. {
  12999. //Local list full update
  13000. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  13001. OCPP_cleanLocalList();
  13002. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  13003. goto end;
  13004. }
  13005. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  13006. {
  13007. //Local list different update
  13008. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  13009. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  13010. goto end;
  13011. }
  13012. }
  13013. result = PASS;
  13014. }
  13015. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  13016. end:
  13017. json_object_put(SendLocalList);
  13018. sendSendLocalListConfirmation(uuid, comfirmstr);
  13019. return result;
  13020. }
  13021. int handleSetChargingProfileRequest(char *uuid, char *payload)
  13022. {
  13023. mtrace();
  13024. int result = FAIL;
  13025. struct StructSetChargingProfile SetProfileReq = {0};
  13026. int tempchargingProfileIdInt;
  13027. int tempstackLevelInt;
  13028. int chargingSchedulePeriodCount = 0;
  13029. char comfirmstr[20]={0};
  13030. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  13031. char rmFileCmd[128]={0};
  13032. int profileQuantity = 0;
  13033. int replaceableProfileCnt = 0;
  13034. json_object *SetChargingProfile;
  13035. DEBUG_INFO("handleSetChargingProfileRequest\n");
  13036. SetChargingProfile = json_tokener_parse(payload);
  13037. if(!is_error(SetChargingProfile))
  13038. {
  13039. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  13040. {
  13041. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  13042. }
  13043. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  13044. {
  13045. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13046. {
  13047. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13048. }
  13049. else
  13050. {
  13051. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13052. DEBUG_WARN("Cannot find chargingProfileId field.");
  13053. goto end;
  13054. }
  13055. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13056. {
  13057. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  13058. }
  13059. else
  13060. {
  13061. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13062. DEBUG_WARN("Cannot find stackLevel field.");
  13063. goto end;
  13064. }
  13065. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  13066. {
  13067. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  13068. }
  13069. else
  13070. {
  13071. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13072. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  13073. goto end;
  13074. }
  13075. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  13076. {
  13077. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  13078. }
  13079. else
  13080. {
  13081. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13082. DEBUG_WARN("Cannot find chargingProfileKind field.");
  13083. goto end;
  13084. }
  13085. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  13086. {
  13087. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  13088. }
  13089. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  13090. {
  13091. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  13092. }
  13093. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  13094. {
  13095. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  13096. }
  13097. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  13098. {
  13099. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  13100. }
  13101. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  13102. {
  13103. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  13104. {
  13105. 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")));
  13106. }
  13107. else
  13108. {
  13109. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13110. DEBUG_WARN("Cannot find chargingRateUnit field.");
  13111. goto end;
  13112. }
  13113. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  13114. {
  13115. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  13116. }
  13117. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  13118. {
  13119. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  13120. }
  13121. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  13122. {
  13123. 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")));
  13124. }
  13125. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  13126. {
  13127. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  13128. if(chargingSchedulePeriodCount <= 10)
  13129. {
  13130. 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++)
  13131. {
  13132. 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)
  13133. {
  13134. 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"));
  13135. }
  13136. else
  13137. {
  13138. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13139. DEBUG_WARN("Cannot find startPeriod field.");
  13140. goto end;
  13141. }
  13142. 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)
  13143. {
  13144. 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"));
  13145. }
  13146. else
  13147. {
  13148. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13149. DEBUG_WARN("Cannot find limit field.");
  13150. goto end;
  13151. }
  13152. 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)
  13153. {
  13154. 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"));
  13155. }
  13156. }
  13157. }
  13158. }
  13159. else
  13160. {
  13161. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13162. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  13163. goto end;
  13164. }
  13165. }
  13166. else
  13167. {
  13168. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13169. DEBUG_WARN("Cannot find chargingSchedule field.");
  13170. goto end;
  13171. }
  13172. }
  13173. }
  13174. // Profile periods quantity check
  13175. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  13176. {
  13177. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13178. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13179. goto end;
  13180. }
  13181. // Check invalid limit
  13182. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  13183. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  13184. {
  13185. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  13186. {
  13187. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  13188. {
  13189. 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)))) ||
  13190. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  13191. {
  13192. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13193. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  13194. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  13195. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  13196. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  13197. goto end;
  13198. }
  13199. }
  13200. }
  13201. else
  13202. {
  13203. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  13204. {
  13205. 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) ||
  13206. (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)))
  13207. {
  13208. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13209. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  13210. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  13211. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  13212. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  13213. goto end;
  13214. }
  13215. }
  13216. }
  13217. }
  13218. // Profile purpose info check
  13219. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13220. {
  13221. FILE *fp;
  13222. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  13223. if(SetProfileReq.ConnectorId != 0)
  13224. {
  13225. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13226. DEBUG_WARN("Profile connector id is not 0.\n");
  13227. goto end;
  13228. }
  13229. fp = fopen(ChargePointMaxProfile_JSON, "r");
  13230. if (!fp)
  13231. {
  13232. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  13233. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  13234. }
  13235. else
  13236. {
  13237. char *line = NULL;
  13238. size_t len = 0;
  13239. while(getline(&line, &len, fp) != -1)
  13240. {
  13241. json_object *obj = NULL;
  13242. obj = json_tokener_parse(line);
  13243. if(is_error(obj))
  13244. {
  13245. DEBUG_ERROR("Parse txProfile from file error.\n");
  13246. }
  13247. else
  13248. {
  13249. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13250. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13251. {
  13252. profileQuantity += 1;
  13253. }
  13254. else
  13255. replaceableProfileCnt += 1;
  13256. }
  13257. }
  13258. }
  13259. fclose(fp);
  13260. }
  13261. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13262. {
  13263. FILE *fp;
  13264. char filename[128]={0};
  13265. int tmpProfileQuantity;
  13266. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  13267. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13268. {
  13269. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13270. DEBUG_WARN("Profile connector id is over max gun number.\n");
  13271. goto end;
  13272. }
  13273. if(SetProfileReq.ConnectorId == 0)
  13274. {
  13275. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  13276. {
  13277. tmpProfileQuantity = 0;
  13278. memset(filename, 0, ARRAY_SIZE(filename));
  13279. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13280. fp = fopen(filename, "r");
  13281. if (!fp)
  13282. {
  13283. DEBUG_INFO("%s does not create.\n", filename);
  13284. fp = fopen(filename, "w+");
  13285. }
  13286. else
  13287. {
  13288. char *line = NULL;
  13289. size_t len = 0;
  13290. while(getline(&line, &len, fp) != -1)
  13291. {
  13292. json_object *obj = NULL;
  13293. obj = json_tokener_parse(line);
  13294. if(is_error(obj))
  13295. {
  13296. DEBUG_ERROR("Parse txProfile from file error.\n");
  13297. }
  13298. else
  13299. {
  13300. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13301. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13302. {
  13303. tmpProfileQuantity += 1;
  13304. }
  13305. else
  13306. replaceableProfileCnt += 1;
  13307. }
  13308. }
  13309. }
  13310. fclose(fp);
  13311. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  13312. }
  13313. }
  13314. else
  13315. {
  13316. memset(filename, 0, ARRAY_SIZE(filename));
  13317. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13318. fp = fopen(filename, "r");
  13319. if (!fp)
  13320. {
  13321. DEBUG_INFO("%s does not create.\n", filename);
  13322. fp = fopen(filename, "w+");
  13323. }
  13324. else
  13325. {
  13326. char *line = NULL;
  13327. size_t len = 0;
  13328. while(getline(&line, &len, fp) != -1)
  13329. {
  13330. json_object *obj = NULL;
  13331. obj = json_tokener_parse(line);
  13332. if(is_error(obj))
  13333. {
  13334. DEBUG_ERROR("Parse txProfile from file error.\n");
  13335. }
  13336. else
  13337. {
  13338. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13339. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13340. {
  13341. profileQuantity += 1;
  13342. }
  13343. else
  13344. replaceableProfileCnt += 1;
  13345. }
  13346. }
  13347. }
  13348. fclose(fp);
  13349. }
  13350. }
  13351. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  13352. {
  13353. int isMatchTransactiodId= FALSE;
  13354. FILE *fp;
  13355. char filename[128]={0};
  13356. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  13357. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  13358. if(SetProfileReq.ConnectorId == 0)
  13359. {
  13360. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13361. DEBUG_WARN("Profile connector id is 0.\n");
  13362. goto end;
  13363. }
  13364. int tempIndex = 0;
  13365. //check Transaction active
  13366. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  13367. {
  13368. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13369. {
  13370. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13371. }
  13372. else
  13373. {
  13374. tempIndex = SetProfileReq.ConnectorId -1;
  13375. }
  13376. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13377. {
  13378. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13379. {
  13380. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13381. {
  13382. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13383. {
  13384. isMatchTransactiodId = TRUE;
  13385. break;
  13386. }
  13387. }
  13388. }
  13389. }
  13390. }
  13391. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  13392. {
  13393. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13394. {
  13395. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13396. }
  13397. else
  13398. {
  13399. tempIndex = SetProfileReq.ConnectorId -1;
  13400. }
  13401. for (int index = 0; index < CCS_QUANTITY; index++)
  13402. {
  13403. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13404. {
  13405. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  13406. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13407. {
  13408. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13409. {
  13410. isMatchTransactiodId = TRUE;
  13411. break;
  13412. }
  13413. }
  13414. }
  13415. }
  13416. }
  13417. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  13418. {
  13419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13420. {
  13421. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13422. }
  13423. else
  13424. {
  13425. tempIndex = SetProfileReq.ConnectorId -1;
  13426. }
  13427. for (int index = 0; index < GB_QUANTITY; index++)
  13428. {
  13429. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13430. {
  13431. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13432. {
  13433. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13434. {
  13435. isMatchTransactiodId = TRUE;
  13436. break;
  13437. }
  13438. }
  13439. }
  13440. }
  13441. }
  13442. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  13443. {
  13444. tempIndex = SetProfileReq.ConnectorId -1;
  13445. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13446. {
  13447. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13448. {
  13449. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  13450. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13451. {
  13452. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13453. {
  13454. isMatchTransactiodId = TRUE;
  13455. break;
  13456. }
  13457. }
  13458. }
  13459. }
  13460. }
  13461. else
  13462. {
  13463. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13464. {
  13465. tempIndex = 2;
  13466. }
  13467. else
  13468. {
  13469. tempIndex = (SetProfileReq.ConnectorId -1);
  13470. }
  13471. for (int index = 0; index < AC_QUANTITY; index++)
  13472. {
  13473. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13474. {
  13475. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  13476. {
  13477. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13478. {
  13479. isMatchTransactiodId = TRUE;
  13480. break;
  13481. }
  13482. }
  13483. }
  13484. }
  13485. }
  13486. //check Transaction active
  13487. if(isMatchTransactiodId == FALSE)
  13488. {
  13489. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13490. DEBUG_WARN("Tx profile transaction id is not match.\n");
  13491. goto end;
  13492. }
  13493. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13494. {
  13495. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13496. DEBUG_WARN("Connector id is over max gun number.\n");
  13497. goto end;
  13498. }
  13499. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13500. fp = fopen(filename, "r");
  13501. if (!fp)
  13502. {
  13503. DEBUG_INFO("%s does not create.\n", filename);
  13504. fp = fopen(filename, "w+");
  13505. }
  13506. else
  13507. {
  13508. char *line = NULL;
  13509. size_t len = 0;
  13510. while(getline(&line, &len, fp) != -1)
  13511. {
  13512. json_object *obj = NULL;
  13513. obj = json_tokener_parse(line);
  13514. if(is_error(obj))
  13515. {
  13516. DEBUG_ERROR("Parse txProfile from file error.\n");
  13517. }
  13518. else
  13519. {
  13520. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13521. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13522. {
  13523. profileQuantity += 1;
  13524. }
  13525. else
  13526. replaceableProfileCnt += 1;
  13527. }
  13528. }
  13529. }
  13530. fclose(fp);
  13531. }
  13532. // Check ChargeProfileMaxStackLevel
  13533. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  13534. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  13535. {
  13536. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13537. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13538. goto end;
  13539. }
  13540. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13541. {
  13542. FILE *fp;
  13543. char dataLine[4096]={0};
  13544. char fnametemp[128]={0};
  13545. int tmpProfileQuantity;
  13546. //Check ChargePointMaxProfile.json exit
  13547. profileQuantity = 0;
  13548. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  13549. {
  13550. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  13551. //Check Charging Profile Count
  13552. tmpProfileQuantity = 0;
  13553. while(fscanf(fp, "%s", dataLine) != EOF)
  13554. {
  13555. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13556. {
  13557. profileQuantity += 1;
  13558. tmpProfileQuantity += 1;
  13559. }
  13560. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13561. }
  13562. fclose(fp);
  13563. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  13564. }
  13565. //Check TxDefaultProfile_%d.json
  13566. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13567. {
  13568. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13569. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13570. if((access(fnametemp,F_OK))!=-1)
  13571. {
  13572. fp = fopen(fnametemp, "r");
  13573. //Check Charging Profile Count
  13574. tmpProfileQuantity = 0;
  13575. while(fscanf(fp, "%s", dataLine) != EOF)
  13576. {
  13577. //DEBUG_INFO("word=%s\n",word);
  13578. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13579. {
  13580. profileQuantity += 1;
  13581. tmpProfileQuantity += 1;
  13582. }
  13583. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13584. }
  13585. fclose(fp);
  13586. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13587. }
  13588. }
  13589. //Check TxProfile_%d.json
  13590. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13591. {
  13592. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13593. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  13594. if((access(fnametemp,F_OK))!=-1)
  13595. {
  13596. fp = fopen(fnametemp, "r");
  13597. //Check Charging Profile Count
  13598. tmpProfileQuantity = 0;
  13599. while(fscanf(fp, "%s", dataLine) != EOF)
  13600. {
  13601. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13602. {
  13603. profileQuantity += 1;
  13604. tmpProfileQuantity += 1;
  13605. }
  13606. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13607. }
  13608. fclose(fp);
  13609. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13610. }
  13611. }
  13612. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  13613. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  13614. // To check total Profile quantity
  13615. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  13616. {
  13617. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13618. {
  13619. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13620. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13621. goto end;
  13622. }
  13623. }
  13624. else
  13625. {
  13626. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13627. {
  13628. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13629. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13630. goto end;
  13631. }
  13632. }
  13633. }
  13634. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13635. //**********************************Write to File********************************************************/
  13636. {
  13637. FILE *infile;
  13638. FILE *outfile;
  13639. char dataLine[4096]={0};
  13640. char filename[128]={0};
  13641. int chkChar=0;
  13642. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  13643. {
  13644. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13645. {
  13646. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  13647. }
  13648. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13649. {
  13650. if(SetProfileReq.ConnectorId==0)
  13651. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13652. else
  13653. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13654. }
  13655. else
  13656. {
  13657. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13658. }
  13659. infile = fopen (filename, "r");
  13660. outfile = fopen (tempfile, "w");
  13661. chkChar = fgetc(infile);
  13662. rewind(infile);
  13663. if(chkChar == EOF)
  13664. {
  13665. // Profile is empty
  13666. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13667. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13668. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13669. fclose(infile);
  13670. fclose(outfile);
  13671. sprintf(rmFileCmd,"rm -f %s",filename);
  13672. system(rmFileCmd);
  13673. rename(tempfile, filename);
  13674. }
  13675. else
  13676. {
  13677. // Profile is not empty
  13678. int ChargingProfileAdded = FALSE;
  13679. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  13680. {
  13681. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  13682. json_object *tmpChargingProfile;
  13683. tmpChargingProfile = json_tokener_parse(dataLine);
  13684. if(!is_error(SetChargingProfile))
  13685. {
  13686. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13687. {
  13688. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13689. {
  13690. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13691. }
  13692. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13693. {
  13694. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13695. }
  13696. }
  13697. }
  13698. json_object_put(tmpChargingProfile);
  13699. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  13700. {
  13701. if(ChargingProfileAdded == FALSE)
  13702. {
  13703. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13704. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13705. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13706. ChargingProfileAdded = TRUE;
  13707. }
  13708. }
  13709. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13710. {
  13711. if(ChargingProfileAdded == FALSE)
  13712. {
  13713. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13714. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13715. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13716. ChargingProfileAdded = TRUE;
  13717. }
  13718. }
  13719. else
  13720. {
  13721. fprintf(outfile,"%s\n",dataLine);
  13722. if(ChargingProfileAdded == FALSE)
  13723. {
  13724. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13725. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13726. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13727. ChargingProfileAdded = TRUE;
  13728. }
  13729. }
  13730. } // end of while loop
  13731. fclose(infile);
  13732. fclose(outfile);
  13733. sprintf(rmFileCmd,"rm -f %s",filename);
  13734. system(rmFileCmd);
  13735. rename(tempfile, filename);
  13736. }
  13737. }
  13738. sleep(1);
  13739. result = TRUE;
  13740. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13741. }
  13742. end:
  13743. json_object_put(SetChargingProfile);
  13744. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13745. {
  13746. if(SetProfileReq.ConnectorId == 0)
  13747. {
  13748. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13749. {
  13750. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13751. }
  13752. }
  13753. else
  13754. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13755. }
  13756. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13757. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13758. return result;
  13759. }
  13760. int handleTriggerMessageRequest(char *uuid, char *payload)
  13761. {
  13762. mtrace();
  13763. int result = FAIL;
  13764. int connectorIdIsNULL = FALSE;
  13765. int connectorIdInt =0;
  13766. char sstr[40]={0},sstrtemp[100]={ 0 };
  13767. char requestedMessagestr[40]={0};
  13768. char comfirmstr[20]={0};
  13769. int c = 0;
  13770. char *loc;
  13771. DEBUG_INFO("handleTriggerMessageRequest\n");
  13772. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13773. strcpy(sstrtemp, stringtrimspace(payload));
  13774. c = 0;
  13775. loc = strstr(sstrtemp, "requestedMessage");
  13776. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13777. {
  13778. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13779. c++;
  13780. }
  13781. sstr[c] = '\0';
  13782. strcpy(requestedMessagestr, sstr);
  13783. c = 0;
  13784. loc = strstr(sstrtemp, "connectorId");
  13785. if(loc == NULL)
  13786. {
  13787. connectorIdIsNULL = TRUE;
  13788. }
  13789. else
  13790. {
  13791. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13792. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13793. {
  13794. sstr[c] = loc[strlen("connectorId")+2+c];
  13795. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13796. c++;
  13797. }
  13798. sstr[c] = '\0';
  13799. connectorIdInt = atoi(sstr);
  13800. }
  13801. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13802. {
  13803. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13804. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13805. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13806. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13807. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13808. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13809. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13810. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13811. {
  13812. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13813. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13814. return TRUE;
  13815. }
  13816. else
  13817. {
  13818. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13819. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13820. }
  13821. }
  13822. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13823. {
  13824. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13825. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13826. return TRUE;
  13827. }
  13828. //==========================
  13829. // Trigger message
  13830. //==========================
  13831. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13832. {
  13833. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13834. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13835. {
  13836. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13837. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13838. }
  13839. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13840. }
  13841. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13842. {
  13843. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13844. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13845. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13846. }
  13847. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13848. {
  13849. //sendBootNotificationRequest();
  13850. server_sign = FALSE;
  13851. }
  13852. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13853. {
  13854. refreshStartTimer(&clientTime.Heartbeat);
  13855. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13856. }
  13857. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13858. {
  13859. if(connectorIdIsNULL == FALSE)
  13860. {
  13861. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13862. {
  13863. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13864. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13865. }
  13866. }
  13867. else
  13868. {
  13869. for(int idx=0;idx< gunTotalNumber;idx++)
  13870. {
  13871. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13872. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13873. }
  13874. }
  13875. }
  13876. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13877. {
  13878. if(connectorIdIsNULL == FALSE)
  13879. {
  13880. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13881. {
  13882. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13883. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13884. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13885. }
  13886. }
  13887. else
  13888. {
  13889. for(int idx=0;idx< gunTotalNumber;idx++)
  13890. {
  13891. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13892. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13893. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13894. }
  13895. }
  13896. }
  13897. return result;
  13898. }
  13899. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13900. {
  13901. mtrace();
  13902. int result = FAIL;
  13903. int connectorIdInt =0;
  13904. char comfirmstr[20]={0};
  13905. int tempIndex = 0;
  13906. json_object *UnlockConnector;
  13907. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13908. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13909. UnlockConnector = json_tokener_parse(payload);
  13910. if(!is_error(UnlockConnector))
  13911. {
  13912. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13913. {
  13914. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13915. }
  13916. }
  13917. json_object_put(UnlockConnector);
  13918. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13919. if(gunTotalNumber == 0)
  13920. {
  13921. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13922. goto end;
  13923. }
  13924. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13925. {
  13926. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13927. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13928. goto end;
  13929. }
  13930. else
  13931. {
  13932. //check Transaction active
  13933. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13934. {
  13935. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13936. {
  13937. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13938. }
  13939. else
  13940. {
  13941. tempIndex = connectorIdInt -1;
  13942. }
  13943. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13944. {
  13945. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13946. {
  13947. //stop Transaction
  13948. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13949. }
  13950. }
  13951. }
  13952. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13953. {
  13954. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13955. {
  13956. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13957. }
  13958. else
  13959. {
  13960. tempIndex = connectorIdInt -1;
  13961. }
  13962. for (int index = 0; index < CCS_QUANTITY; index++)
  13963. {
  13964. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13965. {
  13966. //stop Transaction
  13967. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13968. }
  13969. }
  13970. }
  13971. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13972. {
  13973. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13974. {
  13975. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13976. }
  13977. else
  13978. {
  13979. tempIndex = connectorIdInt -1;
  13980. }
  13981. for (int index = 0; index < GB_QUANTITY; index++)
  13982. {
  13983. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13984. {
  13985. //stop Transaction
  13986. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13987. }
  13988. }
  13989. }
  13990. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13991. {
  13992. tempIndex = connectorIdInt -1;
  13993. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13994. {
  13995. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13996. {
  13997. //stop Transaction
  13998. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13999. }
  14000. }
  14001. }
  14002. else
  14003. {
  14004. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14005. {
  14006. tempIndex = 2;
  14007. }
  14008. else
  14009. {
  14010. tempIndex = connectorIdInt-1;
  14011. }
  14012. for (int index = 0; index < AC_QUANTITY; index++)
  14013. {
  14014. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  14015. {
  14016. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  14017. }
  14018. }
  14019. }
  14020. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  14021. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  14022. result = TRUE;
  14023. return result;
  14024. }
  14025. end:
  14026. //json_object_put(obj); --- remove temporally
  14027. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  14028. return result;
  14029. }
  14030. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  14031. {
  14032. mtrace();
  14033. int result = FAIL;
  14034. pthread_t t;
  14035. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  14036. sendUpdateFirmwareConfirmation(uuid);
  14037. if(!interLock.isUpdateFirmwareGoing)
  14038. {
  14039. interLock.isUpdateFirmwareGoing = 1;
  14040. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  14041. sleep(1);
  14042. }
  14043. else
  14044. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  14045. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  14046. return result;
  14047. }
  14048. void *UpdateFirmwareProcess(void *data)
  14049. {
  14050. pthread_detach(pthread_self());
  14051. mtrace();
  14052. int retriesInt =0, retryIntervalInt=0;
  14053. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  14054. int port=0;
  14055. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  14056. int isSuccess = 0;
  14057. char ftpbuf[1024];
  14058. char temp[1024];
  14059. char * pch;
  14060. json_object *UpdateFirmware;
  14061. UpdateFirmware = json_tokener_parse(data);
  14062. if(!is_error(UpdateFirmware))
  14063. {
  14064. // Required data
  14065. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  14066. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  14067. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  14068. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  14069. // Optional data
  14070. if(json_object_object_get(UpdateFirmware, "retries"))
  14071. {
  14072. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  14073. }
  14074. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  14075. {
  14076. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  14077. }
  14078. }
  14079. json_object_put(UpdateFirmware);
  14080. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14081. memset(path, 0, ARRAY_SIZE(path));
  14082. // Wait retrieveData
  14083. if(strlen(retrieveDatestr) > 10)
  14084. {
  14085. do
  14086. {
  14087. sleep(1);
  14088. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  14089. }
  14090. // Ready to download
  14091. system("rm -f /mnt/*");
  14092. if(strncmp(locationstr,"http", 4) == 0)
  14093. {
  14094. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14095. sprintf(ftppath,"/%s", path);
  14096. DEBUG_INFO("locationstr: %s\n", locationstr);
  14097. DEBUG_INFO("protocol: %s\n",protocol);
  14098. DEBUG_INFO("host: %s\n",host);
  14099. DEBUG_INFO("path: %s\n",path);
  14100. DEBUG_INFO("ftppath: %s\n",ftppath);
  14101. int ftppathlen=strlen(ftppath);
  14102. int i=1;
  14103. char filenametemp[50];
  14104. while(i < ftppathlen)
  14105. {
  14106. int len=ftppathlen-i;
  14107. if(ftppath[len]== 47) // '/' ascll code: 47
  14108. {
  14109. DEBUG_INFO("compare '/' all right\n");
  14110. break;
  14111. }
  14112. i=i+1;
  14113. }
  14114. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14115. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  14116. filenametemp[i+1] = 0;
  14117. do
  14118. {
  14119. sleep(1);
  14120. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  14121. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14122. sleep(1);
  14123. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  14124. if(!isSuccess)
  14125. {
  14126. sleep(1);
  14127. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  14128. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14129. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  14130. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  14131. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14132. }
  14133. else
  14134. {
  14135. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  14136. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14137. }
  14138. retriesInt--;
  14139. }while((isSuccess == 0)&&(retriesInt >= 0));
  14140. }
  14141. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  14142. {
  14143. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14144. memset(temp, 0, ARRAY_SIZE(temp));
  14145. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14146. strcpy(ftpbuf, locationstr);
  14147. int ftppathlen=strlen(ftpbuf);
  14148. int i=1;
  14149. char filenametemp[50];
  14150. while(i < ftppathlen)
  14151. {
  14152. int len=ftppathlen-i;
  14153. if(ftpbuf[len]== 47) // '/' ascii code: 47
  14154. {
  14155. DEBUG_INFO(" compare '/' all right\n");
  14156. break;
  14157. }
  14158. i=i+1;
  14159. }
  14160. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14161. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  14162. filenametemp[i+1] = 0;
  14163. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14164. pch=strchr(temp,'@');
  14165. if(pch==NULL)
  14166. {
  14167. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14168. protocol, host, &port, path);
  14169. strcpy(user,"anonymous");
  14170. strcpy(password,"");
  14171. }
  14172. else
  14173. {
  14174. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  14175. protocol, user, host, &port, path);
  14176. }
  14177. sscanf(host,"%[^/]%s",host1, path1);
  14178. sprintf(ftppath,"%s:/%s", host,path);
  14179. if(port == 0)
  14180. {
  14181. port = 21;
  14182. }
  14183. do
  14184. {
  14185. sleep(1);
  14186. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  14187. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14188. sleep(1);
  14189. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  14190. if(!isSuccess)
  14191. {
  14192. //BulldogUtil.sleepMs(interval*1000);
  14193. DEBUG_INFO("Update firmware request and download file fail.\n");
  14194. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  14195. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14196. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  14197. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  14198. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14199. }
  14200. else
  14201. {
  14202. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  14203. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14204. }
  14205. retriesInt--;
  14206. }while((!isSuccess)&&(retriesInt >= 0));
  14207. }
  14208. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  14209. {
  14210. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14211. memset(temp, 0, ARRAY_SIZE(temp));
  14212. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14213. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  14214. int ftppathlen=strlen(ftpbuf);
  14215. int i=1;
  14216. char filenametemp[50];
  14217. while(i < ftppathlen)
  14218. {
  14219. int len=ftppathlen-i;
  14220. if(ftpbuf[len]== 47) // '/' ascll code: 47
  14221. {
  14222. DEBUG_INFO(" compare '/' all right\n");
  14223. break;
  14224. }
  14225. i=i+1;
  14226. }
  14227. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14228. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  14229. filenametemp[i+1] = 0;
  14230. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14231. pch=strchr(temp,'@');
  14232. if(pch==NULL)
  14233. {
  14234. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14235. protocol, host, &port, path);
  14236. strcpy(user,"anonymous");
  14237. strcpy(password,"");
  14238. }
  14239. else
  14240. {
  14241. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14242. protocol, user, password, host, &port, path);
  14243. }
  14244. sscanf(host,"%[^/]%s",host1, path1);
  14245. sprintf(ftppath,"%s", path1);
  14246. //DEBUG_INFO("protocol =%s\n",protocol);
  14247. //DEBUG_INFO("user =%s\n",user);
  14248. //DEBUG_INFO("password =%s\n",password);
  14249. //DEBUG_INFO("host1 =%s\n",host1);
  14250. //DEBUG_INFO("port =%d\n",port);
  14251. //DEBUG_INFO("path1 =%s\n",path1);
  14252. //DEBUG_INFO("ftppath=%s\n",ftppath);
  14253. //ftpFile(host, user, password, port, ftppath, fname);
  14254. //download firmware pthred
  14255. if(port == 0)
  14256. {
  14257. port = 21;
  14258. }
  14259. do
  14260. {
  14261. sleep(1);
  14262. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  14263. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14264. sleep(1);
  14265. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  14266. if(!isSuccess)
  14267. {
  14268. //BulldogUtil.sleepMs(interval*1000);
  14269. DEBUG_INFO("Update firmware request and download file fail.\n");
  14270. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  14271. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14272. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  14273. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  14274. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14275. }
  14276. else
  14277. {
  14278. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  14279. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14280. }
  14281. retriesInt--;
  14282. }while((!isSuccess)&&(retriesInt >= 0));
  14283. }
  14284. else
  14285. {
  14286. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  14287. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14288. sleep(1);
  14289. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  14290. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14291. }
  14292. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)
  14293. {
  14294. sleep(3);
  14295. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  14296. }
  14297. interLock.isUpdateFirmwareGoing = 0;
  14298. pthread_exit(NULL);
  14299. }
  14300. int handleCertificateSignedRequest(char *uuid, char *payload)
  14301. {
  14302. mtrace();
  14303. int result = PASS;
  14304. json_object *CertificateSigned;
  14305. DEBUG_INFO("handleCertificateSignedRequest...\n");
  14306. CertificateSigned = json_tokener_parse(payload);
  14307. if(!is_error(CertificateSigned))
  14308. {
  14309. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  14310. }
  14311. json_object_put(CertificateSigned);
  14312. FILE *fp = fopen(CERTIFICATE_CP, "w");
  14313. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  14314. fclose(fp);
  14315. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14316. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  14317. if(certVerify(PRIVATE_KEY_CP, CERTIFICATE_CP) == PASS)
  14318. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  14319. else
  14320. {
  14321. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Rejected");
  14322. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  14323. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14324. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14325. }
  14326. sendCertificateSignedConfirmation(uuid);
  14327. return result;
  14328. }
  14329. int handleDeleteCertificateRequest(char *uuid, char *payload)
  14330. {
  14331. mtrace();
  14332. int result = PASS;
  14333. json_object *DeleteCertificate;
  14334. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  14335. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  14336. DeleteCertificate = json_tokener_parse(payload);
  14337. if(!is_error(DeleteCertificate))
  14338. {
  14339. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  14340. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  14341. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  14342. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  14343. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14344. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  14345. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  14346. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  14347. char temp[256] = {0};
  14348. char compareData[256] = {0};
  14349. int isMatch = TRUE;
  14350. FILE *fp;
  14351. if(access(ROOTCA_CS,F_OK) != -1)
  14352. {
  14353. // Check CentralSystemRootCertificate
  14354. DEBUG_INFO("Checking CentralSystemRootCertificate...\n");
  14355. parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, compareData);
  14356. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14357. isMatch = FALSE;
  14358. if(isMatch == TRUE)
  14359. {
  14360. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, compareData);
  14361. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14362. isMatch = FALSE;
  14363. }
  14364. if(isMatch == TRUE)
  14365. {
  14366. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, compareData);
  14367. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14368. isMatch = FALSE;
  14369. }
  14370. if(isMatch == TRUE)
  14371. {
  14372. sprintf(temp, "rm -f /Storage/OCPP/%s", ROOTCA_CS);
  14373. system(temp);
  14374. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14375. goto End;
  14376. }
  14377. }
  14378. // Check ManufacturerRootCertificate
  14379. if(access(ROOTCA_MFG,F_OK) != -1)
  14380. {
  14381. isMatch = TRUE;
  14382. parseCertInfo(ROOTCA_MFG, CERT_PARSE_SerialNumber, compareData);
  14383. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14384. isMatch = FALSE;
  14385. if(isMatch == TRUE)
  14386. {
  14387. parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerNameHash, compareData);
  14388. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14389. isMatch = FALSE;
  14390. }
  14391. if(isMatch == TRUE)
  14392. {
  14393. parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerKeyHash, compareData);
  14394. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14395. isMatch = FALSE;
  14396. }
  14397. if(isMatch == TRUE)
  14398. {
  14399. sprintf(temp, "rm -f %s", ROOTCA_MFG);
  14400. system(temp);
  14401. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14402. goto End;
  14403. }
  14404. }
  14405. // Check certCP
  14406. if(access(CERTIFICATE_CP,F_OK) != -1)
  14407. {
  14408. isMatch = FALSE;
  14409. sprintf(temp ,"openssl x509 -noout -serial -in %s", CERTIFICATE_CP);
  14410. fp = popen(temp, "r");
  14411. if(fp)
  14412. {
  14413. while(fgets(temp, sizeof(temp), fp) != NULL)
  14414. {
  14415. if(strstr(temp, "serial=") != NULL)
  14416. {
  14417. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14418. sscanf(temp, "%*[^=]=%s", compareData);
  14419. break;
  14420. }
  14421. }
  14422. }
  14423. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14424. isMatch = FALSE;
  14425. if(isMatch == TRUE)
  14426. {
  14427. memset(compareData, 0, ARRAY_SIZE(compareData));
  14428. sprintf(temp ,"openssl x509 -noout -issuer -in %s | openssl dgst -%s", CERTIFICATE_CP, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14429. fp = popen(temp, "r");
  14430. if(fp)
  14431. {
  14432. while(fgets(temp, sizeof(temp), fp) != NULL)
  14433. {
  14434. strcat(compareData, temp);
  14435. }
  14436. }
  14437. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) == NULL)
  14438. isMatch = FALSE;
  14439. }
  14440. if(isMatch == TRUE)
  14441. {
  14442. memset(compareData, 0, ARRAY_SIZE(compareData));
  14443. sprintf(temp ,"openssl x509 -noout -pubkey -in %s | openssl dgst -%s", CERTIFICATE_CP, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14444. fp = popen(temp, "r");
  14445. if(fp)
  14446. {
  14447. while(fgets(temp, sizeof(temp), fp) != NULL)
  14448. {
  14449. strcat(compareData, temp);
  14450. }
  14451. }
  14452. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14453. isMatch = FALSE;
  14454. }
  14455. if(isMatch == TRUE)
  14456. {
  14457. sprintf(temp, "rm -f %s", CERTIFICATE_CP);
  14458. system(temp);
  14459. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14460. goto End;
  14461. }
  14462. }
  14463. }
  14464. End:
  14465. json_object_put(DeleteCertificate);
  14466. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  14467. sendDeleteCertificateConfirmation(uuid);
  14468. return result;
  14469. }
  14470. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  14471. {
  14472. mtrace();
  14473. int result = PASS;
  14474. json_object *ExtendedTriggerMessage;
  14475. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  14476. ExtendedTriggerMessage = json_tokener_parse(payload);
  14477. if(!is_error(ExtendedTriggerMessage))
  14478. {
  14479. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  14480. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  14481. {
  14482. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  14483. }
  14484. else
  14485. {
  14486. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  14487. }
  14488. }
  14489. json_object_put(ExtendedTriggerMessage);
  14490. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  14491. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  14492. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  14493. {
  14494. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  14495. }
  14496. else
  14497. {
  14498. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  14499. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  14500. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  14501. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  14502. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  14503. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  14504. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  14505. {
  14506. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  14507. }
  14508. else
  14509. {
  14510. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  14511. }
  14512. }
  14513. sendExtendedTriggerMessageConfirmation(uuid);
  14514. //==========================
  14515. // Trigger message
  14516. //==========================
  14517. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  14518. {
  14519. //sendBootNotificationRequest();
  14520. server_sign = FALSE;
  14521. }
  14522. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  14523. {
  14524. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14525. }
  14526. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  14527. {
  14528. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  14529. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  14530. {
  14531. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  14532. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  14533. }
  14534. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14535. }
  14536. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  14537. {
  14538. refreshStartTimer(&clientTime.Heartbeat);
  14539. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  14540. }
  14541. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  14542. {
  14543. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14544. {
  14545. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  14546. }
  14547. else
  14548. {
  14549. for(int idx=0;idx< gunTotalNumber;idx++)
  14550. {
  14551. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  14552. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  14553. }
  14554. }
  14555. }
  14556. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  14557. {
  14558. char cmdBuf[1024]={0};
  14559. 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);
  14560. system(cmdBuf);
  14561. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  14562. }
  14563. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  14564. {
  14565. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14566. {
  14567. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  14568. }
  14569. else
  14570. {
  14571. for(int idx=0;idx< gunTotalNumber;idx++)
  14572. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  14573. }
  14574. }
  14575. return result;
  14576. }
  14577. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  14578. {
  14579. mtrace();
  14580. int result = PASS;
  14581. json_object *GetInstalledCertificateIds;
  14582. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  14583. GetInstalledCertificateIds = json_tokener_parse(payload);
  14584. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  14585. if(!is_error(GetInstalledCertificateIds))
  14586. {
  14587. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  14588. DEBUG_INFO("Requested Certificate: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14589. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "Accepted");
  14590. // Check CentralSystemRootCertificate
  14591. if((strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "CentralSystemRootCertificate")!= NULL) && (access(ROOTCA_CS,F_OK) != -1))
  14592. {
  14593. char parseData[512] = {0};
  14594. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14595. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14596. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_SerialNumber, parseData) == PASS)
  14597. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14598. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14599. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14600. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14601. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14602. }
  14603. else
  14604. {
  14605. DEBUG_INFO(">>> No CentralSystemRootCertificate found.\n");
  14606. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14607. }
  14608. // Check ManufacturerRootCertificate
  14609. if((strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "ManufacturerRootCertificate") != NULL) && (access(ROOTCA_MFG,F_OK) != -1))
  14610. {
  14611. char parseData[512] = {0};
  14612. if(parseCertInfo(ROOTCA_MFG, 1, parseData) == PASS)
  14613. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14614. if(parseCertInfo(ROOTCA_MFG, 1, parseData) == PASS)
  14615. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14616. if(parseCertInfo(ROOTCA_MFG, 1, parseData) == PASS)
  14617. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14618. if(parseCertInfo(ROOTCA_MFG, 1, parseData) == PASS)
  14619. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14620. }
  14621. else
  14622. {
  14623. DEBUG_INFO(">>> No ManufacturerRootCertificate found.\n");
  14624. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14625. }
  14626. }
  14627. json_object_put(GetInstalledCertificateIds);
  14628. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  14629. sendGetInstalledCertificateIdsConfirmation(uuid);
  14630. return result;
  14631. }
  14632. void* GetLogProcess(void* data)
  14633. {
  14634. pthread_detach(pthread_self());
  14635. mtrace();
  14636. 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};
  14637. int port=0;
  14638. int isSuccess = FALSE;
  14639. char cmdBuf[2048];
  14640. struct tm *tmNow;
  14641. time_t CurrentTime;
  14642. struct tm tmStart;
  14643. struct tm tmStop;
  14644. CurrentTime = time(NULL);
  14645. tmNow=localtime(&CurrentTime);
  14646. uint16_t targetYear, targetMonth;
  14647. json_object *GetLog;
  14648. DEBUG_INFO("GetLogProcess...\n");
  14649. GetLog = json_tokener_parse(data);
  14650. if(!is_error(GetLog))
  14651. {
  14652. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  14653. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  14654. if(json_object_object_get(GetLog, "retries") != NULL)
  14655. {
  14656. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  14657. }
  14658. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  14659. {
  14660. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  14661. }
  14662. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  14663. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  14664. {
  14665. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  14666. }
  14667. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  14668. {
  14669. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  14670. }
  14671. }
  14672. json_object_put(GetLog);
  14673. // Pack log to compress file
  14674. 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) &&
  14675. (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))
  14676. {
  14677. // Pack system log
  14678. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14679. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14680. targetYear = tmStart.tm_year;
  14681. targetMonth = tmStart.tm_mon;
  14682. do
  14683. {
  14684. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14685. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  14686. if(targetMonth+1>=13)
  14687. {
  14688. targetYear += 1;
  14689. targetMonth = 1;
  14690. }
  14691. else
  14692. {
  14693. targetMonth += 1;
  14694. }
  14695. }while((targetYear < (tmNow->tm_year+1900)) ||
  14696. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14697. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  14698. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  14699. system(cmdBuf);
  14700. // Pack charging & event log
  14701. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14702. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  14703. targetYear = tmStart.tm_year;
  14704. targetMonth = tmStart.tm_mon;
  14705. do
  14706. {
  14707. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14708. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  14709. if(targetMonth+1>=13)
  14710. {
  14711. targetYear += 1;
  14712. targetMonth = 1;
  14713. }
  14714. else
  14715. {
  14716. targetMonth += 1;
  14717. }
  14718. }while((targetYear < (tmNow->tm_year+1900)) ||
  14719. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14720. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  14721. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  14722. system(cmdBuf);
  14723. // Combine log file
  14724. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  14725. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  14726. }
  14727. else
  14728. {
  14729. system("exec /root/logPackTools 'log' 6");
  14730. }
  14731. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetLog.Response_filename);
  14732. system(cmdBuf);
  14733. checkUploadLog();
  14734. //****************location*******************/
  14735. if(strcmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"")==0)
  14736. {
  14737. DEBUG_INFO("location is <Empty>!\n");
  14738. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14739. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14740. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14741. goto end;
  14742. }
  14743. memset(protocol, 0, ARRAY_SIZE(protocol));
  14744. memset(user, 0, ARRAY_SIZE(user) );
  14745. memset(password, 0, ARRAY_SIZE(password));
  14746. memset(host, 0, ARRAY_SIZE(host));
  14747. memset(path, 0, ARRAY_SIZE(path));
  14748. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14749. memset(host1, 0, ARRAY_SIZE(host1));
  14750. memset(path1, 0, ARRAY_SIZE(path1));
  14751. /*location: ftp://user:password@host:port/path*/
  14752. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  14753. if((access(fnamePlusPath,F_OK))!=-1)
  14754. {
  14755. DEBUG_INFO("fnamePlusPath exist.\n");
  14756. }
  14757. else
  14758. {
  14759. DEBUG_INFO("fnamePlusPath not exist!\n");
  14760. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14761. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14762. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14763. goto end;
  14764. }
  14765. if(strchr((char*)ShmOCPP16Data->GetLog.log.remoteLocation,'@')==NULL)
  14766. {
  14767. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,
  14768. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14769. protocol, host, &port, path);
  14770. strcpy(user,"anonymous");
  14771. strcpy(password,"");
  14772. }
  14773. else
  14774. {
  14775. //DEBUG_INFO("pch=%s\n", pch);
  14776. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14777. protocol, user, password, host, &port, path);
  14778. }
  14779. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  14780. {
  14781. DEBUG_INFO("protocol is not ftp/http ! \n");
  14782. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14783. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14784. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14785. goto end;
  14786. }
  14787. if(strncmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"http", 4) == 0)
  14788. {
  14789. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14790. sprintf(ftppath,"/%s", path);
  14791. do
  14792. {
  14793. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14794. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14795. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14796. sleep(3);
  14797. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, (char*)ShmOCPP16Data->GetLog.log.remoteLocation);
  14798. if(!isSuccess)
  14799. {
  14800. DEBUG_INFO("Diagnostics fail.\n");
  14801. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14802. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14803. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14804. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14805. }
  14806. else
  14807. {
  14808. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14809. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14810. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14811. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14812. }
  14813. ShmOCPP16Data->GetLog.retries--;
  14814. }while((isSuccess == 0)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14815. }
  14816. else
  14817. {
  14818. sscanf(host,"%[^/]%s",host1, path1);
  14819. if(strlen(path) > 0)
  14820. sprintf(ftppath,"/%s", path);
  14821. else
  14822. sprintf(ftppath,"/%s", path1);
  14823. int ftppathlen=strlen(ftppath);
  14824. int i=1;
  14825. char filenametemp[50];
  14826. while(i < ftppathlen)
  14827. {
  14828. int len=ftppathlen-i;
  14829. if(ftppath[len]== 47) // '/' ascll code: 47
  14830. {
  14831. DEBUG_INFO("find '/' all right\n");
  14832. break;
  14833. }
  14834. i=i+1;
  14835. }
  14836. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14837. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  14838. filenametemp[i+1] = 0;
  14839. if(port == 0)
  14840. port = 21;
  14841. do
  14842. {
  14843. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14844. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14845. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14846. sleep(3);
  14847. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  14848. if(!isSuccess)
  14849. {
  14850. DEBUG_INFO("Diagnostics fail.\n");
  14851. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14852. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14853. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14854. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14855. }
  14856. else
  14857. {
  14858. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14859. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14860. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14861. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14862. }
  14863. ShmOCPP16Data->GetLog.retries--;
  14864. }while((!isSuccess)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14865. }
  14866. end:
  14867. system("rm -f /mnt/*");
  14868. sleep(5);
  14869. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14870. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Idle");
  14871. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14872. interLock.isGetDiagnosticGoing = 0;
  14873. pthread_exit(NULL);
  14874. }
  14875. int handleGetLogRequest(char *uuid, char *payload)
  14876. {
  14877. mtrace();
  14878. int result = PASS;
  14879. time_t CurrentTime;
  14880. struct tm *tm;
  14881. DEBUG_INFO("handleGetLogRequest...\n");
  14882. pthread_t th_Status;
  14883. CurrentTime = time(NULL);
  14884. tm = localtime(&CurrentTime);
  14885. memset(ShmOCPP16Data->GetLog.Response_filename, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetLog.Response_filename));
  14886. 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);
  14887. if(!interLock.isGetDiagnosticGoing)
  14888. {
  14889. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Accepted");
  14890. interLock.isGetDiagnosticGoing = 1;
  14891. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  14892. sleep(1);
  14893. }
  14894. else
  14895. {
  14896. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  14897. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  14898. }
  14899. sendGetLogConfirmation(uuid);
  14900. return result;
  14901. }
  14902. int handleInstallCertificateRequest(char *uuid, char *payload)
  14903. {
  14904. mtrace();
  14905. int result = PASS;
  14906. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  14907. json_object *InstallCertificate;
  14908. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14909. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14910. InstallCertificate = json_tokener_parse(payload);
  14911. if(!is_error(InstallCertificate))
  14912. {
  14913. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14914. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14915. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  14916. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  14917. char temp[1024];
  14918. FILE *fp = fopen(tempCert, "w");
  14919. fprintf(fp, "%s", ShmOCPP16Data->InstallCertificate.certificate);
  14920. fclose(fp);
  14921. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  14922. char strExpDate[30];
  14923. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  14924. fp = popen(temp, "r");
  14925. if(fp)
  14926. {
  14927. while(fgets(temp, sizeof(temp), fp) != NULL)
  14928. {
  14929. if(strstr(temp, "notAfter=") != NULL)
  14930. {
  14931. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14932. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  14933. break;
  14934. }
  14935. }
  14936. }
  14937. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  14938. struct tm tmExpDate;
  14939. struct timeb tbExpDate;
  14940. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  14941. tbExpDate.time = mktime(&tmExpDate);
  14942. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  14943. {
  14944. DEBUG_INFO("The enddate is already expired...\n");
  14945. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14946. goto End;
  14947. }
  14948. // Verify certificate with rootCA
  14949. sprintf(temp ,"openssl verify -CAfile /root/cacert.pem /Storage/OCPP/tempInstallCertificate.pem");
  14950. fp = popen(temp, "r");
  14951. if(fp)
  14952. {
  14953. while(fgets(temp, sizeof(temp), fp) != NULL)
  14954. {
  14955. if((strstr(temp, "tempInstallCertificate.pem: OK") != NULL) || (strstr(temp, "self signed certificate") != NULL))
  14956. {
  14957. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14958. break;
  14959. }
  14960. else
  14961. {
  14962. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14963. }
  14964. }
  14965. }
  14966. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14967. {
  14968. //=====================================================
  14969. // Verify if the certificate is valid or not. (OCSP?)
  14970. //=====================================================
  14971. /*
  14972. DEBUG_INFO("openssl CA verifying...FAIL --> Start OCSP process...\n");
  14973. // Get ocsp url
  14974. char ocspUrl[512];
  14975. sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", tempCert);
  14976. fp = popen(temp, "r");
  14977. if(fp)
  14978. {
  14979. while(fgets(temp, sizeof(temp), fp) != NULL)
  14980. {
  14981. if(strstr(temp, "://") != NULL)
  14982. {
  14983. strcpy(ocspUrl, temp);
  14984. break;
  14985. }
  14986. }
  14987. }
  14988. // Get certificate chain for issuer
  14989. * openssl s_client -connect [serverURL:port] -showcerts | sed -n '/-----BEGIN/,/-------END/p' > tempChain.pem
  14990. *
  14991. // Execute OCSP
  14992. sprintf(temp ,"openssl ocsp -issuer tempChain.pem -cert /Storage/OCPP/tempInstallCertificate.pem -text -url %s", ocspUrl);
  14993. fp = popen(temp, "r");
  14994. if(fp)
  14995. {
  14996. while(fgets(temp, sizeof(temp), fp) != NULL)
  14997. {
  14998. if(strstr(temp, "tempInstallCertificate.pem: good") != NULL)
  14999. {
  15000. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  15001. break;
  15002. }
  15003. }
  15004. }
  15005. system("rm -f /Storage/OCPP/tempChain.pem");
  15006. pclose(fp);
  15007. */
  15008. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  15009. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  15010. {
  15011. DEBUG_INFO("OCSP verifying...FAIL.\n");
  15012. goto End;
  15013. }
  15014. else
  15015. DEBUG_INFO("OCSP verifying...PASS.\n");
  15016. }
  15017. else
  15018. DEBUG_INFO("openssl CA verifying...PASS.\n");
  15019. }
  15020. End:
  15021. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") == 0)
  15022. {
  15023. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "CentralSystemRootCertificate") == 0)
  15024. {
  15025. if(access(ROOTCA_CS,F_OK) != -1)
  15026. {
  15027. DEBUG_INFO("Existed CentralSystemRootCertificate is found. Replacing...\n");
  15028. rename(ROOTCA_CS, "/Storage/OCPP/CentralSystemRootCertificate_fallback.pem");
  15029. rename(tempCert, ROOTCA_CS);
  15030. }
  15031. else
  15032. {
  15033. DEBUG_INFO("No existed CentralSystemRootCertificate. Creating...\n");
  15034. rename(tempCert, ROOTCA_CS);
  15035. }
  15036. }
  15037. else if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "ManufacturerRootCertificate") == 0)
  15038. {
  15039. if(access(ROOTCA_MFG,F_OK) != -1)
  15040. {
  15041. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  15042. rename(ROOTCA_MFG, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  15043. rename(tempCert, ROOTCA_MFG);
  15044. }
  15045. else
  15046. {
  15047. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  15048. rename(tempCert, ROOTCA_MFG);
  15049. }
  15050. }
  15051. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  15052. }
  15053. sendInstallCertificateConfirmation(uuid);
  15054. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  15055. {
  15056. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidCentralSystemCertificate");
  15057. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  15058. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  15059. }
  15060. json_object_put(InstallCertificate);
  15061. return result;
  15062. }
  15063. void *SignedUpdateFirmwareProcess(void *data)
  15064. {
  15065. pthread_detach(pthread_self());
  15066. mtrace();
  15067. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  15068. int port=0;
  15069. int isSuccess = 0;
  15070. char ftpbuf[1024];
  15071. char temp[1024];
  15072. char * pch;
  15073. char firmwareFileName[50];
  15074. DEBUG_INFO("SignedUpdateFirmwareProcess ...\n");
  15075. json_object *SignedUpdateFirmware;
  15076. SignedUpdateFirmware = json_tokener_parse(data);
  15077. if(!is_error(SignedUpdateFirmware))
  15078. {
  15079. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  15080. {
  15081. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  15082. }
  15083. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  15084. {
  15085. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  15086. }
  15087. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  15088. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  15089. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  15090. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  15091. {
  15092. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  15093. }
  15094. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  15095. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  15096. }
  15097. json_object_put(SignedUpdateFirmware);
  15098. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  15099. memset(path, 0, ARRAY_SIZE(path));
  15100. // Wait retrieveData
  15101. if(strlen((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location) > 10)
  15102. {
  15103. do
  15104. {
  15105. sleep(1);
  15106. }while(!isOvertNow((uint8_t*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime));
  15107. }
  15108. // Ready to download
  15109. system("rm -f /mnt/*");
  15110. if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"http", 4) == 0)
  15111. {
  15112. sscanf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  15113. sprintf(ftppath,"/%s", path);
  15114. DEBUG_INFO("locationstr: %s\n", (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15115. DEBUG_INFO("protocol: %s\n",protocol);
  15116. DEBUG_INFO("host: %s\n",host);
  15117. DEBUG_INFO("path: %s\n",path);
  15118. DEBUG_INFO("ftppath: %s\n",ftppath);
  15119. int ftppathlen=strlen(ftppath);
  15120. int i=1;
  15121. while(i < ftppathlen)
  15122. {
  15123. int len=ftppathlen-i;
  15124. if(ftppath[len]== 47) // '/' ascll code: 47
  15125. {
  15126. DEBUG_INFO("compare '/' all right\n");
  15127. break;
  15128. }
  15129. i=i+1;
  15130. }
  15131. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  15132. strncpy(firmwareFileName, ftppath+(ftppathlen-i+1), i+1);
  15133. firmwareFileName[i+1] = 0;
  15134. do
  15135. {
  15136. sleep(1);
  15137. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15138. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  15139. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15140. sleep(1);
  15141. isSuccess = httpDownLoadFile(host, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15142. if(!isSuccess)
  15143. {
  15144. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15145. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15146. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15147. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  15148. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15149. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15150. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15151. }
  15152. else
  15153. {
  15154. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15155. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  15156. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15157. }
  15158. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15159. }while((isSuccess == 0)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15160. }
  15161. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"sftp", 4) == 0) // sftp
  15162. {
  15163. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15164. memset(temp, 0, ARRAY_SIZE(temp));
  15165. //DEBUG_INFO("locationstr=%s\n",locationstr);
  15166. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15167. int ftppathlen=strlen(ftpbuf);
  15168. int i=1;
  15169. while(i < ftppathlen)
  15170. {
  15171. int len=ftppathlen-i;
  15172. if(ftpbuf[len]== 47) // '/' ascii code: 47
  15173. {
  15174. DEBUG_INFO(" compare '/' all right\n");
  15175. break;
  15176. }
  15177. i=i+1;
  15178. }
  15179. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  15180. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  15181. firmwareFileName[i+1] = 0;
  15182. strncpy(temp, ftpbuf, ftppathlen-i+1);
  15183. pch=strchr(temp,'@');
  15184. if(pch==NULL)
  15185. {
  15186. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15187. protocol, host, &port, path);
  15188. strcpy(user,"anonymous");
  15189. strcpy(password,"");
  15190. }
  15191. else
  15192. {
  15193. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  15194. protocol, user, host, &port, path);
  15195. }
  15196. sscanf(host,"%[^/]%s",host1, path1);
  15197. sprintf(ftppath,"%s:/%s", host,path);
  15198. if(port == 0)
  15199. {
  15200. port = 21;
  15201. }
  15202. do
  15203. {
  15204. sleep(1);
  15205. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15206. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  15207. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15208. sleep(1);
  15209. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15210. if(!isSuccess)
  15211. {
  15212. sleep(1);
  15213. DEBUG_INFO("Update firmware request and download file fail.\n");
  15214. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15215. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15216. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15217. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  15218. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15219. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15220. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15221. }
  15222. else
  15223. {
  15224. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15225. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  15226. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15227. }
  15228. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15229. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15230. }
  15231. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"ftp", 3) == 0) // ftp
  15232. {
  15233. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15234. memset(temp, 0, ARRAY_SIZE(temp));
  15235. //DEBUG_INFO("locationstr=%s\n",locationstr);
  15236. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15237. int ftppathlen=strlen(ftpbuf);
  15238. int i=1;
  15239. while(i < ftppathlen)
  15240. {
  15241. int len=ftppathlen-i;
  15242. if(ftpbuf[len]== 47) // '/' ascll code: 47
  15243. {
  15244. DEBUG_INFO(" compare '/' all right\n");
  15245. break;
  15246. }
  15247. i=i+1;
  15248. }
  15249. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  15250. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  15251. firmwareFileName[i+1] = 0;
  15252. strncpy(temp, ftpbuf, ftppathlen-i+1);
  15253. pch=strchr(temp,'@');
  15254. if(pch==NULL)
  15255. {
  15256. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15257. protocol, host, &port, path);
  15258. strcpy(user,"anonymous");
  15259. strcpy(password,"");
  15260. }
  15261. else
  15262. {
  15263. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  15264. protocol, user, password, host, &port, path);
  15265. }
  15266. sscanf(host,"%[^/]%s",host1, path1);
  15267. sprintf(ftppath,"%s", path1);
  15268. //DEBUG_INFO("protocol =%s\n",protocol);
  15269. //DEBUG_INFO("user =%s\n",user);
  15270. //DEBUG_INFO("password =%s\n",password);
  15271. //DEBUG_INFO("host1 =%s\n",host1);
  15272. //DEBUG_INFO("port =%d\n",port);
  15273. //DEBUG_INFO("path1 =%s\n",path1);
  15274. //DEBUG_INFO("ftppath=%s\n",ftppath);
  15275. //ftpFile(host, user, password, port, ftppath, fname);
  15276. //download firmware pthred
  15277. if(port == 0)
  15278. {
  15279. port = 21;
  15280. }
  15281. do
  15282. {
  15283. sleep(1);
  15284. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15285. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  15286. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15287. sleep(1);
  15288. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15289. if(!isSuccess)
  15290. {
  15291. //BulldogUtil.sleepMs(interval*1000);
  15292. DEBUG_INFO("Update firmware request and download file fail.\n");
  15293. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15294. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15295. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15296. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  15297. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15298. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15299. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15300. }
  15301. else
  15302. {
  15303. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15304. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  15305. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15306. }
  15307. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15308. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15309. }
  15310. else
  15311. {
  15312. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15313. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15314. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15315. sleep(1);
  15316. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15317. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15318. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15319. }
  15320. // Verify firmware image signature
  15321. struct stat st;
  15322. FILE *fp = fopen("/tmp/signingFirmwareUpdate.crt", "w");
  15323. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  15324. fclose(fp);
  15325. system("openssl x509 -pubkey -noout -in /tmp/signingFirmwareUpdate.crt > /tmp/signingFirmwareUpdate.key");
  15326. fp = fopen("/tmp/signingFirmwareUpdate.sign", "w");
  15327. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  15328. fclose(fp);
  15329. system("openssl base64 -d -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15330. stat("/tmp/signingFirmwareUpdate.sign.256", &st);
  15331. if(st.st_size == 0)
  15332. system("openssl base64 -d -A -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15333. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "Downloaded") != NULL)
  15334. {
  15335. sprintf(temp ,"openssl dgst -verify /tmp/signingFirmwareUpdate.key -signature /tmp/signingFirmwareUpdate.sign.256 /mnt/%s", firmwareFileName);
  15336. fp = popen(temp, "r");
  15337. if(fp)
  15338. {
  15339. while(fgets(temp, sizeof(temp), fp) != NULL)
  15340. {
  15341. if(strstr(temp, "Verified OK") != NULL)
  15342. {
  15343. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15344. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "SignatureVerified");
  15345. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15346. }
  15347. else
  15348. {
  15349. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15350. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InvalidSignature");
  15351. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15352. sleep(1);
  15353. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15354. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InstallationFailed");
  15355. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15356. sleep(1);
  15357. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15358. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15359. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15360. }
  15361. break;
  15362. }
  15363. }
  15364. pclose(fp);
  15365. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "SignatureVerified") != NULL)ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  15366. }
  15367. interLock.isUpdateFirmwareGoing = 0;
  15368. pthread_exit(NULL);
  15369. }
  15370. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  15371. {
  15372. mtrace();
  15373. int result = PASS;
  15374. pthread_t t;
  15375. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  15376. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Accepted");
  15377. sendSignedUpdateFirmwareConfirmation(uuid);
  15378. if(!interLock.isUpdateFirmwareGoing)
  15379. {
  15380. interLock.isUpdateFirmwareGoing = 1;
  15381. pthread_create(&t, NULL, SignedUpdateFirmwareProcess, payload);
  15382. sleep(1);
  15383. }
  15384. else
  15385. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  15386. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareConf = 1;
  15387. return result;
  15388. }
  15389. int handleUnknownRequest(char *uuid, char *payload)
  15390. {
  15391. mtrace();
  15392. int result = PASS;
  15393. DEBUG_INFO("handleUnknownRequest...\n");
  15394. sendUnknownConfirmation(uuid);
  15395. return result;
  15396. }
  15397. //==========================================
  15398. // Handle server response routine
  15399. //==========================================
  15400. void handleAuthorizeResponse(char *payload, int gun_index)
  15401. {
  15402. mtrace();
  15403. char expiryDatestr[36]={0};
  15404. char parentIdTagstr[21]={0};
  15405. char statusstr[20]={0};
  15406. int expiryDateISNULL=FALSE;
  15407. int parentIdTagISNULL=FALSE;
  15408. DEBUG_INFO("handleAuthorizeResponse...\n");
  15409. json_object *Authorize;
  15410. Authorize = json_tokener_parse(payload);
  15411. if(!is_error(Authorize))
  15412. {
  15413. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  15414. {
  15415. // Required data
  15416. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  15417. // Optional data
  15418. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  15419. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  15420. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  15421. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  15422. }
  15423. }
  15424. json_object_put(Authorize);
  15425. if(expiryDateISNULL == FALSE)
  15426. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  15427. if(parentIdTagISNULL == FALSE)
  15428. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  15429. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  15430. //Update idTag information to authorization cache if supproted
  15431. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  15432. {
  15433. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  15434. }
  15435. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  15436. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  15437. authorizeRetryTimes = 0;
  15438. }
  15439. void handleBootNotificationResponse(char *payload, int gun_index)
  15440. {
  15441. mtrace();
  15442. char statusStr[12]={0};
  15443. char currentTimeStr[30]={0};
  15444. int intervalInt = 0;
  15445. DEBUG_INFO("handleBootNotificationResponse...\n");
  15446. json_object *BootNotification;
  15447. BootNotification = json_tokener_parse(payload);
  15448. if(!is_error(BootNotification))
  15449. {
  15450. // Required data
  15451. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  15452. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  15453. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  15454. }
  15455. json_object_put(BootNotification);
  15456. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15457. BootNotificationInterval = intervalInt;
  15458. //write back to ShmOCPP16Data->BootNotification
  15459. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  15460. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15461. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  15462. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  15463. {
  15464. BootNotificationInterval = 0;
  15465. if((intervalInt == 0) || (intervalInt >= 10))
  15466. {
  15467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  15468. HeartBeatWaitTime = intervalInt;
  15469. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  15470. }
  15471. server_sign = TRUE;
  15472. server_pending =FALSE;
  15473. }
  15474. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  15475. {
  15476. server_pending = TRUE;
  15477. }
  15478. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  15479. srand(time(NULL));
  15480. refreshStartTimer(&clientTime.Heartbeat);
  15481. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  15482. SetOcppConnStatus(TRUE);
  15483. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  15484. }
  15485. void handleDataTransferResponse(char *payload, int gun_index)
  15486. {
  15487. json_object *DataTransfer = json_tokener_parse(payload);
  15488. DEBUG_INFO("Corresponding gun-%d MessageId: %s\n", gun_index, ShmOCPP16Data->DataTransfer[gun_index].MessageId);
  15489. if(!is_error(DataTransfer))
  15490. {
  15491. // Required data
  15492. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  15493. // Optional data
  15494. if(json_object_object_get(DataTransfer, "data") != NULL)
  15495. {
  15496. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15497. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15498. if(!is_error(Data))
  15499. {
  15500. if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Authorize") != NULL)
  15501. {
  15502. if(json_object_object_get(Data, "certificateStatus") != NULL)
  15503. {
  15504. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "%s", json_object_get_string(json_object_object_get(Data, "certificateStatus")));
  15505. }
  15506. if(json_object_object_get(Data, "idTokenInfo") != NULL)
  15507. {
  15508. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "status") != NULL)
  15509. {
  15510. 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")));
  15511. }
  15512. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "cacheExpiryDateTime") != NULL)
  15513. {
  15514. 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")));
  15515. }
  15516. }
  15517. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  15518. }
  15519. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Get15118EVCertificate") != NULL)
  15520. {
  15521. if(json_object_object_get(Data, "status") != NULL)
  15522. {
  15523. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15524. }
  15525. if(json_object_object_get(Data, "exiResponse") != NULL)
  15526. {
  15527. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_exiResponse, "%s", json_object_get_string(json_object_object_get(Data, "exiResponse")));
  15528. }
  15529. ShmOCPP16Data->v2g_extend.Get15118EVCertificateConf = 1;
  15530. }
  15531. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "GetCertificateStatus") != NULL)
  15532. {
  15533. if(json_object_object_get(Data, "status") != NULL)
  15534. {
  15535. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15536. }
  15537. if(json_object_object_get(Data, "ocspResult") != NULL)
  15538. {
  15539. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_ocspResult, "%s", json_object_get_string(json_object_object_get(Data, "ocspResult")));
  15540. }
  15541. ShmOCPP16Data->v2g_extend.GetCertificateStatusConf = 1;
  15542. }
  15543. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "SignCertificate") != NULL)
  15544. {
  15545. sprintf((char*)ShmOCPP16Data->v2g_extend.SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15546. ShmOCPP16Data->v2g_extend.SignCertificateConf = 1;
  15547. }
  15548. else
  15549. {
  15550. if(json_object_object_get(Data, "msgId") != NULL)
  15551. {
  15552. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  15553. {
  15554. 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")));
  15555. }
  15556. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  15557. {
  15558. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15559. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  15560. }
  15561. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_GetOccupancyFee") != NULL)
  15562. {
  15563. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15564. {
  15565. if(json_object_object_get(Data, "occupancySN") != NULL)
  15566. sprintf((char*)ShmOCPP16Data->TcciCustomData.GetOccupancyFee[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_occupancySN, "%s", json_object_get_string(json_object_object_get(Data, "occupancySN")));
  15567. if(json_object_object_get(Data, "startTime") != NULL)
  15568. sprintf((char*)ShmOCPP16Data->TcciCustomData.GetOccupancyFee[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_startTime, "%s", json_object_get_string(json_object_object_get(Data, "startTime")));
  15569. if(json_object_object_get(Data, "duration") != NULL)
  15570. ShmOCPP16Data->TcciCustomData.GetOccupancyFee[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_duration = json_object_get_int(json_object_object_get(Data, "duration"));
  15571. if(json_object_object_get(Data, "occupancyFee") != NULL)
  15572. ShmOCPP16Data->TcciCustomData.GetOccupancyFee[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].response_occupancyFee = json_object_get_double(json_object_object_get(Data, "occupancyFee"));
  15573. }
  15574. ShmOCPP16Data->TcciCustomData.GetOccupancyFee[gun_index].GetOccupancyFeeReq = 0;
  15575. }
  15576. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_OccupancyFeeResult") != NULL)
  15577. {
  15578. if(json_object_object_get(Data, "occupancySN") != NULL)
  15579. OCPP_update_occupancyDeduct_info((char*)json_object_get_string(json_object_object_get(Data, "occupancySN")));
  15580. }
  15581. }
  15582. }
  15583. }
  15584. json_object_put(Data);
  15585. }
  15586. }
  15587. json_object_put(DataTransfer);
  15588. }
  15589. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  15590. {
  15591. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  15592. //struct json_object *obj;
  15593. // obj = json_tokener_parse(payload);
  15594. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  15595. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  15596. //No fields are defined.
  15597. }
  15598. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15599. {
  15600. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  15601. //struct json_object *obj;
  15602. // obj = json_tokener_parse(payload);
  15603. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  15604. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  15605. //No fields are defined.
  15606. }
  15607. void handleHeartbeatResponse(char *payload, int gun_index)
  15608. {
  15609. mtrace();
  15610. DEBUG_INFO("handleHeartbeatResponse...\n");
  15611. json_object *Heartbeat;
  15612. Heartbeat = json_tokener_parse(payload);
  15613. if(!is_error(Heartbeat))
  15614. {
  15615. // Required data
  15616. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  15617. }
  15618. json_object_put(Heartbeat);
  15619. if(FirstHeartBeat == 0)
  15620. {
  15621. FirstHeartBeat = 1;
  15622. DEBUG_INFO("FirstHeartBeat \n");
  15623. }
  15624. HeartBeatWithNOResponse = 0;
  15625. refreshStartTimer(&clientTime.Heartbeat);
  15626. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  15627. }
  15628. void handleMeterValuesResponse(char *payload, int gun_index)
  15629. {
  15630. mtrace();
  15631. DEBUG_INFO("handleMeterValuesResponse...\n");
  15632. isQueueSendable = 1;
  15633. }
  15634. void handleStartTransactionResponse(char *payload, int gun_index)
  15635. {
  15636. mtrace();
  15637. //int transactionIdInt = 0;
  15638. FILE *outfile;
  15639. char data[100]={0};
  15640. DEBUG_INFO("handleStartTransactionResponse...\n");
  15641. json_object *StartTransaction;
  15642. StartTransaction = json_tokener_parse(payload);
  15643. if(!is_error(StartTransaction))
  15644. {
  15645. // Required data
  15646. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  15647. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  15648. // Optional data
  15649. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  15650. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  15651. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15652. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  15653. }
  15654. json_object_put(StartTransaction);
  15655. OCPP_updatePeriodEnergy(gun_index);
  15656. //-----------Start : write to the Queue TransactionId file -----------------//
  15657. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  15658. {}
  15659. else
  15660. {
  15661. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  15662. if(log == NULL)
  15663. {
  15664. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  15665. return ;
  15666. }
  15667. else
  15668. {
  15669. fclose(log);
  15670. }
  15671. }
  15672. // open file for writing
  15673. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  15674. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  15675. {
  15676. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  15677. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  15678. fputs(data, outfile);
  15679. fclose (outfile);
  15680. }
  15681. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15682. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15683. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  15684. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  15685. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15686. isQueueSendable = 1;
  15687. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  15688. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  15689. }
  15690. void handleStatusNotificationResponse(char *payload, int gun_index)
  15691. {
  15692. mtrace();
  15693. DEBUG_INFO("handleStatusNotificationResponse...\n");
  15694. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15695. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15696. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  15697. }
  15698. void handleStopTransactionnResponse(char *payload, int gun_index)
  15699. {
  15700. mtrace();
  15701. DEBUG_INFO("handleStopTransactionnResponse...\n");
  15702. json_object *StopTransaction;
  15703. StopTransaction = json_tokener_parse(payload);
  15704. if(!is_error(StopTransaction))
  15705. {
  15706. // Optional data
  15707. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  15708. {
  15709. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  15710. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  15711. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  15712. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15713. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  15714. }
  15715. }
  15716. json_object_put(StopTransaction);
  15717. isQueueSendable = 1;
  15718. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  15719. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  15720. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15721. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15722. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  15723. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  15724. }
  15725. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  15726. {
  15727. mtrace();
  15728. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  15729. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  15730. }
  15731. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  15732. {
  15733. mtrace();
  15734. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  15735. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  15736. }
  15737. void handleSignCertificateResponse(char *payload, int gun_index)
  15738. {
  15739. mtrace();
  15740. DEBUG_INFO("handleSignCertificateResponse...\n");
  15741. json_object *SignCertificate;
  15742. SignCertificate = json_tokener_parse(payload);
  15743. if(!is_error(SignCertificate))
  15744. {
  15745. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  15746. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  15747. }
  15748. json_object_put(SignCertificate);
  15749. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  15750. }
  15751. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15752. {
  15753. mtrace();
  15754. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  15755. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  15756. }
  15757. //==========================================
  15758. // Handle Error routine
  15759. //==========================================
  15760. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  15761. {
  15762. mtrace();
  15763. #ifdef SystemLogMessage
  15764. DEBUG_INFO("errorCode: %s\n", errorCode);
  15765. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  15766. DEBUG_INFO("errorDetails: %s\n", payload);
  15767. #endif
  15768. }
  15769. //===============================================
  15770. // Common routine
  15771. //===============================================
  15772. int initialConfigurationTable(void)
  15773. {
  15774. //clock_t start_t, end_t, total_t;
  15775. FILE *fp;
  15776. FILE *outfile;
  15777. char str[512]={0};
  15778. char sstr[256]={0};
  15779. int c = 0;
  15780. char *loc;
  15781. int confVersion = 21;
  15782. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  15783. //start_t = clock();
  15784. //printf("Starting of the program, start_t = %ld\n", start_t);
  15785. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  15786. // Check configuration file size is correct
  15787. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  15788. {
  15789. struct stat st;
  15790. stat("/Storage/OCPP/OCPPConfiguration", &st);
  15791. if(st.st_size < 3100)
  15792. {
  15793. system("rm -f /Storage/OCPP/OCPPConfiguration");
  15794. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  15795. }
  15796. }
  15797. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  15798. {
  15799. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15800. if(outfile == NULL)
  15801. {
  15802. DEBUG_INFO("Error opening file\n");
  15803. return FALSE;
  15804. }
  15805. /*Core Profile*/
  15806. //AllowOfflineTxForUnknownId
  15807. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  15810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15811. //AuthorizationCacheEnabled
  15812. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15816. //AuthorizeRemoteTxRequests
  15817. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  15818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  15820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15821. //BlinkRepeat
  15822. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15826. //ClockAlignedDataInterval
  15827. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15830. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15831. //ConnectionTimeOut
  15832. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15834. if(ShmSysConfigAndInfo->SysConfig.ModelName[3]=='J')
  15835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "55" );
  15836. else
  15837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15838. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15839. //GetConfigurationMaxKeys
  15840. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15842. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  15843. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15844. // HeartbeatInterval
  15845. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  15848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15849. // LightIntensity
  15850. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15854. // LocalAuthorizeOffline
  15855. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  15856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15858. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15859. // LocalPreAuthorize
  15860. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  15861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15864. // MaxEnergyOnInvalidId
  15865. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15869. // MeterValuesAlignedData
  15870. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15872. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15873. 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" );
  15874. else
  15875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15877. // MeterValuesAlignedDataMaxLength
  15878. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15880. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  15882. else
  15883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  15884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15885. // MeterValuesSampledData
  15886. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15888. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15889. 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" );
  15890. else
  15891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15893. // MeterValuesSampledDataMaxLength
  15894. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15896. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  15898. else
  15899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  15900. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15901. // MeterValueSampleInterval
  15902. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15904. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  15905. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15906. // MinimumStatusDuration
  15907. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  15910. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  15911. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15912. // NumberOfConnectors
  15913. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15915. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15916. {
  15917. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15918. }
  15919. else
  15920. {
  15921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15922. }
  15923. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15924. // ResetRetries
  15925. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15929. // ConnectorPhaseRotation
  15930. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15934. // ConnectorPhaseRotationMaxLength
  15935. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15939. // StopTransactionOnEVSideDisconnect
  15940. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  15941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15943. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15944. // StopTransactionOnInvalidId
  15945. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  15946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15948. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15949. // StopTxnAlignedData
  15950. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  15953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15954. // StopTxnAlignedDataMaxLength
  15955. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  15958. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15959. // StopTxnSampledData
  15960. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15962. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  15964. else
  15965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  15966. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15967. // StopTxnSampledDataMaxLength
  15968. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15970. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15971. {
  15972. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  15973. }
  15974. else
  15975. {
  15976. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  15977. }
  15978. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15979. // SupportedFeatureProfiles
  15980. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15983. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15984. // SupportedFeatureProfilesMaxLength
  15985. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15989. // TransactionMessageAttempts
  15990. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15993. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15995. // TransactionMessageRetryInterval
  15996. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15999. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16000. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16001. // UnlockConnectorOnEVSideDisconnect
  16002. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  16003. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  16004. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  16005. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  16006. // WebSocketPingInterval
  16007. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  16008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  16009. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  16010. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16011. // QueueOffLineMeterValues
  16012. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  16013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  16014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  16015. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  16016. // AuthorizationKey
  16017. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  16018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  16019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  16020. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16021. // SecurityProfile
  16022. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  16023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  16024. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  16025. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16026. // DefaultPrice
  16027. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  16028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  16029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  16030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16031. // CustomDisplayCostAndPrice
  16032. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  16033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  16034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  16035. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  16036. // CustomIdleFeeAfterStop
  16037. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  16038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  16039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  16040. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  16041. // TimeOffset
  16042. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  16043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  16044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  16045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  16046. // NextTimeOffsetTransitionDateTime
  16047. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  16048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  16049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  16050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  16051. // TimeOffsetNextTransition
  16052. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  16053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  16054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  16055. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  16056. // SystemUptimeSec
  16057. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  16058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  16059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  16060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  16061. // FreeVend
  16062. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  16063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  16064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  16065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  16066. // FreeVendIdtag
  16067. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  16068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  16069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  16070. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16071. // OcppServer
  16072. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  16073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  16074. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  16075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16076. // MaintainServer
  16077. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  16078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  16079. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  16080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16081. // StatusNotificationPeriodically
  16082. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  16083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  16084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  16085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  16086. // StatusNotificationInterval
  16087. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  16088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  16089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  16090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  16091. // PreAuthAmount
  16092. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  16093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  16094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  16095. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  16096. // isEnableLocalPowerSharing
  16097. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  16098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  16099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  16100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  16101. // PowerSharingServerIP
  16102. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  16103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  16104. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  16105. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  16106. // EVCCID_PREFIX
  16107. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  16108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  16109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  16110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  16111. // OffLineMaxChargingPower
  16112. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  16113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  16114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  16115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  16116. // Configuration Version
  16117. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  16118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  16119. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  16120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  16121. // Charging profile refresh interval
  16122. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  16123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  16124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  16125. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  16126. // CpoName
  16127. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  16128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  16129. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "Zerova");
  16130. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  16131. // Ocpp Software certificated version
  16132. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  16133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  16134. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  16135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  16136. //* Local Auth List Management Profile*/
  16137. #if 0
  16138. //For OCTT Test Case
  16139. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  16140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  16141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  16142. #endif
  16143. #if 1
  16144. //LocalAuthListEnabled
  16145. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  16146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  16147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  16148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16149. #endif
  16150. //LocalAuthListMaxLength
  16151. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  16152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  16153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  16154. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  16155. //SendLocalListMaxLength
  16156. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  16157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  16158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  16159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  16160. //ReserveConnectorZeroSupported
  16161. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  16162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  16163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  16164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16165. //* Smart Charging Profile */
  16166. //ChargeProfileMaxStackLevel
  16167. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  16168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  16169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  16170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16171. // ChargingScheduleAllowedChargingRateUnit
  16172. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  16173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  16174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  16175. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16176. // ChargingScheduleMaxPeriods
  16177. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  16178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  16179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  16180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16181. // ConnectorSwitch3to1PhaseSupported
  16182. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  16183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  16184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  16185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16186. // MaxChargingProfilesInstalled
  16187. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  16188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  16189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  16190. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16191. fclose(outfile);
  16192. }
  16193. else
  16194. {
  16195. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  16196. char keystr[60]={0};
  16197. char readonlystr[10]={0};
  16198. char valuestr[256]={0};
  16199. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  16200. if(fp == NULL) {
  16201. DEBUG_INFO("Error opening file");
  16202. return FALSE;
  16203. }
  16204. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  16205. {
  16206. //DEBUG_INFO("Get Configuration \n");
  16207. if(strlen(str) > 0)
  16208. {
  16209. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16210. //*************************key*********************************/
  16211. if(strstr(str, "key") != NULL)
  16212. {
  16213. loc = strstr(str, "key");
  16214. c = 0;
  16215. memset(sstr ,0, ARRAY_SIZE(sstr) );
  16216. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  16217. {
  16218. sstr[c] = loc[strlen("key")+3+c];
  16219. c++;
  16220. }
  16221. sstr[c] = '\0';
  16222. strcpy(keystr,sstr);
  16223. }
  16224. //*************************readonly*********************************/
  16225. if(strstr(str, "readonly") != NULL)
  16226. {
  16227. loc = strstr(str, "readonly");
  16228. c = 0;
  16229. memset(sstr ,0, ARRAY_SIZE(sstr) );
  16230. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  16231. {
  16232. sstr[c] = loc[strlen("readonly")+2+c];
  16233. c++;
  16234. }
  16235. sstr[c] = '\0';
  16236. strcpy(readonlystr,sstr);
  16237. }
  16238. //*************************value*********************************/
  16239. if(strstr(str, "value") != NULL)
  16240. {
  16241. loc = strstr(str, "value");
  16242. c = 0;
  16243. memset(sstr ,0, ARRAY_SIZE(sstr) );
  16244. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  16245. {
  16246. sstr[c] = loc[strlen("value")+3+c];
  16247. c++;
  16248. }
  16249. sstr[c] = '\0';
  16250. strcpy(valuestr,sstr);
  16251. }
  16252. // DEBUG_INFO("keystr=%s\n",keystr);
  16253. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  16254. // DEBUG_INFO("valuestr=%s\n",valuestr);
  16255. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  16256. {
  16257. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16258. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16259. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  16260. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  16261. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  16262. }
  16263. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  16264. {
  16265. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16266. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16267. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  16268. }
  16269. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  16270. {
  16271. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16272. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  16273. }
  16274. if(strcmp(keystr, "BlinkRepeat") == 0)
  16275. {
  16276. //Charger.BlinkRepeat = Integer.parseInt(value);
  16277. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16278. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  16279. }
  16280. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  16281. {
  16282. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16283. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  16284. }
  16285. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  16286. {
  16287. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16288. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  16289. }
  16290. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  16291. {
  16292. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16293. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  16294. }
  16295. if(strcmp(keystr, "HeartbeatInterval") == 0)
  16296. {
  16297. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16298. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  16299. HeartBeatWaitTime = atoi(valuestr);
  16300. }
  16301. if(strcmp(keystr, "LightIntensity") == 0)
  16302. {
  16303. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16304. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  16305. }
  16306. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  16307. {
  16308. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16309. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  16310. }
  16311. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  16312. {
  16313. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16314. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  16315. }
  16316. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  16317. {
  16318. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16319. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  16320. }
  16321. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  16322. {
  16323. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16324. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  16325. }
  16326. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  16327. {
  16328. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16329. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  16330. }
  16331. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  16332. {
  16333. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16334. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  16335. }
  16336. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  16337. {
  16338. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16339. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  16340. }
  16341. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  16342. {
  16343. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16344. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  16345. }
  16346. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  16347. {
  16348. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16349. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  16350. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  16351. }
  16352. if(strcmp(keystr, "NumberOfConnectors") == 0)
  16353. {
  16354. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16355. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  16356. }
  16357. if(strcmp(keystr, "ResetRetries") == 0)
  16358. {
  16359. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16360. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  16361. }
  16362. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  16363. {
  16364. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16365. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  16366. }
  16367. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  16368. {
  16369. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16370. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  16371. }
  16372. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  16373. {
  16374. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16375. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  16376. }
  16377. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  16378. {
  16379. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16380. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  16381. }
  16382. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  16383. {
  16384. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16385. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  16386. }
  16387. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  16388. {
  16389. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16390. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16391. }
  16392. if(strcmp(keystr, "StopTxnSampledData") == 0)
  16393. {
  16394. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16395. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  16396. }
  16397. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  16398. {
  16399. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16400. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16401. }
  16402. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  16403. {
  16404. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16405. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  16406. }
  16407. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  16408. {
  16409. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16410. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  16411. }
  16412. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  16413. {
  16414. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16415. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  16416. TransactionMessageAttemptsValue = atoi(valuestr);
  16417. }
  16418. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  16419. {
  16420. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16421. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  16422. TransactionMessageRetryIntervalValue = atoi(valuestr);
  16423. }
  16424. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  16425. {
  16426. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16427. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  16428. }
  16429. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  16430. {
  16431. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16432. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  16433. }
  16434. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  16435. {
  16436. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16437. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  16438. }
  16439. if(strcmp(keystr, "AuthorizationKey") == 0)
  16440. {
  16441. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16442. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  16443. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  16444. }
  16445. if(strcmp(keystr, "SecurityProfile") == 0)
  16446. {
  16447. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16448. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  16449. }
  16450. if(strcmp(keystr, "DefaultPrice") == 0)
  16451. {
  16452. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16453. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  16454. }
  16455. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  16456. {
  16457. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16458. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  16459. }
  16460. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  16461. {
  16462. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16463. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  16464. }
  16465. if(strcmp(keystr, "TimeOffset") == 0)
  16466. {
  16467. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16468. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  16469. }
  16470. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  16471. {
  16472. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16473. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  16474. }
  16475. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  16476. {
  16477. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  16479. }
  16480. if(strcmp(keystr, "SystemUptimeSec") == 0)
  16481. {
  16482. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16483. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  16484. }
  16485. if(strcmp(keystr, "FreeVend") == 0)
  16486. {
  16487. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16488. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  16489. }
  16490. if(strcmp(keystr, "FreeVendIdtag") == 0)
  16491. {
  16492. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  16494. }
  16495. if(strcmp(keystr, "OcppServer") == 0)
  16496. {
  16497. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16498. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  16499. }
  16500. if(strcmp(keystr, "MaintainServer") == 0)
  16501. {
  16502. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16503. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  16504. }
  16505. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  16506. {
  16507. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16508. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  16509. }
  16510. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  16511. {
  16512. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16513. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  16514. }
  16515. if(strcmp(keystr, "PreAuthAmount") == 0)
  16516. {
  16517. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16518. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  16519. }
  16520. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  16521. {
  16522. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16523. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  16524. }
  16525. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  16526. {
  16527. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16528. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  16529. }
  16530. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  16531. {
  16532. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16533. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  16534. }
  16535. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  16536. {
  16537. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16538. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  16539. }
  16540. if(strcmp(keystr, "ConfigurationVersion") == 0)
  16541. {
  16542. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16543. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  16544. }
  16545. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  16546. {
  16547. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16548. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  16549. }
  16550. if(strcmp(keystr, "CpoName") == 0)
  16551. {
  16552. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16553. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", valuestr);
  16554. }
  16555. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  16556. {
  16557. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16558. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  16559. }
  16560. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  16561. {
  16562. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16563. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  16564. }
  16565. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  16566. {
  16567. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16568. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  16569. }
  16570. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  16571. {
  16572. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16573. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  16574. }
  16575. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  16576. {
  16577. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16578. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  16579. }
  16580. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  16581. {
  16582. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16583. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  16584. }
  16585. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16586. {
  16587. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16588. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  16589. }
  16590. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  16591. {
  16592. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16593. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  16594. }
  16595. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  16596. {
  16597. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  16599. }
  16600. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  16601. {
  16602. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16603. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  16604. }
  16605. }
  16606. }
  16607. fclose(fp);
  16608. }
  16609. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  16610. {
  16611. return PASS;
  16612. }
  16613. else
  16614. {
  16615. return FAIL;
  16616. }
  16617. }
  16618. void StoreConfigurationTable(void)
  16619. {
  16620. FILE *outfile;
  16621. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  16622. if(outfile == NULL)
  16623. {
  16624. DEBUG_INFO("Error opening file");
  16625. return ;
  16626. }
  16627. /*Core Profile*/
  16628. //AllowOfflineTxForUnknownId
  16629. /*
  16630. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  16631. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  16632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  16633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  16634. */
  16635. //DEBUG_INFO("data=%s\n",data);
  16636. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  16637. //AuthorizationCacheEnabled
  16638. /*
  16639. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  16640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  16641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  16642. */
  16643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  16644. //AuthorizeRemoteTxRequests
  16645. /*
  16646. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  16647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  16648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  16649. */
  16650. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  16651. //BlinkRepeat
  16652. /*
  16653. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  16654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  16655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  16656. */
  16657. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  16658. //ClockAlignedDataInterval
  16659. /*
  16660. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  16661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  16662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  16663. */
  16664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  16665. //ConnectionTimeOut
  16666. /*
  16667. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  16668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  16669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  16670. */
  16671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  16672. //GetConfigurationMaxKeys
  16673. /*
  16674. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  16675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  16676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  16677. */
  16678. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  16679. // HeartbeatInterval
  16680. /*
  16681. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  16682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  16683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  16684. */
  16685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  16686. // LightIntensity
  16687. /*
  16688. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  16689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  16690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  16691. */
  16692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  16693. // LocalAuthorizeOffline
  16694. /*
  16695. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  16696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  16697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  16698. */
  16699. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16700. // LocalPreAuthorize
  16701. /*
  16702. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  16703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  16704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  16705. */
  16706. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  16707. // MaxEnergyOnInvalidId
  16708. /*
  16709. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  16710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  16711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  16712. */
  16713. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  16714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  16715. // MeterValuesAlignedData
  16716. /*
  16717. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  16718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  16719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16720. */
  16721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  16722. // MeterValuesAlignedDataMaxLength
  16723. /*
  16724. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  16725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  16726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  16727. */
  16728. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  16729. // MeterValuesSampledData
  16730. /*
  16731. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  16732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  16733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16734. */
  16735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  16736. // MeterValuesSampledDataMaxLength
  16737. /*
  16738. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  16739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  16740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  16741. */
  16742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  16743. // MeterValueSampleInterval
  16744. /*
  16745. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  16746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  16747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  16748. */
  16749. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  16750. // MinimumStatusDuration
  16751. /*
  16752. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  16753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  16754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  16755. */
  16756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16757. // NumberOfConnectors
  16758. /*
  16759. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  16760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  16761. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16762. {
  16763. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  16764. }
  16765. else
  16766. {
  16767. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  16768. }
  16769. */
  16770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  16771. // ResetRetries
  16772. /*
  16773. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  16774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  16775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  16776. */
  16777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  16778. // ConnectorPhaseRotation
  16779. /*
  16780. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  16781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  16782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  16783. */
  16784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  16785. // ConnectorPhaseRotationMaxLength
  16786. /*
  16787. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  16788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  16789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  16790. */
  16791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  16792. // StopTransactionOnEVSideDisconnect
  16793. /*
  16794. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  16795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  16796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  16797. */
  16798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  16799. // StopTransactionOnInvalidId
  16800. /*
  16801. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  16802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  16803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  16804. */
  16805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  16806. // StopTxnAlignedData
  16807. /*
  16808. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  16809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  16810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  16811. */
  16812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  16813. // StopTxnAlignedDataMaxLength
  16814. /*
  16815. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  16816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  16817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  16818. */
  16819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  16820. // StopTxnSampledData
  16821. /*
  16822. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  16823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  16824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  16825. */
  16826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  16827. // StopTxnSampledDataMaxLength
  16828. /*
  16829. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  16830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  16831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  16832. */
  16833. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  16834. // SupportedFeatureProfiles
  16835. /*
  16836. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  16837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  16838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  16839. */
  16840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  16841. // SupportedFeatureProfilesMaxLength
  16842. /*
  16843. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  16844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  16845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  16846. */
  16847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  16848. // TransactionMessageAttempts
  16849. /*
  16850. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  16851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  16852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  16853. */
  16854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16855. // TransactionMessageRetryInterval
  16856. /*
  16857. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  16858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  16859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  16860. */
  16861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16862. // UnlockConnectorOnEVSideDisconnect
  16863. /*
  16864. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  16865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  16866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  16867. */
  16868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  16869. // WebSocketPingInterval
  16870. /*
  16871. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  16872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  16873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  16874. */
  16875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16876. // QueueOffLineMeterValues
  16877. /*
  16878. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  16879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  16880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  16881. */
  16882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  16883. // AuthorizationKey
  16884. /*
  16885. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  16886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  16887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  16888. */
  16889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16890. // SecurityProfile
  16891. /*
  16892. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  16893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  16894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  16895. */
  16896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16897. // DefaultPrice
  16898. /*
  16899. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  16900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  16901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  16902. */
  16903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16904. // CustomDisplayCostAndPrice
  16905. /*
  16906. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  16907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  16908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  16909. */
  16910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  16911. // CustomIdleFeeAfterStop
  16912. /*
  16913. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  16914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  16915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  16916. */
  16917. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  16918. // TimeOffset
  16919. /*
  16920. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  16921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  16922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  16923. */
  16924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  16925. // NextTimeOffsetTransitionDateTime
  16926. /*
  16927. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  16928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  16929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  16930. */
  16931. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  16932. // TimeOffsetNextTransition
  16933. /*
  16934. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  16935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  16936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  16937. */
  16938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  16939. // SystemUptimeSec
  16940. /*
  16941. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  16942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  16943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  16944. */
  16945. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  16946. // FreeVend
  16947. /*
  16948. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  16949. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  16950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  16951. */
  16952. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  16953. // FreeVendIdtag
  16954. /*
  16955. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  16956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  16957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  16958. */
  16959. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16960. // OcppServer
  16961. /*
  16962. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  16963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  16964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  16965. */
  16966. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16967. // MaintainServer
  16968. /*
  16969. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  16970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  16971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  16972. */
  16973. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16974. // StatusNotificationPeriodically
  16975. /*
  16976. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  16977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  16978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  16979. */
  16980. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  16981. // StatusNotificationInterval
  16982. /*
  16983. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  16984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  16985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  16986. */
  16987. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  16988. // PreAuthAmount
  16989. /*
  16990. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  16991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  16992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  16993. */
  16994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  16995. // isEnableLocalPowerSharing
  16996. /*
  16997. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  16998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  16999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  17000. */
  17001. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  17002. // PowerSharingServerIP
  17003. /*
  17004. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  17005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  17006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  17007. */
  17008. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  17009. // EVCCID_PREFIX
  17010. /*
  17011. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  17012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  17013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  17014. */
  17015. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  17016. // OffLineMaxChargingPower
  17017. /*
  17018. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  17019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  17020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  17021. */
  17022. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  17023. // ConfigurationVersion
  17024. /*
  17025. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  17026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  17027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  17028. */
  17029. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  17030. // CharingProfileRefreshInterval
  17031. /*
  17032. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  17033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  17034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  17035. */
  17036. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  17037. // CpoName
  17038. /*
  17039. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  17040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  17041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "" );
  17042. */
  17043. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  17044. // OcppSoftwareVersion
  17045. /*
  17046. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  17047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  17048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  17049. */
  17050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  17051. //* Local Auth List Management Profile*/
  17052. //LocalAuthListEnabled
  17053. /*
  17054. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  17055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  17056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  17057. */
  17058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17059. //LocalAuthListMaxLength
  17060. /*
  17061. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  17062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  17063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  17064. */
  17065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  17066. //SendLocalListMaxLength
  17067. /*
  17068. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  17069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  17070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  17071. */
  17072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  17073. //ReserveConnectorZeroSupported
  17074. /*
  17075. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  17076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  17077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  17078. */
  17079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  17080. //* Smart Charging Profile */
  17081. //ChargeProfileMaxStackLevel
  17082. /*
  17083. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  17084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  17085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  17086. */
  17087. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  17088. // ChargingScheduleAllowedChargingRateUnit
  17089. /*
  17090. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  17091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  17092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  17093. */
  17094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  17095. // ChargingScheduleMaxPeriods
  17096. /*
  17097. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  17098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  17099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  17100. */
  17101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  17102. // ConnectorSwitch3to1PhaseSupported
  17103. /*
  17104. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  17105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  17106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  17107. */
  17108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  17109. // MaxChargingProfilesInstalled
  17110. /*
  17111. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  17112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  17113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  17114. */
  17115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  17116. fclose(outfile);
  17117. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17118. }
  17119. void getKeyValue(char *keyReq)
  17120. {
  17121. int isEmpty = FALSE;
  17122. int isKnowKey = FALSE;
  17123. DEBUG_INFO("keyReq = %s\n", keyReq);
  17124. if((keyReq == NULL) || (strlen(keyReq) == 0))
  17125. isEmpty = TRUE;
  17126. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  17127. {
  17128. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  17129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  17130. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  17131. {
  17132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  17133. }
  17134. else
  17135. {
  17136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  17137. }
  17138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  17139. isKnowKey = TRUE;
  17140. }
  17141. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  17142. {
  17143. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  17144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  17145. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  17146. {
  17147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  17148. }
  17149. else
  17150. {
  17151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  17152. }
  17153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  17154. isKnowKey = TRUE;
  17155. }
  17156. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  17157. {
  17158. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  17159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  17160. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  17161. {
  17162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  17163. }
  17164. else
  17165. {
  17166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  17167. }
  17168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  17169. isKnowKey = TRUE;
  17170. }
  17171. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  17172. {
  17173. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  17174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  17175. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  17176. {
  17177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  17178. }
  17179. else
  17180. {
  17181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  17182. }
  17183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  17184. isKnowKey = TRUE;
  17185. }
  17186. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  17187. {
  17188. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  17189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  17190. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  17191. {
  17192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  17193. }
  17194. else
  17195. {
  17196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  17197. }
  17198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  17199. isKnowKey = TRUE;
  17200. }
  17201. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  17202. {
  17203. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  17204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  17205. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  17206. {
  17207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  17208. }
  17209. else
  17210. {
  17211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  17212. }
  17213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  17214. isKnowKey = TRUE;
  17215. }
  17216. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  17217. {
  17218. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  17219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  17220. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  17221. {
  17222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  17223. }
  17224. else
  17225. {
  17226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  17227. }
  17228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  17229. isKnowKey = TRUE;
  17230. }
  17231. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  17232. {
  17233. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  17234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  17235. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  17236. {
  17237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  17238. }
  17239. else
  17240. {
  17241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  17242. }
  17243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  17244. isKnowKey = TRUE;
  17245. }
  17246. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  17247. {
  17248. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  17249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  17250. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  17251. {
  17252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  17253. }
  17254. else
  17255. {
  17256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  17257. }
  17258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  17259. isKnowKey = TRUE;
  17260. }
  17261. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  17262. {
  17263. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  17264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  17265. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  17266. {
  17267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  17268. }
  17269. else
  17270. {
  17271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  17272. }
  17273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  17274. isKnowKey = TRUE;
  17275. }
  17276. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  17277. {
  17278. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  17279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  17280. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  17281. {
  17282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  17283. }
  17284. else
  17285. {
  17286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  17287. }
  17288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  17289. isKnowKey = TRUE;
  17290. }
  17291. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  17292. {
  17293. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  17294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  17295. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  17296. {
  17297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17298. }
  17299. else
  17300. {
  17301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17302. }
  17303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  17304. isKnowKey = TRUE;
  17305. }
  17306. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  17307. {
  17308. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  17309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  17310. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  17311. {
  17312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17313. }
  17314. else
  17315. {
  17316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17317. }
  17318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  17319. isKnowKey = TRUE;
  17320. }
  17321. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  17322. {
  17323. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  17324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  17325. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  17326. {
  17327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17328. }
  17329. else
  17330. {
  17331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17332. }
  17333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  17334. isKnowKey = TRUE;
  17335. }
  17336. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  17337. {
  17338. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  17339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  17340. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  17341. {
  17342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  17343. }
  17344. else
  17345. {
  17346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  17347. }
  17348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  17349. isKnowKey = TRUE;
  17350. }
  17351. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  17352. {
  17353. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  17354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  17355. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  17356. {
  17357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17358. }
  17359. else
  17360. {
  17361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17362. }
  17363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  17364. isKnowKey = TRUE;
  17365. }
  17366. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  17367. {
  17368. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  17369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  17370. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  17371. {
  17372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  17373. }
  17374. else
  17375. {
  17376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  17377. }
  17378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  17379. isKnowKey = TRUE;
  17380. }
  17381. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  17382. {
  17383. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  17384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  17385. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  17386. {
  17387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  17388. }
  17389. else
  17390. {
  17391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  17392. }
  17393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  17394. isKnowKey = TRUE;
  17395. }
  17396. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  17397. {
  17398. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  17399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  17400. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  17401. {
  17402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  17403. }
  17404. else
  17405. {
  17406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  17407. }
  17408. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  17409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  17410. isKnowKey = TRUE;
  17411. }
  17412. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  17413. {
  17414. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  17415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  17416. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  17417. {
  17418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  17419. }
  17420. else
  17421. {
  17422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  17423. }
  17424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  17425. isKnowKey = TRUE;
  17426. }
  17427. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  17428. {
  17429. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  17430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  17431. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17432. {
  17433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  17434. }
  17435. else
  17436. {
  17437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  17438. }
  17439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  17440. isKnowKey = TRUE;
  17441. }
  17442. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  17443. {
  17444. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  17445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  17446. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  17447. {
  17448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17449. }
  17450. else
  17451. {
  17452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17453. }
  17454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  17455. isKnowKey = TRUE;
  17456. }
  17457. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  17458. {
  17459. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  17460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  17461. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17462. {
  17463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17464. }
  17465. else
  17466. {
  17467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17468. }
  17469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  17470. isKnowKey = TRUE;
  17471. }
  17472. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  17473. {
  17474. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  17475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  17476. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17477. {
  17478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17479. }
  17480. else
  17481. {
  17482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17483. }
  17484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  17485. isKnowKey = TRUE;
  17486. }
  17487. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  17488. {
  17489. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  17490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  17491. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17492. {
  17493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17494. }
  17495. else
  17496. {
  17497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17498. }
  17499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  17500. isKnowKey = TRUE;
  17501. }
  17502. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  17503. {
  17504. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  17505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  17506. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17507. {
  17508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17509. }
  17510. else
  17511. {
  17512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17513. }
  17514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  17515. isKnowKey = TRUE;
  17516. }
  17517. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  17518. {
  17519. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  17520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  17521. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17522. {
  17523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  17524. }
  17525. else
  17526. {
  17527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  17528. }
  17529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  17530. isKnowKey = TRUE;
  17531. }
  17532. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  17533. {
  17534. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  17535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  17536. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17537. {
  17538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17539. }
  17540. else
  17541. {
  17542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17543. }
  17544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  17545. isKnowKey = TRUE;
  17546. }
  17547. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  17548. {
  17549. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  17550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  17551. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17552. {
  17553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  17554. }
  17555. else
  17556. {
  17557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  17558. }
  17559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  17560. isKnowKey = TRUE;
  17561. }
  17562. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  17563. {
  17564. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  17565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  17566. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17567. {
  17568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17569. }
  17570. else
  17571. {
  17572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17573. }
  17574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  17575. isKnowKey = TRUE;
  17576. }
  17577. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  17578. {
  17579. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  17580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  17581. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17582. {
  17583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  17584. }
  17585. else
  17586. {
  17587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  17588. }
  17589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  17590. isKnowKey = TRUE;
  17591. }
  17592. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  17593. {
  17594. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  17595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  17596. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17597. {
  17598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  17599. }
  17600. else
  17601. {
  17602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  17603. }
  17604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  17605. isKnowKey = TRUE;
  17606. }
  17607. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  17608. {
  17609. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  17610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  17611. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17612. {
  17613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17614. }
  17615. else
  17616. {
  17617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17618. }
  17619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  17620. isKnowKey = TRUE;
  17621. }
  17622. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  17623. {
  17624. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  17625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  17626. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17627. {
  17628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  17629. }
  17630. else
  17631. {
  17632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  17633. }
  17634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  17635. isKnowKey = TRUE;
  17636. }
  17637. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  17638. {
  17639. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  17640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  17641. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17642. {
  17643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  17644. }
  17645. else
  17646. {
  17647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  17648. }
  17649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  17650. isKnowKey = TRUE;
  17651. }
  17652. /*
  17653. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  17654. {
  17655. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  17656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  17657. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  17658. {
  17659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  17660. }
  17661. else
  17662. {
  17663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  17664. }
  17665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  17666. isKnowKey = TRUE;
  17667. }*/
  17668. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  17669. {
  17670. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  17671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  17672. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17673. {
  17674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  17675. }
  17676. else
  17677. {
  17678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  17679. }
  17680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  17681. isKnowKey = TRUE;
  17682. }
  17683. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  17684. {
  17685. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  17686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  17687. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  17688. {
  17689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  17690. }
  17691. else
  17692. {
  17693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  17694. }
  17695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  17696. isKnowKey = TRUE;
  17697. }
  17698. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  17699. {
  17700. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  17701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  17702. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17703. {
  17704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  17705. }
  17706. else
  17707. {
  17708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  17709. }
  17710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  17711. isKnowKey = TRUE;
  17712. }
  17713. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  17714. {
  17715. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  17716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  17717. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17718. {
  17719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  17720. }
  17721. else
  17722. {
  17723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  17724. }
  17725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  17726. isKnowKey = TRUE;
  17727. }
  17728. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  17729. {
  17730. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  17731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  17732. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17733. {
  17734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  17735. }
  17736. else
  17737. {
  17738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  17739. }
  17740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  17741. isKnowKey = TRUE;
  17742. }
  17743. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  17744. {
  17745. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  17746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  17747. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17748. {
  17749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  17750. }
  17751. else
  17752. {
  17753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  17754. }
  17755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  17756. isKnowKey = TRUE;
  17757. }
  17758. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  17759. {
  17760. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  17761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  17762. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17763. {
  17764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  17765. }
  17766. else
  17767. {
  17768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  17769. }
  17770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  17771. isKnowKey = TRUE;
  17772. }
  17773. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  17774. {
  17775. struct sysinfo s_info;
  17776. int error = sysinfo(&s_info);
  17777. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  17778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  17779. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  17780. {
  17781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  17782. }
  17783. else
  17784. {
  17785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  17786. }
  17787. if(error != 0)
  17788. {
  17789. DEBUG_WARN("System uptime get error: %d\n", error);
  17790. }
  17791. else
  17792. {
  17793. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  17794. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  17795. }
  17796. isKnowKey = TRUE;
  17797. }
  17798. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  17799. {
  17800. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  17801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  17802. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17803. {
  17804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  17805. }
  17806. else
  17807. {
  17808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  17809. }
  17810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  17811. isKnowKey = TRUE;
  17812. }
  17813. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  17814. {
  17815. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  17816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  17817. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17818. {
  17819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  17820. }
  17821. else
  17822. {
  17823. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  17824. }
  17825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  17826. isKnowKey = TRUE;
  17827. }
  17828. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  17829. {
  17830. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  17831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  17832. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17833. {
  17834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  17835. }
  17836. else
  17837. {
  17838. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  17839. }
  17840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  17841. isKnowKey = TRUE;
  17842. }
  17843. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  17844. {
  17845. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  17846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  17847. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17848. {
  17849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  17850. }
  17851. else
  17852. {
  17853. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  17854. }
  17855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  17856. isKnowKey = TRUE;
  17857. }
  17858. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  17859. {
  17860. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  17861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  17862. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17863. {
  17864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  17865. }
  17866. else
  17867. {
  17868. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  17869. }
  17870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  17871. isKnowKey = TRUE;
  17872. }
  17873. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  17874. {
  17875. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  17876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  17877. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17878. {
  17879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  17880. }
  17881. else
  17882. {
  17883. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  17884. }
  17885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  17886. isKnowKey = TRUE;
  17887. }
  17888. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  17889. {
  17890. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  17891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  17892. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17893. {
  17894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  17895. }
  17896. else
  17897. {
  17898. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  17899. }
  17900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  17901. isKnowKey = TRUE;
  17902. }
  17903. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  17904. {
  17905. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  17906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  17907. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17908. {
  17909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  17910. }
  17911. else
  17912. {
  17913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  17914. }
  17915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  17916. isKnowKey = TRUE;
  17917. }
  17918. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  17919. {
  17920. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  17921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  17922. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17923. {
  17924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  17925. }
  17926. else
  17927. {
  17928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  17929. }
  17930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  17931. isKnowKey = TRUE;
  17932. }
  17933. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  17934. {
  17935. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  17936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  17937. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17938. {
  17939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  17940. }
  17941. else
  17942. {
  17943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  17944. }
  17945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  17946. isKnowKey = TRUE;
  17947. }
  17948. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  17949. {
  17950. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  17951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  17952. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17953. {
  17954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  17955. }
  17956. else
  17957. {
  17958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  17959. }
  17960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  17961. isKnowKey = TRUE;
  17962. }
  17963. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  17964. {
  17965. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  17966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  17967. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  17968. {
  17969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  17970. }
  17971. else
  17972. {
  17973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  17974. }
  17975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  17976. isKnowKey = TRUE;
  17977. }
  17978. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  17979. {
  17980. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  17981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  17982. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  17983. {
  17984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  17985. }
  17986. else
  17987. {
  17988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  17989. }
  17990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  17991. isKnowKey = TRUE;
  17992. }
  17993. if(isEmpty || strcmp(keyReq, "CpoName") == 0 )
  17994. {
  17995. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CpoName].Item, "CpoName");
  17996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Key, "CpoName");
  17997. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  17998. {
  17999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "0"/*"FALSE"*/);
  18000. }
  18001. else
  18002. {
  18003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "1"/*"TRUE"*/);
  18004. }
  18005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData );
  18006. isKnowKey = TRUE;
  18007. }
  18008. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  18009. {
  18010. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  18011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  18012. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  18013. {
  18014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  18015. }
  18016. else
  18017. {
  18018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  18019. }
  18020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  18021. isKnowKey = TRUE;
  18022. }
  18023. #if 1
  18024. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  18025. {
  18026. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  18027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  18028. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  18029. {
  18030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  18031. }
  18032. else
  18033. {
  18034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  18035. }
  18036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  18037. isKnowKey = TRUE;
  18038. }
  18039. #endif
  18040. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  18041. {
  18042. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  18043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  18044. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  18045. {
  18046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  18047. }
  18048. else
  18049. {
  18050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  18051. }
  18052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  18053. isKnowKey = TRUE;
  18054. }
  18055. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  18056. {
  18057. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  18058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  18059. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  18060. {
  18061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  18062. }
  18063. else
  18064. {
  18065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  18066. }
  18067. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  18068. isKnowKey = TRUE;
  18069. }
  18070. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  18071. {
  18072. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  18073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  18074. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  18075. {
  18076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  18077. }
  18078. else
  18079. {
  18080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  18081. }
  18082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  18083. isKnowKey = TRUE;
  18084. }
  18085. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  18086. {
  18087. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  18088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  18089. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  18090. {
  18091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  18092. }
  18093. else
  18094. {
  18095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  18096. }
  18097. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  18098. isKnowKey = TRUE;
  18099. }
  18100. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  18101. {
  18102. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  18103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  18104. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  18105. {
  18106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  18107. }
  18108. else
  18109. {
  18110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  18111. }
  18112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  18113. isKnowKey = TRUE;
  18114. }
  18115. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  18116. {
  18117. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  18118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  18119. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  18120. {
  18121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  18122. }
  18123. else
  18124. {
  18125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  18126. }
  18127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  18128. isKnowKey = TRUE;
  18129. }
  18130. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  18131. {
  18132. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  18133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  18134. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  18135. {
  18136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  18137. }
  18138. else
  18139. {
  18140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  18141. }
  18142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  18143. isKnowKey = TRUE;
  18144. }
  18145. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  18146. {
  18147. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  18148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  18149. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  18150. {
  18151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  18152. }
  18153. else
  18154. {
  18155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  18156. }
  18157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  18158. isKnowKey = TRUE;
  18159. }
  18160. //=========================================================
  18161. if(!isEmpty && !isKnowKey)
  18162. {
  18163. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  18164. strcpy(unknownkey[UnknownKeynum], keyReq);
  18165. UnknownKeynum = UnknownKeynum + 1;
  18166. }
  18167. }
  18168. void processUnkownKey(void)
  18169. {
  18170. DEBUG_INFO("processUnkownKey...\n");
  18171. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  18172. for(int index=0; index < UnknownKeynum; index++)
  18173. {
  18174. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  18175. {
  18176. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  18177. }
  18178. }
  18179. }
  18180. int setKeyValue(char *key, char *value)
  18181. {
  18182. int isSuccess = NotSupported;
  18183. int check_ascii=0;
  18184. char str[501]={0};
  18185. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  18186. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  18187. {
  18188. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  18189. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  18190. {
  18191. strcpy(str, (const char*)value);
  18192. for(int i = 0; str[i]; i++){
  18193. str[i] = tolower(str[i]);
  18194. }
  18195. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18196. isSuccess = ConfigurationStatus_Accepted;
  18197. }
  18198. else
  18199. {
  18200. isSuccess = ConfigurationStatus_Rejected;
  18201. }
  18202. }
  18203. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  18204. {
  18205. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  18206. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  18207. {
  18208. strcpy(str, (const char*)value);
  18209. for(int i = 0; str[i]; i++){
  18210. str[i] = tolower(str[i]);
  18211. }
  18212. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18213. isSuccess = ConfigurationStatus_Accepted;
  18214. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  18215. }
  18216. else
  18217. {
  18218. isSuccess = ConfigurationStatus_Rejected;
  18219. }
  18220. }
  18221. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  18222. {
  18223. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  18224. {
  18225. strcpy(str, (const char*)value);
  18226. for(int i = 0; str[i]; i++)
  18227. {
  18228. str[i] = tolower(str[i]);
  18229. }
  18230. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  18231. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18232. isSuccess = ConfigurationStatus_Accepted;
  18233. }
  18234. else
  18235. {
  18236. isSuccess = ConfigurationStatus_Rejected;
  18237. }
  18238. }
  18239. if(strcmp(key, "BlinkRepeat") == 0)
  18240. {
  18241. //Charger.BlinkRepeat = Integer.parseInt(value);
  18242. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  18243. {
  18244. check_ascii = value[0];
  18245. if( (check_ascii < 48) || (check_ascii > 57) )
  18246. {
  18247. isSuccess = ConfigurationStatus_Rejected;
  18248. }
  18249. else
  18250. {
  18251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  18252. isSuccess = ConfigurationStatus_Accepted;
  18253. }
  18254. }
  18255. else
  18256. {
  18257. isSuccess = ConfigurationStatus_Rejected;
  18258. }
  18259. }
  18260. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  18261. {
  18262. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  18263. {
  18264. check_ascii = value[0];
  18265. if( (check_ascii < 48) || (check_ascii > 57) )
  18266. {
  18267. isSuccess = ConfigurationStatus_Rejected;
  18268. }
  18269. else
  18270. {
  18271. if((atoi(value) == 0) || (atoi(value) >= 5))
  18272. {
  18273. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  18274. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  18275. isSuccess = ConfigurationStatus_Accepted;
  18276. }
  18277. else
  18278. isSuccess = ConfigurationStatus_Rejected;
  18279. }
  18280. }
  18281. else
  18282. {
  18283. isSuccess = ConfigurationStatus_Rejected;
  18284. }
  18285. }
  18286. if(strcmp(key, "ConnectionTimeOut") == 0 )
  18287. {
  18288. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  18289. {
  18290. check_ascii = value[0];
  18291. if( (check_ascii < 48) || (check_ascii > 57) )
  18292. {
  18293. isSuccess = ConfigurationStatus_Rejected;
  18294. }
  18295. else
  18296. {
  18297. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  18298. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  18299. isSuccess = ConfigurationStatus_Accepted;
  18300. }
  18301. }
  18302. else
  18303. {
  18304. isSuccess = ConfigurationStatus_Rejected;
  18305. }
  18306. }
  18307. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  18308. {
  18309. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  18310. {
  18311. check_ascii = value[0];
  18312. if( (check_ascii < 48) || (check_ascii > 57) )
  18313. {
  18314. isSuccess = ConfigurationStatus_Rejected;
  18315. }
  18316. else
  18317. {
  18318. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18319. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  18320. isSuccess = ConfigurationStatus_Accepted;
  18321. }
  18322. }
  18323. else
  18324. {
  18325. isSuccess = ConfigurationStatus_Rejected;
  18326. }
  18327. }
  18328. if(strcmp(key, "HeartbeatInterval") == 0)
  18329. {
  18330. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  18331. {
  18332. check_ascii = value[0];
  18333. if( (check_ascii < 48) || (check_ascii > 57) )
  18334. {
  18335. isSuccess = ConfigurationStatus_Rejected;
  18336. }
  18337. else
  18338. {
  18339. if((atoi(value) == 0) || (atoi(value) >= 10))
  18340. {
  18341. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  18343. HeartBeatWaitTime = atoi(value);
  18344. isSuccess = ConfigurationStatus_Accepted;
  18345. }
  18346. else
  18347. {
  18348. isSuccess = ConfigurationStatus_Rejected;
  18349. }
  18350. }
  18351. }
  18352. else
  18353. {
  18354. isSuccess = ConfigurationStatus_Rejected;
  18355. }
  18356. }
  18357. if(strcmp(key, "LightIntensity") == 0)
  18358. {
  18359. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  18360. {
  18361. check_ascii = value[0];
  18362. if( (check_ascii < 48) || (check_ascii > 57) )
  18363. {
  18364. isSuccess = ConfigurationStatus_Rejected;
  18365. }
  18366. else
  18367. {
  18368. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  18369. isSuccess = ConfigurationStatus_Accepted;
  18370. }
  18371. }
  18372. else
  18373. {
  18374. isSuccess = ConfigurationStatus_Rejected;
  18375. }
  18376. }
  18377. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  18378. {
  18379. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  18380. {
  18381. strcpy(str, (const char*)value);
  18382. for(int i = 0; str[i]; i++)
  18383. {
  18384. str[i] = tolower(str[i]);
  18385. }
  18386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18387. isSuccess = ConfigurationStatus_Accepted;
  18388. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  18389. }
  18390. else
  18391. {
  18392. isSuccess = ConfigurationStatus_Rejected;
  18393. }
  18394. }
  18395. if(strcmp(key, "LocalPreAuthorize") == 0)
  18396. {
  18397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  18398. {
  18399. strcpy(str, (const char*)value);
  18400. for(int i = 0; str[i]; i++)
  18401. {
  18402. str[i] = tolower(str[i]);
  18403. }
  18404. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18405. isSuccess = ConfigurationStatus_Accepted;
  18406. }
  18407. else
  18408. {
  18409. isSuccess = ConfigurationStatus_Rejected;
  18410. }
  18411. }
  18412. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  18413. {
  18414. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  18415. {
  18416. check_ascii = value[0];
  18417. if( (check_ascii < 48) || (check_ascii > 57) )
  18418. {
  18419. isSuccess = ConfigurationStatus_Rejected;
  18420. }
  18421. else
  18422. {
  18423. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  18424. isSuccess = ConfigurationStatus_Accepted;
  18425. }
  18426. }
  18427. else
  18428. {
  18429. isSuccess = ConfigurationStatus_Rejected;
  18430. }
  18431. }
  18432. if(strcmp(key, "MeterValuesAlignedData") == 0)
  18433. {
  18434. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  18435. {
  18436. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  18437. isSuccess = ConfigurationStatus_Accepted;
  18438. }
  18439. else
  18440. {
  18441. isSuccess = ConfigurationStatus_Rejected;
  18442. }
  18443. }
  18444. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  18445. {
  18446. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  18447. {
  18448. check_ascii = value[0];
  18449. if( (check_ascii < 48) || (check_ascii > 57) )
  18450. {
  18451. isSuccess = ConfigurationStatus_Rejected;
  18452. }
  18453. else
  18454. {
  18455. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18456. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  18457. isSuccess = ConfigurationStatus_Accepted;
  18458. }
  18459. }
  18460. else
  18461. {
  18462. isSuccess = ConfigurationStatus_Rejected;
  18463. }
  18464. }
  18465. if(strcmp(key, "MeterValuesSampledData") == 0 )
  18466. {
  18467. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  18468. {
  18469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  18470. isSuccess = ConfigurationStatus_Accepted;
  18471. }
  18472. else
  18473. {
  18474. isSuccess = ConfigurationStatus_Rejected;
  18475. }
  18476. }
  18477. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  18478. {
  18479. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  18480. {
  18481. check_ascii = value[0];
  18482. if( (check_ascii < 48) || (check_ascii > 57) )
  18483. {
  18484. isSuccess = ConfigurationStatus_Rejected;
  18485. }
  18486. else
  18487. {
  18488. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  18490. isSuccess = ConfigurationStatus_Accepted;
  18491. }
  18492. }
  18493. else
  18494. {
  18495. isSuccess = ConfigurationStatus_Rejected;
  18496. }
  18497. }
  18498. if(strcmp(key, "MeterValueSampleInterval") == 0)
  18499. {
  18500. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  18501. {
  18502. check_ascii = value[0];
  18503. if( (check_ascii < 48) || (check_ascii > 57) )
  18504. {
  18505. isSuccess = ConfigurationStatus_Rejected;
  18506. }
  18507. else
  18508. {
  18509. if((atoi(value) == 0) || (atoi(value) >= 3))
  18510. {
  18511. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18512. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  18513. isSuccess = ConfigurationStatus_Accepted;
  18514. }
  18515. else
  18516. {
  18517. isSuccess = ConfigurationStatus_Rejected;
  18518. }
  18519. }
  18520. }
  18521. else
  18522. {
  18523. isSuccess = ConfigurationStatus_Rejected;
  18524. }
  18525. }
  18526. if(strcmp(key, "MinimumStatusDuration") == 0)
  18527. {
  18528. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  18529. {
  18530. check_ascii = value[0];
  18531. if( (check_ascii < 48) || (check_ascii > 57) )
  18532. {
  18533. isSuccess = ConfigurationStatus_Rejected;
  18534. }
  18535. else
  18536. {
  18537. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  18538. {
  18539. isSuccess = ConfigurationStatus_Rejected;
  18540. }
  18541. else
  18542. {
  18543. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  18544. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  18545. server_cycle_Status = atoi(value); //StatusNotification Cycle
  18546. isSuccess = ConfigurationStatus_Accepted;
  18547. }
  18548. }
  18549. }
  18550. else
  18551. {
  18552. isSuccess = ConfigurationStatus_Rejected;
  18553. }
  18554. }
  18555. if(strcmp(key, "NumberOfConnectors") == 0)
  18556. {
  18557. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  18558. {
  18559. check_ascii = value[0];
  18560. if( (check_ascii < 48) || (check_ascii > 57) )
  18561. {
  18562. isSuccess = ConfigurationStatus_Rejected;
  18563. }
  18564. else
  18565. {
  18566. //Charger.ResetRetries = Integer.parseInt(value);
  18567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  18568. isSuccess = ConfigurationStatus_Accepted;
  18569. }
  18570. }
  18571. else
  18572. {
  18573. isSuccess = ConfigurationStatus_Rejected;
  18574. }
  18575. }
  18576. if(strcmp(key, "ResetRetries") == 0)
  18577. {
  18578. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  18579. {
  18580. check_ascii = value[0];
  18581. if( (check_ascii < 48) || (check_ascii > 57) )
  18582. {
  18583. isSuccess = ConfigurationStatus_Rejected;
  18584. }
  18585. else
  18586. {
  18587. //Charger.ResetRetries = Integer.parseInt(value);
  18588. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  18589. isSuccess = ConfigurationStatus_Accepted;
  18590. }
  18591. }
  18592. else
  18593. {
  18594. isSuccess = ConfigurationStatus_Rejected;
  18595. }
  18596. }
  18597. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  18598. {
  18599. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  18600. {
  18601. strcpy(str, (const char*)value);
  18602. for(int i = 0; str[i]; i++)
  18603. {
  18604. str[i] = tolower(str[i]);
  18605. }
  18606. if(strcmp(str, "notapplicable")== 0)
  18607. {
  18608. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  18609. isSuccess = ConfigurationStatus_Accepted;
  18610. }
  18611. else if(strcmp(str, "unknown")== 0)
  18612. {
  18613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  18614. isSuccess = ConfigurationStatus_Accepted;
  18615. }
  18616. else if(strcmp(str, "rst")== 0)
  18617. {
  18618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  18619. isSuccess = ConfigurationStatus_Accepted;
  18620. }
  18621. else if(strcmp(str, "rts")== 0)
  18622. {
  18623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  18624. isSuccess = ConfigurationStatus_Accepted;
  18625. }
  18626. else if(strcmp(str, "srt")== 0)
  18627. {
  18628. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  18629. isSuccess = ConfigurationStatus_Accepted;
  18630. }
  18631. else if(strcmp(str, "str")== 0)
  18632. {
  18633. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  18634. isSuccess = ConfigurationStatus_Accepted;
  18635. }
  18636. else if(strcmp(str, "trs")== 0)
  18637. {
  18638. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  18639. isSuccess = ConfigurationStatus_Accepted;
  18640. }
  18641. else if(strcmp(str, "tsr")== 0)
  18642. {
  18643. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  18644. isSuccess = ConfigurationStatus_Accepted;
  18645. }
  18646. else
  18647. {
  18648. isSuccess = ConfigurationStatus_Rejected;
  18649. }
  18650. }
  18651. else
  18652. {
  18653. isSuccess = ConfigurationStatus_Rejected;
  18654. }
  18655. }
  18656. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  18657. {
  18658. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  18659. {
  18660. check_ascii = value[0];
  18661. if( (check_ascii < 48) || (check_ascii > 57) )
  18662. {
  18663. isSuccess = ConfigurationStatus_Rejected;
  18664. }
  18665. else
  18666. {
  18667. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  18668. isSuccess = ConfigurationStatus_Accepted;
  18669. }
  18670. }
  18671. else
  18672. {
  18673. isSuccess = ConfigurationStatus_Rejected;
  18674. }
  18675. }
  18676. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  18677. {
  18678. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  18679. {
  18680. strcpy(str, (const char*)value);
  18681. for(int i = 0; str[i]; i++)
  18682. {
  18683. str[i] = tolower(str[i]);
  18684. }
  18685. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18687. isSuccess = ConfigurationStatus_Accepted;
  18688. }
  18689. else
  18690. {
  18691. isSuccess = ConfigurationStatus_Rejected;
  18692. }
  18693. }
  18694. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  18695. {
  18696. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  18697. {
  18698. strcpy(str, (const char*)value);
  18699. for(int i = 0; str[i]; i++)
  18700. {
  18701. str[i] = tolower(str[i]);
  18702. }
  18703. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  18704. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18705. isSuccess = ConfigurationStatus_Accepted;
  18706. }
  18707. else
  18708. {
  18709. isSuccess = ConfigurationStatus_Rejected;
  18710. }
  18711. }
  18712. if(strcmp(key, "StopTxnAlignedData") == 0)
  18713. {
  18714. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  18715. {
  18716. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  18717. isSuccess = ConfigurationStatus_Accepted;
  18718. }
  18719. else
  18720. {
  18721. isSuccess = ConfigurationStatus_Rejected;
  18722. }
  18723. }
  18724. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  18725. {
  18726. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  18727. {
  18728. check_ascii = value[0];
  18729. if( (check_ascii < 48) || (check_ascii > 57) )
  18730. {
  18731. isSuccess = ConfigurationStatus_Rejected;
  18732. }
  18733. else
  18734. {
  18735. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  18736. isSuccess = ConfigurationStatus_Accepted;
  18737. }
  18738. }
  18739. else
  18740. {
  18741. isSuccess = ConfigurationStatus_Rejected;
  18742. }
  18743. }
  18744. if(strcmp(key, "StopTxnSampledData") == 0)
  18745. {
  18746. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  18747. {
  18748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  18749. isSuccess = ConfigurationStatus_Accepted;
  18750. }
  18751. else
  18752. {
  18753. isSuccess = ConfigurationStatus_Rejected;
  18754. }
  18755. }
  18756. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  18757. {
  18758. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  18759. {
  18760. check_ascii = value[0];
  18761. if( (check_ascii < 48) || (check_ascii > 57) )
  18762. {
  18763. isSuccess = ConfigurationStatus_Rejected;
  18764. }
  18765. else
  18766. {
  18767. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  18768. isSuccess = ConfigurationStatus_Accepted;
  18769. }
  18770. }
  18771. else
  18772. {
  18773. isSuccess = ConfigurationStatus_Rejected;
  18774. }
  18775. }
  18776. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  18777. {
  18778. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  18779. {
  18780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  18781. isSuccess = ConfigurationStatus_Accepted;
  18782. }
  18783. else
  18784. {
  18785. isSuccess = ConfigurationStatus_Rejected;
  18786. }
  18787. }
  18788. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  18789. {
  18790. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  18791. {
  18792. check_ascii = value[0];
  18793. if( (check_ascii < 48) || (check_ascii > 57) )
  18794. {
  18795. isSuccess = ConfigurationStatus_Rejected;
  18796. }
  18797. else
  18798. {
  18799. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  18800. isSuccess = ConfigurationStatus_Accepted;
  18801. }
  18802. }
  18803. else
  18804. {
  18805. isSuccess = ConfigurationStatus_Rejected;
  18806. }
  18807. }
  18808. if(strcmp(key, "TransactionMessageAttempts") == 0)
  18809. {
  18810. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  18811. {
  18812. check_ascii = value[0];
  18813. if( (check_ascii < 48) || (check_ascii > 57) )
  18814. {
  18815. isSuccess = ConfigurationStatus_Rejected;
  18816. }
  18817. else
  18818. {
  18819. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  18820. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  18821. TransactionMessageAttemptsValue = atoi(value);
  18822. isSuccess = ConfigurationStatus_Accepted;
  18823. }
  18824. }
  18825. else
  18826. {
  18827. isSuccess = ConfigurationStatus_Rejected;
  18828. }
  18829. }
  18830. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  18831. {
  18832. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  18833. {
  18834. check_ascii = value[0];
  18835. if( (check_ascii < 48) || (check_ascii > 57) )
  18836. {
  18837. isSuccess = ConfigurationStatus_Rejected;
  18838. }
  18839. else
  18840. {
  18841. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  18842. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  18843. TransactionMessageRetryIntervalValue = atoi(value);
  18844. isSuccess = ConfigurationStatus_Accepted;
  18845. }
  18846. }
  18847. else
  18848. {
  18849. isSuccess = ConfigurationStatus_Rejected;
  18850. }
  18851. }
  18852. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  18853. {
  18854. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  18855. {
  18856. strcpy(str, (const char*)value);
  18857. for(int i = 0; str[i]; i++)
  18858. {
  18859. str[i] = tolower(str[i]);
  18860. }
  18861. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18862. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18863. isSuccess = ConfigurationStatus_Accepted;
  18864. }
  18865. else
  18866. {
  18867. isSuccess = ConfigurationStatus_Rejected;
  18868. }
  18869. }
  18870. if(strcmp(key, "WebSocketPingInterval") == 0)
  18871. {
  18872. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  18873. {
  18874. check_ascii = value[0];
  18875. if( (check_ascii < 48) || (check_ascii > 57) )
  18876. {
  18877. isSuccess = ConfigurationStatus_Rejected;
  18878. }
  18879. else
  18880. {
  18881. if((atoi(value) == 0) || (atoi(value) >= 10))
  18882. {
  18883. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  18884. isSuccess = ConfigurationStatus_Accepted;
  18885. }
  18886. else
  18887. isSuccess = ConfigurationStatus_Rejected;
  18888. }
  18889. }
  18890. else
  18891. {
  18892. isSuccess = ConfigurationStatus_Rejected;
  18893. }
  18894. }
  18895. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  18896. {
  18897. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  18898. {
  18899. strcpy(str, (const char*)value);
  18900. for(int i = 0; str[i]; i++)
  18901. {
  18902. str[i] = tolower(str[i]);
  18903. }
  18904. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18905. isSuccess = ConfigurationStatus_Accepted;
  18906. }
  18907. else
  18908. {
  18909. isSuccess = ConfigurationStatus_Rejected;
  18910. }
  18911. }
  18912. if(strcmp(key, "AuthorizationKey") == 0)
  18913. {
  18914. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  18915. {
  18916. strcpy(str, (const char*)value);
  18917. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  18918. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18919. isSuccess = ConfigurationStatus_Accepted;
  18920. }
  18921. else
  18922. {
  18923. isSuccess = ConfigurationStatus_Rejected;
  18924. }
  18925. }
  18926. if(strcmp(key, "SecurityProfile") == 0)
  18927. {
  18928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  18929. {
  18930. check_ascii = value[0];
  18931. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  18932. {
  18933. isSuccess = ConfigurationStatus_Rejected;
  18934. }
  18935. else if(check_ascii == 0x33)
  18936. {
  18937. isSuccess = NotSupported;
  18938. }
  18939. else
  18940. {
  18941. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  18942. {
  18943. if(((check_ascii - 0x30) == 1) ||
  18944. ((check_ascii - 0x30) == 2) ||
  18945. (((check_ascii - 0x30) == 3) && (access(CERTIFICATE_CP,F_OK) != -1)))
  18946. {
  18947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  18948. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  18949. isSuccess = ConfigurationStatus_Accepted;
  18950. }
  18951. else
  18952. isSuccess = ConfigurationStatus_Rejected;
  18953. }
  18954. else
  18955. isSuccess = ConfigurationStatus_Rejected;
  18956. }
  18957. }
  18958. else
  18959. {
  18960. isSuccess = ConfigurationStatus_Rejected;
  18961. }
  18962. }
  18963. if(strcmp(key, "DefaultPrice") == 0)
  18964. {
  18965. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  18966. {
  18967. strcpy(str, (const char*)value);
  18968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  18969. isSuccess = ConfigurationStatus_Accepted;
  18970. }
  18971. else
  18972. {
  18973. isSuccess = ConfigurationStatus_Rejected;
  18974. }
  18975. }
  18976. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  18977. {
  18978. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  18979. {
  18980. strcpy(str, (const char*)value);
  18981. for(int i = 0; str[i]; i++)
  18982. {
  18983. str[i] = tolower(str[i]);
  18984. }
  18985. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18986. isSuccess = ConfigurationStatus_Accepted;
  18987. }
  18988. else
  18989. {
  18990. isSuccess = ConfigurationStatus_Rejected;
  18991. }
  18992. }
  18993. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  18994. {
  18995. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  18996. {
  18997. strcpy(str, (const char*)value);
  18998. for(int i = 0; str[i]; i++)
  18999. {
  19000. str[i] = tolower(str[i]);
  19001. }
  19002. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19003. isSuccess = ConfigurationStatus_Accepted;
  19004. }
  19005. else
  19006. {
  19007. isSuccess = ConfigurationStatus_Rejected;
  19008. }
  19009. }
  19010. if(strcmp(key, "TimeOffset") == 0)
  19011. {
  19012. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  19013. {
  19014. strcpy(str, (const char*)value);
  19015. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  19016. isSuccess = ConfigurationStatus_Accepted;
  19017. }
  19018. else
  19019. {
  19020. isSuccess = ConfigurationStatus_Rejected;
  19021. }
  19022. }
  19023. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  19024. {
  19025. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  19026. {
  19027. strcpy(str, (const char*)value);
  19028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  19029. isSuccess = ConfigurationStatus_Accepted;
  19030. }
  19031. else
  19032. {
  19033. isSuccess = ConfigurationStatus_Rejected;
  19034. }
  19035. }
  19036. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  19037. {
  19038. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  19039. {
  19040. strcpy(str, (const char*)value);
  19041. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  19042. isSuccess = ConfigurationStatus_Accepted;
  19043. }
  19044. else
  19045. {
  19046. isSuccess = ConfigurationStatus_Rejected;
  19047. }
  19048. }
  19049. if(strcmp(key, "SystemUptimeSec") == 0)
  19050. {
  19051. isSuccess = NotSupported;
  19052. }
  19053. if(strcmp(key, "FreeVend") == 0)
  19054. {
  19055. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  19056. {
  19057. strcpy(str, (const char*)value);
  19058. for(int i = 0; str[i]; i++)
  19059. {
  19060. str[i] = tolower(str[i]);
  19061. }
  19062. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  19063. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19064. isSuccess = ConfigurationStatus_Accepted;
  19065. }
  19066. else
  19067. {
  19068. isSuccess = ConfigurationStatus_Rejected;
  19069. }
  19070. }
  19071. if(strcmp(key, "FreeVendIdtag") == 0)
  19072. {
  19073. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  19074. {
  19075. strcpy(str, (const char*)value);
  19076. if(strlen(str) <= 20)
  19077. {
  19078. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  19079. isSuccess = ConfigurationStatus_Accepted;
  19080. }
  19081. else
  19082. {
  19083. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  19084. isSuccess = ConfigurationStatus_Rejected;
  19085. }
  19086. }
  19087. else
  19088. {
  19089. isSuccess = ConfigurationStatus_Rejected;
  19090. }
  19091. }
  19092. if(strcmp(key, "OcppServer") == 0)
  19093. {
  19094. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  19095. {
  19096. strcpy(str, (const char*)value);
  19097. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  19098. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  19099. isSuccess = ConfigurationStatus_Accepted;
  19100. }
  19101. else
  19102. {
  19103. isSuccess = ConfigurationStatus_Rejected;
  19104. }
  19105. }
  19106. if(strcmp(key, "MaintainServer") == 0)
  19107. {
  19108. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  19109. {
  19110. strcpy(str, (const char*)value);
  19111. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  19112. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  19113. isSuccess = ConfigurationStatus_Accepted;
  19114. }
  19115. else
  19116. {
  19117. isSuccess = ConfigurationStatus_Rejected;
  19118. }
  19119. }
  19120. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  19121. {
  19122. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  19123. {
  19124. strcpy(str, (const char*)value);
  19125. for(int i = 0; str[i]; i++)
  19126. {
  19127. str[i] = tolower(str[i]);
  19128. }
  19129. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  19130. isSuccess = ConfigurationStatus_Accepted;
  19131. }
  19132. else
  19133. {
  19134. isSuccess = ConfigurationStatus_Rejected;
  19135. }
  19136. }
  19137. if(strcmp(key, "StatusNotificationInterval") == 0)
  19138. {
  19139. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  19140. {
  19141. check_ascii = value[0];
  19142. if( (check_ascii < 48) || (check_ascii > 57) )
  19143. {
  19144. isSuccess = ConfigurationStatus_Rejected;
  19145. }
  19146. else
  19147. {
  19148. if((atoi(value) == 0) || (atoi(value) >= 10))
  19149. {
  19150. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  19151. isSuccess = ConfigurationStatus_Accepted;
  19152. }
  19153. else
  19154. isSuccess = ConfigurationStatus_Rejected;
  19155. }
  19156. }
  19157. else
  19158. {
  19159. isSuccess = ConfigurationStatus_Rejected;
  19160. }
  19161. }
  19162. if(strcmp(key, "PreAuthAmount") == 0)
  19163. {
  19164. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  19165. {
  19166. check_ascii = value[0];
  19167. if( (check_ascii < 48) || (check_ascii > 57) )
  19168. {
  19169. isSuccess = ConfigurationStatus_Rejected;
  19170. }
  19171. else
  19172. {
  19173. if(atof(value) >= 0)
  19174. {
  19175. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  19176. isSuccess = ConfigurationStatus_Accepted;
  19177. }
  19178. else
  19179. isSuccess = ConfigurationStatus_Rejected;
  19180. }
  19181. }
  19182. else
  19183. {
  19184. isSuccess = ConfigurationStatus_Rejected;
  19185. }
  19186. }
  19187. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  19188. {
  19189. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  19190. {
  19191. check_ascii = value[0];
  19192. if( (check_ascii < 48) || (check_ascii > 57) )
  19193. {
  19194. isSuccess = ConfigurationStatus_Rejected;
  19195. }
  19196. else
  19197. {
  19198. if(atoi(value) >= 0)
  19199. {
  19200. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  19201. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  19202. isSuccess = ConfigurationStatus_Accepted;
  19203. }
  19204. else
  19205. isSuccess = ConfigurationStatus_Rejected;
  19206. }
  19207. }
  19208. else
  19209. {
  19210. isSuccess = ConfigurationStatus_Rejected;
  19211. }
  19212. }
  19213. if(strcmp(key, "PowerSharingServerIP") == 0)
  19214. {
  19215. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  19216. {
  19217. strcpy(str, (const char*)value);
  19218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  19219. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  19220. isSuccess = ConfigurationStatus_Accepted;
  19221. }
  19222. else
  19223. {
  19224. isSuccess = ConfigurationStatus_Rejected;
  19225. }
  19226. }
  19227. if(strcmp(key, "EVCCID_PREFIX") == 0)
  19228. {
  19229. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  19230. {
  19231. strcpy(str, (const char*)value);
  19232. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  19233. isSuccess = ConfigurationStatus_Accepted;
  19234. }
  19235. else
  19236. {
  19237. isSuccess = ConfigurationStatus_Rejected;
  19238. }
  19239. }
  19240. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  19241. {
  19242. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  19243. {
  19244. if(atoi(value) > modelnameInfo.ratedPower)
  19245. {
  19246. isSuccess = ConfigurationStatus_Rejected;
  19247. }
  19248. else{
  19249. strcpy(str, (const char*)value);
  19250. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  19251. isSuccess = ConfigurationStatus_Accepted;
  19252. }
  19253. }
  19254. else
  19255. {
  19256. isSuccess = ConfigurationStatus_Rejected;
  19257. }
  19258. }
  19259. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  19260. {
  19261. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  19262. {
  19263. if((atoi(value) != 0) && (atoi(value) < 5))
  19264. {
  19265. isSuccess = ConfigurationStatus_Rejected;
  19266. }
  19267. else{
  19268. strcpy(str, (const char*)value);
  19269. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  19270. isSuccess = ConfigurationStatus_Accepted;
  19271. }
  19272. }
  19273. else
  19274. {
  19275. isSuccess = ConfigurationStatus_Rejected;
  19276. }
  19277. }
  19278. if(strcmp(key, "CpoName") == 0)
  19279. {
  19280. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  19281. {
  19282. strcpy(str, (const char*)value);
  19283. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", str );
  19284. isSuccess = ConfigurationStatus_Accepted;
  19285. }
  19286. else
  19287. {
  19288. isSuccess = ConfigurationStatus_Rejected;
  19289. }
  19290. }
  19291. #if 0
  19292. //For OCPP Test Case
  19293. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  19294. {
  19295. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19296. {
  19297. strcpy(str, (const char*)value);
  19298. for(int i = 0; str[i]; i++)
  19299. {
  19300. str[i] = tolower(str[i]);
  19301. }
  19302. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19303. isSuccess = ConfigurationStatus_Accepted;
  19304. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19305. }
  19306. else
  19307. {
  19308. isSuccess = ConfigurationStatus_Rejected;
  19309. }
  19310. }
  19311. #endif
  19312. #if 1
  19313. if(strcmp(key, "LocalAuthListEnabled") == 0)
  19314. {
  19315. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19316. {
  19317. strcpy(str, (const char*)value);
  19318. for(int i = 0; str[i]; i++)
  19319. {
  19320. str[i] = tolower(str[i]);
  19321. }
  19322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19323. isSuccess = ConfigurationStatus_Accepted;
  19324. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19325. }
  19326. else
  19327. {
  19328. isSuccess = ConfigurationStatus_Rejected;
  19329. }
  19330. }
  19331. #endif
  19332. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  19333. {
  19334. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  19335. {
  19336. check_ascii = value[0];
  19337. if( (check_ascii < 48) || (check_ascii > 57) )
  19338. {
  19339. isSuccess = ConfigurationStatus_Rejected;
  19340. }
  19341. else
  19342. {
  19343. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  19344. isSuccess = ConfigurationStatus_Accepted;
  19345. }
  19346. }
  19347. else
  19348. {
  19349. isSuccess = ConfigurationStatus_Rejected;
  19350. }
  19351. }
  19352. if(strcmp(key, "SendLocalListMaxLength") == 0)
  19353. {
  19354. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  19355. {
  19356. check_ascii = value[0];
  19357. if( (check_ascii < 48) || (check_ascii > 57) )
  19358. {
  19359. isSuccess = ConfigurationStatus_Rejected;
  19360. }
  19361. else
  19362. {
  19363. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  19364. isSuccess = ConfigurationStatus_Accepted;
  19365. }
  19366. }
  19367. else
  19368. {
  19369. isSuccess = ConfigurationStatus_Rejected;
  19370. }
  19371. }
  19372. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  19373. {
  19374. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  19375. {
  19376. strcpy(str, (const char*)value);
  19377. for(int i = 0; str[i]; i++)
  19378. {
  19379. str[i] = tolower(str[i]);
  19380. }
  19381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19382. isSuccess = ConfigurationStatus_Accepted;
  19383. }
  19384. else
  19385. {
  19386. isSuccess = ConfigurationStatus_Rejected;
  19387. }
  19388. }
  19389. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  19390. {
  19391. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  19392. {
  19393. check_ascii = value[0];
  19394. if( (check_ascii < 48) || (check_ascii > 57) )
  19395. {
  19396. isSuccess = ConfigurationStatus_Rejected;
  19397. }
  19398. else
  19399. {
  19400. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  19401. isSuccess = ConfigurationStatus_Accepted;
  19402. }
  19403. }
  19404. else
  19405. {
  19406. isSuccess = ConfigurationStatus_Rejected;
  19407. }
  19408. }
  19409. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  19410. {
  19411. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  19412. {
  19413. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  19414. isSuccess = ConfigurationStatus_Accepted;
  19415. }
  19416. else
  19417. {
  19418. isSuccess = ConfigurationStatus_Rejected;
  19419. }
  19420. }
  19421. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  19422. {
  19423. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  19424. {
  19425. check_ascii = value[0];
  19426. if( (check_ascii < 48) || (check_ascii > 57) )
  19427. {
  19428. isSuccess = ConfigurationStatus_Rejected;
  19429. }
  19430. else
  19431. {
  19432. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  19433. isSuccess = ConfigurationStatus_Accepted;
  19434. }
  19435. }
  19436. else
  19437. {
  19438. isSuccess = ConfigurationStatus_Rejected;
  19439. }
  19440. }
  19441. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  19442. {
  19443. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  19444. {
  19445. strcpy(str, (const char*)value);
  19446. for(int i = 0; str[i]; i++)
  19447. {
  19448. str[i] = tolower(str[i]);
  19449. }
  19450. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19451. isSuccess = ConfigurationStatus_Accepted;
  19452. }
  19453. else
  19454. {
  19455. isSuccess = ConfigurationStatus_Rejected;
  19456. }
  19457. }
  19458. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  19459. {
  19460. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  19461. {
  19462. check_ascii = value[0];
  19463. if( (check_ascii < 48) || (check_ascii > 57) )
  19464. {
  19465. isSuccess = ConfigurationStatus_Rejected;
  19466. }
  19467. else
  19468. {
  19469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  19470. isSuccess = ConfigurationStatus_Accepted;
  19471. }
  19472. }
  19473. else
  19474. {
  19475. isSuccess = ConfigurationStatus_Rejected;
  19476. }
  19477. }
  19478. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19479. return isSuccess;
  19480. }
  19481. int TransactionMessageAttemptsGet(void)
  19482. {
  19483. return TransactionMessageAttemptsValue;
  19484. }
  19485. int FirstHeartBeatResponse(void)
  19486. {
  19487. return FirstHeartBeat;
  19488. }
  19489. int TransactionMessageRetryIntervalGet(void)
  19490. {
  19491. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19492. }
  19493. int ReadHttpStatus(int sock)
  19494. {
  19495. //char c;
  19496. char buff[1024]="",*ptr=buff+1;
  19497. int bytes_received, status;
  19498. DEBUG_INFO("Begin Response ..\n");
  19499. while((bytes_received = recv(sock, ptr, 1, 0))){
  19500. if(bytes_received==-1){
  19501. perror("ReadHttpStatus");
  19502. exit(1);
  19503. }
  19504. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  19505. ptr++;
  19506. }
  19507. *ptr=0;
  19508. ptr=buff+1;
  19509. sscanf(ptr,"%*s %d ", &status);
  19510. DEBUG_INFO("%s\n",ptr);
  19511. DEBUG_INFO("status=%d\n",status);
  19512. DEBUG_INFO("End Response ..\n");
  19513. return (bytes_received>0)?status:0;
  19514. }
  19515. //the only filed that it parsed is 'Content-Length'
  19516. int ParseHeader(int sock)
  19517. {
  19518. //char c;
  19519. char buff[1024]="",*ptr=buff+4;
  19520. int bytes_received;
  19521. DEBUG_INFO("Begin HEADER ..\n");
  19522. while((bytes_received = recv(sock, ptr, 1, 0))){
  19523. if(bytes_received==-1){
  19524. perror("Parse Header");
  19525. exit(1);
  19526. }
  19527. if(
  19528. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  19529. (ptr[-1]=='\r') && (*ptr=='\n' )
  19530. ) break;
  19531. ptr++;
  19532. }
  19533. *ptr=0;
  19534. ptr=buff+4;
  19535. //printf("%s",ptr);
  19536. if(bytes_received){
  19537. ptr=strstr(ptr,"Content-Length:");
  19538. if(ptr){
  19539. sscanf(ptr,"%*s %d",&bytes_received);
  19540. }else
  19541. bytes_received=-1; //unknown size
  19542. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  19543. }
  19544. DEBUG_INFO("End HEADER ..\n");
  19545. return bytes_received ;
  19546. }
  19547. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  19548. {
  19549. int result = TRUE;
  19550. char rmFileCmd[100]={0};
  19551. char FilePath[100]={0};
  19552. char ftpbuf[200];
  19553. int systemresult;
  19554. sprintf(FilePath,"/mnt/%s",filename);
  19555. system("ping 8.8.8.8 &");
  19556. if((access(FilePath,F_OK))!=-1)
  19557. {
  19558. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19559. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19560. system(rmFileCmd);
  19561. }
  19562. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19563. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  19564. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19565. systemresult = system(ftpbuf);
  19566. if(systemresult != 0)
  19567. {
  19568. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  19569. result = FALSE;
  19570. }
  19571. system("pkill ping");
  19572. return result;
  19573. }
  19574. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  19575. {
  19576. int result = TRUE;
  19577. char rmFileCmd[100]={0};
  19578. char FilePath[100]={0};
  19579. char ftpbuf[200];
  19580. int systemresult;
  19581. sprintf(FilePath,"/mnt/%s",filename);
  19582. system("ping 8.8.8.8 &");
  19583. if((access(FilePath,F_OK))!=-1)
  19584. {
  19585. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19586. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19587. system(rmFileCmd);
  19588. }
  19589. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19590. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  19591. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19592. systemresult = system(ftpbuf);
  19593. if(systemresult != 0)
  19594. {
  19595. DEBUG_WARN("scp error!\n");
  19596. result = FALSE;
  19597. }
  19598. system("pkill ping");
  19599. return result;
  19600. }
  19601. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  19602. {
  19603. int result = TRUE;
  19604. char rmFileCmd[100]={0};
  19605. char FilePath[100]={0};
  19606. char ftpbuf[200];
  19607. int systemresult;
  19608. sprintf(FilePath,"/mnt/%s",filename);
  19609. system("ping 8.8.8.8 &");
  19610. if((access(FilePath,F_OK))!=-1)
  19611. {
  19612. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19613. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19614. system(rmFileCmd);
  19615. }
  19616. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19617. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  19618. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19619. systemresult = system(ftpbuf);
  19620. if(systemresult != 0)
  19621. {
  19622. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  19623. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19624. systemresult = system(ftpbuf);
  19625. if(systemresult != 0)
  19626. {
  19627. DEBUG_WARN("FTP download fail!\n");
  19628. result = FALSE;
  19629. }
  19630. }
  19631. system("pkill ping");
  19632. return result;
  19633. }
  19634. int httpUploadFile(char *location, char *path, char *filename,char *url)
  19635. {
  19636. char rmFileCmd[100]={0};
  19637. char FilePath[100]={0};
  19638. char buf[512];
  19639. int systemresult = 0;
  19640. //DEBUG_INFO("filename=%s\n",filename);
  19641. //DEBUG_INFO("url=%s\n",url);
  19642. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  19643. if((access(FilePath,F_OK))!=-1)
  19644. {
  19645. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19646. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19647. system(rmFileCmd);
  19648. }
  19649. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  19650. if(fp == NULL)
  19651. {
  19652. DEBUG_INFO("log is NULL\n");
  19653. return FALSE;
  19654. }
  19655. else
  19656. {
  19657. fprintf(fp, "%s\n", url);
  19658. fprintf(fp, "%s\n", filename);
  19659. fclose(fp);
  19660. }
  19661. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  19662. if(phpFP == NULL)
  19663. {
  19664. DEBUG_INFO("PHP upload fail.\n");
  19665. return FALSE;
  19666. }
  19667. else
  19668. {
  19669. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19670. {
  19671. if(strstr(buf, "result") != NULL)
  19672. {
  19673. sscanf(buf, "result: %d", &systemresult);
  19674. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  19675. }
  19676. }
  19677. pclose(phpFP);
  19678. }
  19679. if(systemresult != 1)
  19680. {
  19681. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  19682. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  19683. if(phpFP == NULL)
  19684. {
  19685. DEBUG_WARN("PHP PUT upload fail.\n");
  19686. return FALSE;
  19687. }
  19688. else
  19689. {
  19690. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19691. {
  19692. if(strstr(buf, "result") != NULL)
  19693. {
  19694. sscanf(buf, "result: %d", &systemresult);
  19695. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  19696. }
  19697. }
  19698. pclose(phpFP);
  19699. }
  19700. }
  19701. if(systemresult != 1)
  19702. {
  19703. DEBUG_WARN("PHP PUT upload fail.\n");
  19704. return FALSE;
  19705. }
  19706. return TRUE;
  19707. }
  19708. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  19709. {
  19710. int result = FALSE;
  19711. char ftpbuf[200];
  19712. int systemresult;
  19713. /*
  19714. // Domaind name transfer to IP address
  19715. struct hostent* server;
  19716. char *IPbuffer;
  19717. server = gethostbyname(location);
  19718. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  19719. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19720. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  19721. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  19722. systemresult = system(ftpbuf);
  19723. if(systemresult != 0)
  19724. {
  19725. DEBUG_INFO("ftpput error!\n");
  19726. }
  19727. else
  19728. {
  19729. result = TRUE;
  19730. DEBUG_INFO("ftpput OK!\n");
  19731. }
  19732. return result;
  19733. }
  19734. int GetOcppServerURL()
  19735. {
  19736. int result = FALSE;
  19737. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  19738. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  19739. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  19740. struct yuarel url;
  19741. char urlStr[512];
  19742. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  19743. {
  19744. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  19745. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19746. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19747. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  19748. if(yuarel_parse(&url, urlStr) != -1)
  19749. {
  19750. sprintf(OcppProtocol, "%s", url.scheme);
  19751. sprintf(OcppHost, "%s", url.host);
  19752. if(url.path == NULL)
  19753. OcppTempPath[0] = '\0';
  19754. else
  19755. {
  19756. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  19757. {
  19758. sprintf(OcppTempPath, "%s/", url.path);
  19759. }
  19760. else
  19761. {
  19762. sprintf(OcppTempPath, "%s", url.path);
  19763. }
  19764. }
  19765. if(url.port == 0)
  19766. {
  19767. if(strcmp(OcppProtocol, "wss") == 0)
  19768. OcppPort = 443;
  19769. else
  19770. OcppPort = 80;
  19771. }
  19772. else
  19773. OcppPort = url.port;
  19774. result = TRUE;
  19775. }
  19776. }
  19777. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  19778. {
  19779. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  19780. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19781. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19782. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  19783. if(yuarel_parse(&url, urlStr) != -1)
  19784. {
  19785. sprintf(OcppProtocol, "%s", url.scheme);
  19786. sprintf(OcppHost, "%s", url.host);
  19787. if(url.path == NULL)
  19788. OcppTempPath[0] = '\0';
  19789. else
  19790. sprintf(OcppTempPath, "%s", url.path);
  19791. if(url.port == 0)
  19792. {
  19793. if(strcmp(OcppProtocol, "wss") == 0)
  19794. OcppPort = 443;
  19795. else
  19796. OcppPort = 80;
  19797. }
  19798. else
  19799. OcppPort = url.port;
  19800. result = TRUE;
  19801. }
  19802. }
  19803. else
  19804. {
  19805. strcpy(OcppHost,"");
  19806. }
  19807. return result;
  19808. }
  19809. int GetOcppPath()
  19810. {
  19811. int result = FALSE;
  19812. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  19813. {
  19814. if(OcppTempPath == NULL)
  19815. {
  19816. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19817. }
  19818. else
  19819. {
  19820. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19821. }
  19822. result = TRUE;
  19823. goto End;
  19824. }
  19825. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  19826. {
  19827. if(OcppTempPath == NULL)
  19828. {
  19829. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  19830. }
  19831. else
  19832. {
  19833. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  19834. }
  19835. result = TRUE;
  19836. goto End;
  19837. }
  19838. else
  19839. {
  19840. strcpy(OcppPath,"");
  19841. }
  19842. End:
  19843. return result;
  19844. }
  19845. int GetOcppPort()
  19846. {
  19847. return OcppPort;
  19848. }
  19849. int GetOcppConnStatus(void)
  19850. {
  19851. return ShmOCPP16Data->OcppConnStatus;
  19852. }
  19853. void SetOcppConnStatus(uint8_t status)
  19854. {
  19855. ShmOCPP16Data->OcppConnStatus = status;
  19856. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  19857. }
  19858. int GetHeartBeatWithNOResponse(void)
  19859. {
  19860. return HeartBeatWithNOResponse;
  19861. }
  19862. void SetHeartBeatWithNOResponse(void)
  19863. {
  19864. HeartBeatWithNOResponse = 0;
  19865. }
  19866. void GetStartTransactionIdTag(int gun_index)
  19867. {
  19868. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  19869. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  19870. }
  19871. int GetStartTransactionId(int gun_index)
  19872. {
  19873. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19874. }
  19875. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  19876. {
  19877. char ch;
  19878. FILE *fptr1;
  19879. int temptransactionId;
  19880. char str[100]={0};
  19881. temptransactionId = 0;
  19882. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  19883. {
  19884. DEBUG_INFO("IdTag is empty.\n");
  19885. return temptransactionId;
  19886. }
  19887. /*------ Read the file ----------------*/
  19888. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  19889. if (!fptr1)
  19890. {
  19891. DEBUG_INFO("QueueTransactionId file open error.\n");
  19892. //printf(" File not found or unable to open the input file!!\n");
  19893. return temptransactionId;
  19894. }
  19895. ch=fgetc(fptr1);
  19896. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  19897. rewind(fptr1);
  19898. if(ch!=EOF)
  19899. {
  19900. // printf("%c",ch);
  19901. while (fgets(str, 100, fptr1) != NULL)
  19902. {
  19903. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19904. if(str[0]=='\0')
  19905. {
  19906. break;
  19907. }
  19908. char *revbuf[8] = {0}; // Variable store string split
  19909. int num = 0;// Quantity after string split
  19910. DEBUG_INFO("Transaction queue data= %s\n", str);
  19911. splitstring(str,",",revbuf,&num); // String split
  19912. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  19913. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  19914. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  19915. DEBUG_INFO("------------------------------\n");
  19916. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  19917. {
  19918. if(isStopTransaction)
  19919. {
  19920. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  19921. {
  19922. temptransactionId = atoi(revbuf[2]);
  19923. //break;
  19924. }
  19925. }
  19926. else
  19927. {
  19928. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  19929. {
  19930. temptransactionId = atoi(revbuf[2]);
  19931. //break;
  19932. }
  19933. }
  19934. }
  19935. }
  19936. }
  19937. else
  19938. DEBUG_INFO("EOF\n");
  19939. fclose(fptr1);
  19940. /*------- End of reading ---------------*/
  19941. return temptransactionId;
  19942. }
  19943. void SetTransactionIdZero(int transactionId)
  19944. {
  19945. char ch;
  19946. FILE *fptr1, *fptr2;
  19947. int temptransactionId = 0;
  19948. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  19949. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  19950. if (!fptr1)
  19951. {
  19952. //printf(" File not found or unable to open the input file!!\n");
  19953. return ;
  19954. }
  19955. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  19956. if (!fptr2)
  19957. {
  19958. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  19959. fclose(fptr1);
  19960. return ;
  19961. }
  19962. ch=fgetc(fptr1);
  19963. rewind(fptr1);
  19964. if(ch!=EOF)
  19965. {
  19966. // copy all contents to the temporary file except the specific line
  19967. while (fgets(str, 100, fptr1) != NULL)
  19968. {
  19969. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19970. if(str[0]=='\0')
  19971. {
  19972. break;
  19973. }
  19974. char *revbuf[8] = {0};
  19975. int num = 0;
  19976. strcpy(strtemp, str);
  19977. splitstring(str,",",revbuf,&num);
  19978. if(revbuf[2][0] != '\0')
  19979. {
  19980. temptransactionId = atoi(revbuf[2]);
  19981. if(transactionId != temptransactionId)
  19982. {
  19983. fprintf(fptr2, "%s\n", strtemp);
  19984. }
  19985. }
  19986. }
  19987. }
  19988. fclose(fptr1);
  19989. fclose(fptr2);
  19990. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  19991. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  19992. /*------ Read the file ----------------*/
  19993. }
  19994. int InternetDisconnect(void)
  19995. {
  19996. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  19997. }
  19998. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  19999. void storeTempStopTransaction(int gun_index)
  20000. {
  20001. char guid[37]={0};
  20002. int tempIndex = 0;
  20003. char TempStopTransaction[256];
  20004. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  20005. DEBUG_INFO("storeTempStopTransaction...\n");
  20006. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  20007. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  20008. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  20009. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  20010. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20011. {
  20012. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20013. {
  20014. tempIndex = ((gun_index==2) ? 1: 0);
  20015. }
  20016. else
  20017. {
  20018. tempIndex = gun_index;
  20019. }
  20020. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20021. {
  20022. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20023. {
  20024. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  20025. }
  20026. }// END OF CHAdeMO_QUANTITY
  20027. }
  20028. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20029. {
  20030. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20031. {
  20032. tempIndex = ((gun_index==2) ? 1: 0);
  20033. }
  20034. else
  20035. {
  20036. tempIndex = gun_index;
  20037. }
  20038. for (int index = 0; index < CCS_QUANTITY; index++)
  20039. {
  20040. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20041. {
  20042. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  20043. }
  20044. }// END OF CCS_QUANTITY
  20045. }
  20046. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20047. {
  20048. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20049. {
  20050. tempIndex = ((gun_index==2) ? 1: 0);
  20051. }
  20052. else
  20053. {
  20054. tempIndex = gun_index;
  20055. }
  20056. for (int index = 0; index < GB_QUANTITY; index++)
  20057. {
  20058. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20059. {
  20060. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  20061. }
  20062. }// END OF GB_QUANTITY
  20063. }
  20064. else if(gunType[gun_index] == GUN_TYPE_DO)
  20065. {
  20066. tempIndex = gun_index;
  20067. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20068. {
  20069. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20070. {
  20071. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  20072. }
  20073. }
  20074. }
  20075. else
  20076. {
  20077. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20078. {
  20079. tempIndex = 2;
  20080. }
  20081. else
  20082. {
  20083. tempIndex = gun_index;
  20084. }
  20085. for (int index = 0; index < AC_QUANTITY; index++)
  20086. {
  20087. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20088. {
  20089. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  20090. }
  20091. }// END OF AC_QUANTITY
  20092. }
  20093. //Stop Transaction Time
  20094. struct timeval tmnow;
  20095. struct tm *tm;
  20096. char buf[28];//, usec_buf[6];
  20097. gettimeofday(&tmnow, NULL);
  20098. time_t t;
  20099. t = time(NULL);
  20100. /*UTC time and date*/
  20101. tm = gmtime(&t);
  20102. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  20103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  20104. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  20105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  20106. random_uuid(guid);
  20107. /***********************************transactionData******************************************************/
  20108. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  20109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  20110. //=================================
  20111. //1. Transaction_Begin
  20112. //=================================
  20113. //============================== Energy.Active.Import.Interval ===========================================
  20114. //=================================
  20115. //2. Transaction_End
  20116. //=================================
  20117. //2.1====================================== Current.Import L1 ==============================================
  20118. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  20119. {
  20120. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  20121. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20122. {
  20123. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20124. {
  20125. tempIndex = ((gun_index==2) ? 1: 0);
  20126. }
  20127. else
  20128. {
  20129. tempIndex = gun_index;
  20130. }
  20131. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20132. {
  20133. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20134. {
  20135. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  20136. }
  20137. }// End of for CHAdeMO_QUANTITY
  20138. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  20139. }
  20140. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20141. {
  20142. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20143. {
  20144. tempIndex = ((gun_index==2) ? 1: 0);
  20145. }
  20146. else
  20147. {
  20148. tempIndex = gun_index;
  20149. }
  20150. for (int index = 0; index < CCS_QUANTITY; index++)
  20151. {
  20152. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20153. {
  20154. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  20155. }
  20156. }// End of for CCS_QUANTITY
  20157. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  20158. }
  20159. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20160. {
  20161. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20162. {
  20163. tempIndex = ((gun_index==2) ? 1: 0);
  20164. }
  20165. else
  20166. {
  20167. tempIndex = gun_index;
  20168. }
  20169. for (int index = 0; index < GB_QUANTITY; index++)
  20170. {
  20171. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20172. {
  20173. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  20174. }
  20175. }// End of for GB_QUANTITY
  20176. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  20177. }
  20178. else if(gunType[gun_index] == GUN_TYPE_DO)
  20179. {
  20180. tempIndex = gun_index;
  20181. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20182. {
  20183. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20184. {
  20185. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  20186. }
  20187. }
  20188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  20189. }
  20190. else
  20191. {
  20192. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20193. {
  20194. tempIndex = 2;
  20195. }
  20196. else
  20197. {
  20198. tempIndex = gun_index;
  20199. }
  20200. for (int index = 0; index < AC_QUANTITY; index++)
  20201. {
  20202. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20203. {
  20204. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  20205. }
  20206. }// End of for AC_QUANTITY
  20207. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  20208. }
  20209. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20210. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  20211. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  20212. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  20213. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  20214. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  20215. }
  20216. //2.2===================================== Energy.Active.Import.Interval ==========================================
  20217. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  20218. {
  20219. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20220. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20221. {
  20222. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20223. {
  20224. tempIndex = ((gun_index==2) ? 1: 0);
  20225. }
  20226. else
  20227. {
  20228. tempIndex = gun_index;
  20229. }
  20230. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20231. {
  20232. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20233. {
  20234. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  20235. }
  20236. }// END OF CHAdeMO_QUANTITY
  20237. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  20238. }
  20239. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20240. {
  20241. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20242. {
  20243. tempIndex = ((gun_index==2) ? 1: 0);
  20244. }
  20245. else
  20246. {
  20247. tempIndex = gun_index;
  20248. }
  20249. for (int index = 0; index < CCS_QUANTITY; index++)
  20250. {
  20251. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20252. {
  20253. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  20254. }
  20255. }// END OF CCS_QUANTITY
  20256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  20257. }
  20258. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20259. {
  20260. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20261. {
  20262. tempIndex = ((gun_index==2) ? 1: 0);
  20263. }
  20264. else
  20265. {
  20266. tempIndex = gun_index;
  20267. }
  20268. for (int index = 0; index < GB_QUANTITY; index++)
  20269. {
  20270. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20271. {
  20272. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  20273. }
  20274. }// END OF GB_QUANTITY
  20275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  20276. }
  20277. else if(gunType[gun_index] == GUN_TYPE_DO)
  20278. {
  20279. tempIndex = gun_index;
  20280. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20281. {
  20282. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20283. {
  20284. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  20285. }
  20286. }
  20287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  20288. }
  20289. else
  20290. {
  20291. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20292. {
  20293. tempIndex = 2;
  20294. }
  20295. else
  20296. {
  20297. tempIndex = gun_index;
  20298. }
  20299. for (int index = 0; index < AC_QUANTITY; index++)
  20300. {
  20301. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20302. {
  20303. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));// PresentChargedEnergy is 0~6553.5 kWh
  20304. }
  20305. }// END OF AC_QUANTITY
  20306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  20307. }
  20308. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  20310. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  20311. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  20312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  20313. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  20314. }
  20315. //2.3====================================== Power.Active.Import =========================================
  20316. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  20317. {
  20318. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20319. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20320. {
  20321. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20322. {
  20323. tempIndex = ((gun_index==2) ? 1: 0);
  20324. }
  20325. else
  20326. {
  20327. tempIndex = gun_index;
  20328. }
  20329. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20330. {
  20331. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20332. {
  20333. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20334. }
  20335. } // End for CHAdeMO_QUANTITY
  20336. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  20337. }
  20338. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20339. {
  20340. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20341. {
  20342. tempIndex = ((gun_index==2) ? 1: 0);
  20343. }
  20344. else
  20345. {
  20346. tempIndex = gun_index;
  20347. }
  20348. for (int index = 0; index < CCS_QUANTITY; index++)
  20349. {
  20350. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20351. {
  20352. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20353. }
  20354. } // END for CCS_QUANTITY
  20355. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  20356. }
  20357. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20358. {
  20359. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20360. {
  20361. tempIndex = ((gun_index==2) ? 1: 0);
  20362. }
  20363. else
  20364. {
  20365. tempIndex = gun_index;
  20366. }
  20367. for (int index = 0; index < GB_QUANTITY; index++)
  20368. {
  20369. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20370. {
  20371. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20372. }
  20373. }// END for GB_QUANTITY
  20374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  20375. }
  20376. else if(gunType[gun_index] == GUN_TYPE_DO)
  20377. {
  20378. tempIndex = gun_index;
  20379. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20380. {
  20381. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20382. {
  20383. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20384. }
  20385. }
  20386. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  20387. }
  20388. else
  20389. {
  20390. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20391. {
  20392. tempIndex = 2;
  20393. }
  20394. else
  20395. {
  20396. tempIndex = gun_index;
  20397. }
  20398. for (int index = 0; index < AC_QUANTITY; index++)
  20399. {
  20400. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20401. {
  20402. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20403. }
  20404. } // END for AC_QUANTITY
  20405. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  20406. }
  20407. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20408. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  20409. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  20410. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  20411. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  20412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  20413. }
  20414. //2.4====================================== Voltage L1 ====================================================
  20415. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  20416. {
  20417. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20418. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20419. {
  20420. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20421. {
  20422. tempIndex = ((gun_index==2) ? 1: 0);
  20423. }
  20424. else
  20425. {
  20426. tempIndex = gun_index;
  20427. }
  20428. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20429. {
  20430. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20431. {
  20432. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  20433. }
  20434. } // END OF FOR CHAdeMO_QUANTITY
  20435. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  20436. }
  20437. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20438. {
  20439. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20440. {
  20441. tempIndex = ((gun_index==2) ? 1: 0);
  20442. }
  20443. else
  20444. {
  20445. tempIndex = gun_index;
  20446. }
  20447. for (int index = 0; index < CCS_QUANTITY; index++)
  20448. {
  20449. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20450. {
  20451. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  20452. }
  20453. } // END OF FOR CCS_QUANTITY
  20454. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  20455. }
  20456. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20457. {
  20458. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20459. {
  20460. tempIndex = ((gun_index==2) ? 1: 0);
  20461. }
  20462. else
  20463. {
  20464. tempIndex = gun_index;
  20465. }
  20466. for (int index = 0; index < GB_QUANTITY; index++)
  20467. {
  20468. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20469. {
  20470. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  20471. }
  20472. } // END OF FOR GB_QUANTITY
  20473. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  20474. }
  20475. else if(gunType[gun_index] == GUN_TYPE_DO)
  20476. {
  20477. tempIndex = gun_index;
  20478. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20479. {
  20480. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20481. {
  20482. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  20483. }
  20484. }
  20485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  20486. }
  20487. else
  20488. {
  20489. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20490. {
  20491. tempIndex = 2;
  20492. }
  20493. else
  20494. {
  20495. tempIndex = gun_index;
  20496. }
  20497. for (int index = 0; index < AC_QUANTITY; index++)
  20498. {
  20499. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20500. {
  20501. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  20502. }
  20503. } // END OF FOR AC_QUANTITY
  20504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  20505. }
  20506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  20508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  20509. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  20510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  20511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  20512. }
  20513. //2.5============================================== End SoC =========================================================
  20514. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  20515. {
  20516. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20517. 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))
  20518. {
  20519. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  20520. {
  20521. tempIndex = ((gun_index==2) ? 1: 0);
  20522. }
  20523. else
  20524. {
  20525. tempIndex = gun_index;
  20526. }
  20527. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20528. {
  20529. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20530. {
  20531. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20532. {
  20533. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  20534. }
  20535. }
  20536. }
  20537. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20538. {
  20539. for (int index = 0; index < CCS_QUANTITY; index++)
  20540. {
  20541. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20542. {
  20543. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  20544. }
  20545. }
  20546. }
  20547. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20548. {
  20549. for (int index = 0; index < GB_QUANTITY; index++)
  20550. {
  20551. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20552. {
  20553. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  20554. }
  20555. }
  20556. }
  20557. else if(gunType[gun_index] == GUN_TYPE_DO)
  20558. {
  20559. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20560. {
  20561. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20562. {
  20563. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  20564. }
  20565. }
  20566. }
  20567. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20568. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  20569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  20570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  20571. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  20572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  20573. } // END FOR DC CASE
  20574. }
  20575. //2.6====================================== Current.Import L2 ==============================================
  20576. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  20577. {
  20578. // AC 3 phase L2 current
  20579. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  20580. {
  20581. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20582. {
  20583. tempIndex = 2;
  20584. }
  20585. else
  20586. {
  20587. tempIndex = gun_index;
  20588. }
  20589. for (int index = 0; index < AC_QUANTITY; index++)
  20590. {
  20591. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20592. {
  20593. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  20594. }
  20595. }// End of for AC_QUANTITY
  20596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  20597. }
  20598. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20599. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  20600. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  20601. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  20602. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  20603. }
  20604. //2.7====================================== Current.Import L3 ==============================================
  20605. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  20606. {
  20607. // AC 3 phase L3 current
  20608. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  20609. {
  20610. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20611. {
  20612. tempIndex = 2;
  20613. }
  20614. else
  20615. {
  20616. tempIndex = gun_index;
  20617. }
  20618. for (int index = 0; index < AC_QUANTITY; index++)
  20619. {
  20620. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20621. {
  20622. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  20623. }
  20624. }// End of for AC_QUANTITY
  20625. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  20626. }
  20627. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20628. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  20629. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  20630. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  20631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  20632. }
  20633. //2.9====================================== Voltage L2 ====================================================
  20634. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  20635. {
  20636. // AC 3 phase L2 volatge
  20637. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  20638. {
  20639. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20640. {
  20641. tempIndex = 2;
  20642. }
  20643. else
  20644. {
  20645. tempIndex = gun_index;
  20646. }
  20647. for (int index = 0; index < AC_QUANTITY; index++)
  20648. {
  20649. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20650. {
  20651. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  20652. }
  20653. } // END OF FOR AC_QUANTITY
  20654. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  20655. }
  20656. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  20658. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  20659. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  20660. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  20661. }
  20662. //2.10====================================== Voltage L3 ====================================================
  20663. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  20664. {
  20665. // AC 3 phase L3 volatge
  20666. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  20667. {
  20668. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20669. {
  20670. tempIndex = 2;
  20671. }
  20672. else
  20673. {
  20674. tempIndex = gun_index;
  20675. }
  20676. for (int index = 0; index < AC_QUANTITY; index++)
  20677. {
  20678. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20679. {
  20680. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  20681. }
  20682. } // END OF FOR AC_QUANTITY
  20683. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  20684. }
  20685. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20686. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  20687. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  20688. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  20689. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  20690. }
  20691. //====================== Start SoC ================================
  20692. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  20693. {
  20694. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20695. 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))
  20696. {
  20697. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  20698. {
  20699. tempIndex = ((gun_index==2) ? 1: 0);
  20700. }
  20701. else
  20702. {
  20703. tempIndex = gun_index;
  20704. }
  20705. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20706. {
  20707. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20708. {
  20709. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20710. {
  20711. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  20712. }
  20713. }
  20714. }
  20715. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20716. {
  20717. for (int index = 0; index < CCS_QUANTITY; index++)
  20718. {
  20719. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20720. {
  20721. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  20722. }
  20723. }
  20724. }
  20725. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20726. {
  20727. for (int index = 0; index < GB_QUANTITY; index++)
  20728. {
  20729. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20730. {
  20731. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  20732. }
  20733. }
  20734. }
  20735. else if(gunType[gun_index] == GUN_TYPE_DO)
  20736. {
  20737. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20738. {
  20739. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20740. {
  20741. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  20742. }
  20743. }
  20744. }
  20745. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  20746. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  20747. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  20748. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  20749. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  20750. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  20751. } // END FOR DC CASE
  20752. }
  20753. //======================================== Message create ==============================================
  20754. json_object *StopTransaction = json_object_new_object();
  20755. json_object *transactionDatas = json_object_new_array();
  20756. json_object *sampledValues = json_object_new_array();
  20757. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  20758. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  20759. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  20760. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  20761. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  20762. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  20763. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  20764. {
  20765. json_object *transactionData = json_object_new_object();
  20766. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  20767. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  20768. {
  20769. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  20770. {
  20771. json_object *sampledValue = json_object_new_object();
  20772. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  20773. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  20774. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  20775. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  20776. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  20777. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  20778. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  20779. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  20780. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  20781. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  20782. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  20783. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  20784. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  20785. json_object_array_add(sampledValues, sampledValue);
  20786. }
  20787. }
  20788. json_object_object_add(transactionData, "sampledValue", sampledValues);
  20789. json_object_array_add(transactionDatas, transactionData);
  20790. }
  20791. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  20792. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  20793. ,MESSAGE_TYPE_CALL
  20794. ,guid
  20795. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  20796. json_object_put(StopTransaction);
  20797. // Check File "TempStopTransaction" Exist
  20798. if((access(TempStopTransaction,F_OK))!=-1)
  20799. {
  20800. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  20801. fclose(fopen(TempStopTransaction, "w"));
  20802. }
  20803. else
  20804. {
  20805. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  20806. FILE *log = fopen(TempStopTransaction, "w+");
  20807. if(log == NULL)
  20808. {
  20809. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  20810. return ;
  20811. }
  20812. else
  20813. {
  20814. fclose(log);
  20815. }
  20816. }
  20817. //Add TempStopTransaction | Update TempStopTransaction
  20818. // open file for writing
  20819. FILE *outfile;
  20820. outfile = fopen (TempStopTransaction, "a");
  20821. //DEBUG_INFO("data = %s\n", queuedata);
  20822. fputs(queuedata, outfile);
  20823. fputs("\n", outfile);
  20824. fclose (outfile);
  20825. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  20826. OCPP_updatePeriodEnergy(gun_index);
  20827. }
  20828. void checkTempStopTransaction(int gun_index)
  20829. {
  20830. FILE *fptr1;
  20831. char ch;
  20832. char str[QUEUE_MESSAGE_LENGTH]={0};
  20833. char guid[37]={0};
  20834. char tempdata[65]={0};
  20835. char connectorStr[2]={0};
  20836. char TempStopTransaction[256];
  20837. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  20838. fptr1 = fopen(TempStopTransaction, "r");
  20839. //TempStopTransaction格式: 槍號,StopTransaction封包
  20840. if (!fptr1)
  20841. {
  20842. //printf(" File not found or unable to open the input file!!\n");
  20843. return ;
  20844. }
  20845. ch=fgetc(fptr1);
  20846. //printf(" Now the content of the file %s is : \n",fname);
  20847. rewind(fptr1);
  20848. if(ch!=EOF)
  20849. {
  20850. // copy all contents to the temporary file except the specific line
  20851. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  20852. {
  20853. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  20854. if(str[0]=='\0')
  20855. {
  20856. break;
  20857. }
  20858. //TempStopTransaction格式: 槍號,StopTransaction封包
  20859. strncpy(connectorStr, str, 1);
  20860. if(atoi(connectorStr) != (gun_index+1))
  20861. {
  20862. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  20863. fclose(fptr1);
  20864. return ;
  20865. }
  20866. //random_uuid(guid);
  20867. strncpy(guid, str+6, 36); //copy guid
  20868. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  20869. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  20870. {
  20871. //DEBUG_INFO("StopTransaction mapitem pass\n");
  20872. }
  20873. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  20874. OCPP_insert_transaction_msg(NO, str);
  20875. memset(str,0,ARRAY_SIZE(str));
  20876. }
  20877. }
  20878. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  20879. fclose(fptr1);
  20880. remove(TempStopTransaction); // remove the original file
  20881. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  20882. }
  20883. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  20884. {
  20885. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  20886. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  20887. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  20888. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  20889. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  20890. }
  20891. void FillTransactionId(int ConnectorId, int TransactionId)
  20892. {
  20893. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  20894. ShmOCPP16Data->StartTransaction[ConnectorId-1].ResponseTransactionId = TransactionId;
  20895. }
  20896. int GetWebSocketPingInterval(void)
  20897. {
  20898. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  20899. }
  20900. int GetServerSign(void)
  20901. {
  20902. return server_sign;
  20903. }
  20904. uint8_t GetOcppSecurityProfile()
  20905. {
  20906. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  20907. }
  20908. void MergeCertificates()
  20909. {
  20910. char cmdBuf[2048]={0};
  20911. if(access(ROOTCA_CS,F_OK) != -1)
  20912. {
  20913. sprintf(cmdBuf, "cat /root/cacert.pem %s > /root/certCA.pem", ROOTCA_CS);
  20914. }
  20915. else
  20916. {
  20917. sprintf(cmdBuf, "cat /root/cacert.pem > /root/certCA.pem");
  20918. }
  20919. system(cmdBuf);
  20920. }
  20921. void GetOcppChargerBoxId(uint8_t *data)
  20922. {
  20923. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  20924. }
  20925. void GetOcppSecurityPassword(uint8_t *data)
  20926. {
  20927. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  20928. }
  20929. void SetOcppVersion(uint8_t *version)
  20930. {
  20931. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  20932. DEBUG_INFO("ocpp version: %s\n", version);
  20933. if(strstr((char*)version, "ocpp1.6") != NULL)
  20934. {
  20935. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  20936. }
  20937. else if(strstr((char*)version, "ocpp2.0") != NULL)
  20938. {
  20939. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  20940. system("pkill OcppBackend");
  20941. }
  20942. }
  20943. void SetServerSign(int value)
  20944. {
  20945. server_sign = value;
  20946. }
  20947. int GetBootNotificationInterval(void)
  20948. {
  20949. return BootNotificationInterval;
  20950. }
  20951. int GetInternetConn(void)
  20952. {
  20953. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  20954. }
  20955. int GetBackendConnectionTimeout(void)
  20956. {
  20957. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  20958. }
  20959. int isConnectorInitMode(int gun_index)
  20960. {
  20961. int tempIndex = 0;
  20962. int result = TRUE;
  20963. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  20964. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20965. {
  20966. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20967. {
  20968. tempIndex = ((gun_index==2) ? 1: 0);
  20969. }
  20970. else
  20971. {
  20972. tempIndex = gun_index;
  20973. }
  20974. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20975. {
  20976. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  20977. {
  20978. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20979. } //end of the same index
  20980. }//end of for CHAdeMO_QUANTITY
  20981. }
  20982. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20983. {
  20984. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20985. {
  20986. tempIndex = ((gun_index==2) ? 1: 0);
  20987. }
  20988. else
  20989. {
  20990. tempIndex = gun_index;
  20991. }
  20992. for (int index = 0; index < CCS_QUANTITY; index++)
  20993. {
  20994. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20995. {
  20996. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20997. } //end of the same index
  20998. } // end of for CCS_QUANTITY
  20999. }
  21000. else if(gunType[gun_index] == GUN_TYPE_GBT)
  21001. {
  21002. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  21003. {
  21004. tempIndex = ((gun_index==2) ? 1: 0);
  21005. }
  21006. else
  21007. {
  21008. tempIndex = gun_index;
  21009. }
  21010. for (int index = 0; index < GB_QUANTITY; index++)
  21011. {
  21012. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  21013. {
  21014. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  21015. } //end of the same index
  21016. } // end of for GB_QUANTITY
  21017. }
  21018. else if(gunType[gun_index] == GUN_TYPE_DO)
  21019. {
  21020. tempIndex = gun_index;
  21021. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  21022. {
  21023. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  21024. {
  21025. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  21026. } //end of the same index
  21027. }
  21028. }
  21029. else
  21030. {
  21031. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  21032. {
  21033. tempIndex = 2;
  21034. }
  21035. else
  21036. {
  21037. tempIndex = gun_index;
  21038. }
  21039. for (int index = 0; index < AC_QUANTITY; index++)
  21040. {
  21041. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  21042. {
  21043. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  21044. }//end of the same index
  21045. }//end of for AC_QUANTITY
  21046. }
  21047. return result;
  21048. }
  21049. void refreshProcDogTimer()
  21050. {
  21051. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  21052. }
  21053. void InitialSystemValue(void)
  21054. {
  21055. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  21056. locallistVersion=0;
  21057. BootNotificationInterval = 0;
  21058. authorizeRetryTimes = 0;
  21059. GunStatusInterval = 10;
  21060. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  21061. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  21062. //Hear Beat
  21063. HeartBeatWithNOResponse = 0;
  21064. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  21065. FirstHeartBeat = 0;
  21066. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  21067. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  21068. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  21069. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  21070. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  21071. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  21072. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  21073. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  21074. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  21075. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  21076. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  21077. //Status && ConnectorPlugIn Setting
  21078. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  21079. {
  21080. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  21081. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  21082. }
  21083. for (int index = 0; index < CCS_QUANTITY; index++)
  21084. {
  21085. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  21086. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  21087. }
  21088. for (int index = 0; index < GB_QUANTITY; index++)
  21089. {
  21090. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  21091. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  21092. }
  21093. for (int index = 0; index < AC_QUANTITY; index++)
  21094. {
  21095. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  21096. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  21097. }
  21098. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  21099. {
  21100. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  21101. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  21102. }
  21103. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  21104. {
  21105. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  21106. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  21107. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  21108. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  21109. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  21110. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  21111. }
  21112. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  21113. refreshStartTimer(&clientTime.Heartbeat);
  21114. sleep(1);
  21115. }
  21116. void LWS_Send(char *str)
  21117. {
  21118. //=====================================================
  21119. // Check InternetConn 0: disconnected, 1: connected
  21120. //====================================================
  21121. if(GetOcppConnStatus() == 0)
  21122. {
  21123. DEBUG_INFO("offline now !!!\n");
  21124. return;
  21125. }
  21126. // Only disable isWebsocketSendable operation initiated by charger
  21127. if((strstr((char*)str, "\"Authorize\"") != NULL)
  21128. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  21129. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  21130. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  21131. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  21132. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  21133. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  21134. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  21135. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  21136. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  21137. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  21138. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  21139. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  21140. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  21141. {
  21142. isWebsocketSendable = 0;
  21143. }
  21144. pthread_mutex_lock(&lock_send);
  21145. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  21146. sprintf((char *)SendBuffer, "%s", str);
  21147. SendBufLen = strlen(str);
  21148. pthread_mutex_unlock(&lock_send);
  21149. lws_callback_on_writable(wsi_client);
  21150. //lws_service(context, 0);
  21151. //sleep(1);
  21152. }
  21153. void LWS_SendNow(char *str)
  21154. {
  21155. //=====================================================
  21156. // Check InternetConn 0: disconnected, 1: connected
  21157. //====================================================
  21158. if(GetOcppConnStatus() == 0)
  21159. {
  21160. DEBUG_INFO("offline now !!!\n");
  21161. return;
  21162. }
  21163. // Only disable isWebsocketSendable operation initiated by charger
  21164. if((strstr((char*)str, "\"Authorize\"") != NULL)
  21165. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  21166. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  21167. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  21168. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  21169. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  21170. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  21171. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  21172. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  21173. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  21174. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  21175. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  21176. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  21177. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  21178. {
  21179. isWebsocketSendable = 0;
  21180. }
  21181. pthread_mutex_lock(&lock_send);
  21182. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  21183. sprintf((char *)SendBuffer, "%s", str);
  21184. SendBufLen = strlen(str);
  21185. pthread_mutex_unlock(&lock_send);
  21186. lws_callback_on_writable(wsi_client);
  21187. lws_service(context, 0);
  21188. //sleep(1);
  21189. }