MessageHandler.c 1.0 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static ParsingRatedCur modelnameInfo = {0};
  28. static int gunTotalNumber = 0;
  29. static uint8_t gunType[4] = {0};
  30. //===============================
  31. // Local List Version
  32. //===============================
  33. static int locallistVersion=0;
  34. static char idTagAuthorization[32] = {0};
  35. //===============================
  36. // OCPP sign variable
  37. //===============================
  38. static int server_sign = FALSE;
  39. int server_pending = FALSE;
  40. static int BootNotificationInterval = 0;
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = FALSE;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  54. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  55. //========================================
  56. // OCPP status/previous related variables
  57. //========================================
  58. static int GunStatusInterval = 10;
  59. static uint8_t Connector0PreviousSystemStatus;
  60. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  61. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  62. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  63. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  64. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  65. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  66. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  67. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  68. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  69. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  70. static int TransactionMessageAttemptsValue = 0;
  71. static int TransactionMessageRetryIntervalValue = 0;
  72. static int TempMeterValueInterval = 0;
  73. static struct OCPPAuthLocalElemet
  74. {
  75. int listVersionInt;
  76. char idTagstr[21];
  77. char parentIdTag[21];
  78. char expiryDate[36];
  79. char idTagstatus[16];
  80. }idTagQuery;
  81. //============================================
  82. // OCPP MeterValue request flag
  83. //============================================
  84. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  85. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  86. //============================================
  87. // OCPP HeartBeat Response Not Receive Counts
  88. //============================================
  89. static int HeartBeatWithNOResponse = 0;
  90. //============================================
  91. // OCPP California Pricing Requirements
  92. //============================================
  93. static char dmsVersion[21] = {0};
  94. extern sqlite3 *db;
  95. int TransactionMessageAttemptsGet(void);
  96. int TransactionMessageRetryIntervalGet(void);
  97. int GetOcppConnStatus(void);
  98. void SetOcppConnStatus(uint8_t status);
  99. int setKeyValue(char *key, char *value);
  100. void OCPP_get_TableAuthlocalAllData(void);
  101. void processUnkownKey(void);
  102. struct InterLock
  103. {
  104. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  105. unsigned char isGetDiagnosticGoing:1;
  106. unsigned char isUpdateFirmwareGoing:1;
  107. }interLock;
  108. struct ClientTime
  109. {
  110. struct timespec Heartbeat;
  111. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  112. struct timespec StartTransaction;
  113. struct timespec StopTransaction;
  114. struct timespec MeterValues[CONNECTOR_QUANTITY];
  115. struct timespec RemoteStartWait;
  116. struct timespec TcciQueryDeduct;
  117. struct timespec TcciQueryOccupancyDeduct;
  118. struct timespec CharingProfileRefresh[CONNECTOR_QUANTITY];
  119. }clientTime;
  120. typedef union
  121. {
  122. //Operations Initiated by Central System
  123. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  124. struct
  125. {
  126. //CsMsgValue[0]
  127. unsigned char StatusNotificationReq:1; //bit 0,
  128. unsigned char StatusNotificationConf:1; //bit 1,
  129. unsigned char TriggerMeterValue:1; //bit 2,
  130. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  131. unsigned char isOnCharging:1; //bit 4,
  132. unsigned char :3; //bit5~7
  133. }bits[CONNECTOR_QUANTITY];
  134. }CpinitiateMsg;
  135. CpinitiateMsg cpinitateMsg;
  136. //GetConfiguration Array
  137. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  138. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  139. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  140. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  141. static char *ChargePointErrorCodeStr[] = {
  142. MACROSTR(ConnectorLockFailure),
  143. MACROSTR(EVCommunicationError),
  144. MACROSTR(GroundFailure),
  145. MACROSTR(HighTemperature),
  146. MACROSTR(InternalError),
  147. MACROSTR(LocalListConflict),
  148. MACROSTR(NoError),
  149. MACROSTR(OtherError),
  150. MACROSTR(OverCurrentFailure),
  151. MACROSTR(OverVoltage),
  152. MACROSTR(PowerMeterFailure),
  153. MACROSTR(PowerSwitchFailure),
  154. MACROSTR(ReaderFailure),
  155. MACROSTR(ResetFailure),
  156. MACROSTR(UnderVoltage),
  157. MACROSTR(WeakSignal)
  158. };
  159. static char * ChargePointStatusStr[] = {
  160. MACROSTR(Available),
  161. MACROSTR(Preparing),
  162. MACROSTR(Charging),
  163. MACROSTR(SuspendedEVSE),
  164. MACROSTR(SuspendedEV),
  165. MACROSTR(Finishing),
  166. MACROSTR(Reserved),
  167. MACROSTR(Unavailable),
  168. MACROSTR(Faulted)
  169. };
  170. static char *RegistrationStatusStr[] = {
  171. MACROSTR(Accepted),
  172. MACROSTR(Pending),
  173. MACROSTR(Rejected)
  174. };
  175. static char *AvailabilityTypeStr[] = {
  176. MACROSTR(Inoperative),
  177. MACROSTR(Operative)
  178. };
  179. static char *AvailabilityStatusStr[] = {
  180. MACROSTR(Accepted),
  181. MACROSTR(Rejected),
  182. MACROSTR(Scheduled)
  183. };
  184. static char *ConfigurationStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected),
  187. MACROSTR(RebootRequired),
  188. MACROSTR(NotSupported)
  189. };
  190. static char *ClearCacheStatusStr[] = {
  191. MACROSTR(Accepted),
  192. MACROSTR(Rejected)
  193. };
  194. static char *ChargingProfilePurposeTypeStr[] = {
  195. MACROSTR(ChargePointMaxProfile),
  196. MACROSTR(TxDefaultProfile),
  197. MACROSTR(TxProfile)
  198. };
  199. static char *ChargingProfileStatusStr[] = {
  200. MACROSTR(Accepted),
  201. MACROSTR(Rejected),
  202. MACROSTR(NotSupported)
  203. };
  204. static char *ClearChargingProfileStatusStr[] = {
  205. MACROSTR(Accepted),
  206. MACROSTR(Unknown)
  207. };
  208. static char *GetCompositeScheduleStatusStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Rejected)
  211. };
  212. static char *UpdateTypeStr[] = {
  213. MACROSTR(Differential),
  214. MACROSTR(Full)
  215. };
  216. static char *UpdateStatusStr[] = {
  217. MACROSTR(Accepted),
  218. MACROSTR(Failed),
  219. MACROSTR(NotSupported),
  220. MACROSTR(VersionMismatch)
  221. };
  222. static char *RemoteStartStopStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Rejected)
  225. };
  226. static char *ReservationStatusStr[] = {
  227. MACROSTR(Accepted),
  228. MACROSTR(Faulted),
  229. MACROSTR(Occupied),
  230. MACROSTR(Rejected),
  231. MACROSTR(Unavailable)
  232. };
  233. static char *ResetTypeStr[] = {
  234. MACROSTR(Hard),
  235. MACROSTR(Soft)
  236. };
  237. static char *ResetStatusStr[] = {
  238. MACROSTR(Accepted),
  239. MACROSTR(Rejected)
  240. };
  241. static char * DiagnosticsStatusStr[] = {
  242. MACROSTR(Idle),
  243. MACROSTR(Uploaded),
  244. MACROSTR(UploadFailed),
  245. MACROSTR(Uploading)
  246. };
  247. static char * FirmwareStatusStr[] = {
  248. MACROSTR(Downloaded),
  249. MACROSTR(DownloadFailed),
  250. MACROSTR(Downloading),
  251. MACROSTR(Idle),
  252. MACROSTR(InstallationFailed),
  253. MACROSTR(Installing),
  254. MACROSTR(Installed)
  255. };
  256. static char * MessageTriggerStr[] = {
  257. MACROSTR(BootNotification),
  258. MACROSTR(DiagnosticsStatusNotification),
  259. MACROSTR(FirmwareStatusNotification),
  260. MACROSTR(Heartbeat),
  261. MACROSTR(MeterValues),
  262. MACROSTR(StatusNotification)
  263. };
  264. static char * TriggerMessageStatusStr[] = {
  265. MACROSTR(Accepted),
  266. MACROSTR(Rejected),
  267. MACROSTR(NotImplemented)
  268. };
  269. static char * UnlockStatusStr[] = {
  270. MACROSTR(Unlocked),
  271. MACROSTR(UnlockFailed),
  272. MACROSTR(NotSupported)
  273. };
  274. #if 0
  275. static char * StopTransactionReasonStr[] = {
  276. MACROSTR(EmergencyStop),
  277. MACROSTR(EVDisconnected),
  278. MACROSTR(HardReset),
  279. MACROSTR(Local),
  280. MACROSTR(Other),
  281. MACROSTR(PowerLoss),
  282. MACROSTR(Reboot),
  283. MACROSTR(Remote),
  284. MACROSTR(SoftReset),
  285. MACROSTR(UnlockCommand),
  286. MACROSTR(DeAuthorized)
  287. };
  288. #endif
  289. static char * CancelReservationStatusStr[] = {
  290. MACROSTR(Accepted),
  291. MACROSTR(Rejected)
  292. };
  293. static char * ReadingContextStr[] = {
  294. MACROSTR(Interruption.Begin),
  295. MACROSTR(Interruption.End),
  296. MACROSTR(Other),
  297. MACROSTR(Sample.Clock),
  298. MACROSTR(Sample.Periodic),
  299. MACROSTR(Transaction.Begin),
  300. MACROSTR(Transaction.End),
  301. MACROSTR(Trigger)
  302. };
  303. static char * ValueFormatStr[] = {
  304. MACROSTR(Raw),
  305. MACROSTR(SignedData)
  306. };
  307. static char * MeasurandStr[] = {
  308. MACROSTR(Current.Export),
  309. MACROSTR(Current.Import),
  310. MACROSTR(Current.Offered),
  311. MACROSTR(Energy.Active.Export.Register),
  312. MACROSTR(Energy.Active.Import.Register),
  313. MACROSTR(Energy.Reactive.Export.Register),
  314. MACROSTR(Energy.Reactive.Import.Register),
  315. MACROSTR(Energy.Active.Export.Interval),
  316. MACROSTR(Energy.Active.Import.Interval),
  317. MACROSTR(Energy.Reactive.Export.Interval),
  318. MACROSTR(Energy.Reactive.Import.Interval),
  319. MACROSTR(Frequency),
  320. MACROSTR(Power.Active.Export),
  321. MACROSTR(Power.Active.Import),
  322. MACROSTR(Power.Factor),
  323. MACROSTR(Power.Offered),
  324. MACROSTR(Power.Reactive.ExportMACROSTR),
  325. MACROSTR(Power.Reactive.Import),
  326. MACROSTR(RPM),
  327. MACROSTR(SoC),
  328. MACROSTR(Temperature),
  329. MACROSTR(Voltage)
  330. };
  331. static char * LocationStr[] = {
  332. MACROSTR(Body),
  333. MACROSTR(Cable),
  334. MACROSTR(EV),
  335. MACROSTR(Inlet),
  336. MACROSTR(Outlet)
  337. };
  338. static char * PhaseStr[] = {
  339. MACROSTR(L1),
  340. MACROSTR(L2),
  341. MACROSTR(L3),
  342. MACROSTR(N),
  343. MACROSTR(L1-N),
  344. MACROSTR(L2-N),
  345. MACROSTR(L3-N),
  346. MACROSTR(L1-L2),
  347. MACROSTR(L2-L3),
  348. MACROSTR(L3-L1)
  349. };
  350. static char * UnitOfMeasureStr[] = {
  351. MACROSTR(Wh),
  352. MACROSTR(kWh),
  353. MACROSTR(varh),
  354. MACROSTR(kvarh),
  355. MACROSTR(W),
  356. MACROSTR(kW),
  357. MACROSTR(VA),
  358. MACROSTR(kVA),
  359. MACROSTR(var),
  360. MACROSTR(kvar),
  361. MACROSTR(A),
  362. MACROSTR(V),
  363. MACROSTR(Celsius),
  364. MACROSTR(Fahrenheit),
  365. MACROSTR(K),
  366. MACROSTR(Percent)
  367. };
  368. //=========================================
  369. // Certificate related routine
  370. //=========================================
  371. int certVerify(char *privateKey, char *cert)
  372. {
  373. int result = PASS;
  374. SSL_CTX *ctx = SSL_CTX_new(TLS_method());
  375. // Load certificate file
  376. if(SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM) <= 0)
  377. {
  378. DEBUG_ERROR("Load certificate error!\n");
  379. result = FAIL;
  380. }
  381. // Load private key file
  382. if(SSL_CTX_use_PrivateKey_file(ctx, privateKey, SSL_FILETYPE_PEM) <= 0)
  383. {
  384. DEBUG_ERROR("Load private key error!\n");
  385. result = FAIL;
  386. }
  387. if(!SSL_CTX_check_private_key(ctx))
  388. {
  389. result = FAIL;
  390. }
  391. SSL_CTX_free(ctx);
  392. return result;
  393. }
  394. //=========================================
  395. // TTIA routine
  396. //=========================================
  397. int sendTTIAInfo(uint8_t gun_index)
  398. {
  399. static int sn = 0;
  400. int result = FAIL;
  401. struct hostent *server;
  402. int udp_socket_fd;
  403. struct sockaddr_in dest_addr = {0};
  404. uint8_t tx_buf[80] = {0};
  405. uint8_t logBuf[256]= {0};
  406. uint8_t tx_len, tempIndex, socStart, socEnd;
  407. uint16_t PresentChargedEnergy;
  408. struct tm tmStart, tmEnd;
  409. DEBUG_INFO("sendTTIAInfo...\n");
  410. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  411. {
  412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  413. {
  414. tempIndex = ((gun_index==2) ? 1: 0);
  415. }
  416. else
  417. {
  418. tempIndex = gun_index;
  419. }
  420. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  421. {
  422. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  423. {
  424. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  425. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  426. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  427. }
  428. }
  429. }
  430. else if(gunType[gun_index] == GUN_TYPE_CCS)
  431. {
  432. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  433. {
  434. tempIndex = ((gun_index==2) ? 1: 0);
  435. }
  436. else
  437. {
  438. tempIndex = gun_index;
  439. }
  440. for (int index = 0; index < CCS_QUANTITY; index++)
  441. {
  442. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  443. {
  444. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  445. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  446. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  447. }
  448. }
  449. }
  450. else if(gunType[gun_index] == GUN_TYPE_GBT)
  451. {
  452. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  453. {
  454. tempIndex = ((gun_index==2) ? 1: 0);
  455. }
  456. else
  457. {
  458. tempIndex = gun_index;
  459. }
  460. for (int index = 0; index < GB_QUANTITY; index++)
  461. {
  462. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  463. {
  464. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  465. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  466. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  467. }
  468. }
  469. }
  470. else if(gunType[gun_index] == GUN_TYPE_DO)
  471. {
  472. tempIndex = gun_index;
  473. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  474. {
  475. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  476. {
  477. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  478. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  479. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  480. }
  481. }
  482. }
  483. else
  484. {
  485. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  486. {
  487. tempIndex = 2;
  488. }
  489. else
  490. {
  491. tempIndex = gun_index;
  492. }
  493. for (int index = 0; index < AC_QUANTITY; index++)
  494. {
  495. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  496. {
  497. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  498. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  499. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  500. }
  501. }// END
  502. }
  503. // Message assembly
  504. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  505. tx_buf[4] = 0x02; // Protocol Version
  506. tx_buf[5] = 0xb0; // Message ID
  507. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  508. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  509. tx_buf[8] = 0x00; // CarID low byte
  510. tx_buf[9] = 0x00; // CarID high byte
  511. tx_buf[10] = 0x00; // ID Storage
  512. tx_buf[11] = 0x00; // Driver lowest byte
  513. tx_buf[12] = 0x00; // Driver 2nd byte
  514. tx_buf[13] = 0x00; // Driver 3rd byte
  515. tx_buf[14] = 0x00; // Driver highest byte
  516. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  517. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  518. tx_buf[17] = 0x00; // Reserve
  519. tx_buf[18] = 60 & 0xff; // Payload length low byte
  520. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  521. // EVSE provider
  522. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  523. // EVSE provider
  524. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  525. // EVSE id
  526. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  527. // Connector id
  528. tx_buf[37] = gun_index;
  529. // EVSE station
  530. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  531. // Vehicle SN
  532. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  533. // Mileage
  534. tx_buf[61] = 0x00; // lowest byte
  535. tx_buf[62] = 0x00; // 2nd byte
  536. tx_buf[63] = 0x00; // highest byte
  537. // Start date time 6 bytes
  538. 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))
  539. {
  540. struct tm *tmTarget;
  541. struct timeb tbTarget;
  542. tmStart.tm_year -= 1900;
  543. tmStart.tm_mon -= 1;
  544. tmStart.tm_gmtoff = 0;
  545. tbTarget.time = mktime(&tmStart);
  546. tbTarget.timezone = 0;
  547. tbTarget.time += (8*3600);
  548. tmTarget = gmtime(&tbTarget.time);
  549. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  550. tx_buf[65] = (tmTarget->tm_mon+1);
  551. tx_buf[66] = tmTarget->tm_mday;
  552. tx_buf[67] = tmTarget->tm_hour;
  553. tx_buf[68] = tmTarget->tm_min;
  554. tx_buf[69] = tmTarget->tm_sec;
  555. }
  556. // Stop date time 6 bytes
  557. 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))
  558. {
  559. struct tm *tmTarget;
  560. struct timeb tbTarget;
  561. tmEnd.tm_year -= 1900;
  562. tmEnd.tm_mon -= 1;
  563. tmEnd.tm_gmtoff = 0;
  564. tbTarget.time = mktime(&tmEnd);
  565. tbTarget.timezone = 0;
  566. tbTarget.time += (8*3600);
  567. tmTarget = gmtime(&tbTarget.time);
  568. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  569. tx_buf[71] = (tmTarget->tm_mon+1);
  570. tx_buf[72] = tmTarget->tm_mday;
  571. tx_buf[73] = tmTarget->tm_hour;
  572. tx_buf[74] = tmTarget->tm_min;
  573. tx_buf[75] = tmTarget->tm_sec;
  574. }
  575. // Session energy 2 bytes
  576. tx_buf[76] = PresentChargedEnergy & 0xff;
  577. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  578. // Start SOC 1 byte
  579. tx_buf[78] = socStart;
  580. // Stop SOC 1 byte
  581. tx_buf[79] = socEnd;
  582. // Open socket
  583. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  584. if(udp_socket_fd == -1)
  585. {
  586. DEBUG_ERROR("UDP socket create failed!\n");
  587. }
  588. else
  589. {
  590. // Get server DNS entry
  591. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  592. if (server == NULL)
  593. {
  594. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  595. }
  596. else
  597. {
  598. // Build the server's Internet address
  599. bzero((char *) &dest_addr, sizeof(dest_addr));
  600. dest_addr.sin_family = AF_INET;
  601. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  602. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  603. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  604. {
  605. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  606. {
  607. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  608. }
  609. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  610. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  611. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  612. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  613. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  614. DEBUG_TTIA_INFO("---------- Header ----------\n");
  615. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  616. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  617. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  618. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  619. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  620. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  621. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  622. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  623. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  624. DEBUG_TTIA_INFO("Len: 0x3C\n");
  625. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  626. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  627. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  628. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  629. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  630. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  631. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  632. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  633. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  634. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  635. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  636. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  637. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  638. DEBUG_TTIA_INFO("=========================================\n");
  639. sn++;
  640. result = PASS;
  641. }
  642. else
  643. {
  644. DEBUG_ERROR("UDP sent out fail.\n");
  645. }
  646. }
  647. }
  648. return result;
  649. }
  650. //=========================================
  651. // Save configuration
  652. //=========================================
  653. int runShellCmd(const char*cmd)
  654. {
  655. int result = FAIL;
  656. char buf[256];
  657. FILE *fp;
  658. fp = popen(cmd, "r");
  659. if(fp != NULL)
  660. {
  661. while(fgets(buf, sizeof(buf), fp) != NULL)
  662. {
  663. DEBUG_INFO("%s\n", buf);
  664. }
  665. result = PASS;
  666. }
  667. pclose(fp);
  668. return result;
  669. }
  670. int StoreUsrConfigData(struct SysConfigData *UsrData)
  671. {
  672. int result = PASS;
  673. int fd,wrd;
  674. unsigned int i,Chk;
  675. unsigned char *ptr, *BufTmp;
  676. int MtdBlockSize = 0x300000;
  677. Chk=0;
  678. ptr=(unsigned char *)UsrData;
  679. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  680. {
  681. memset(BufTmp,0,MtdBlockSize);
  682. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  683. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  684. Chk+=*(BufTmp+i);
  685. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  686. // Output configuration to file.
  687. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  688. if (fd < 0)
  689. {
  690. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  691. free(BufTmp);
  692. return 0;
  693. }
  694. wrd=write(fd, BufTmp, MtdBlockSize);
  695. close(fd);
  696. if(wrd<MtdBlockSize)
  697. {
  698. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  699. free(BufTmp);
  700. return 0;
  701. }
  702. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  703. DEBUG_INFO("Erase /dev/mtd10.\n");
  704. runShellCmd("flash_erase /dev/mtd10 0 0");
  705. DEBUG_INFO("Write /dev/mtd10.\n");
  706. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  707. DEBUG_INFO("Erase /dev/mtd11.\n");
  708. runShellCmd("flash_erase /dev/mtd11 0 0");
  709. DEBUG_INFO("Write /dev/mtd11.\n");
  710. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  711. system("rm -f /mnt/EvseConfig.bin");
  712. DEBUG_INFO("EvseConfig write to flash OK\n");
  713. }
  714. else
  715. {
  716. DEBUG_ERROR("alloc BlockSize NG\r\n");
  717. result = FAIL;
  718. }
  719. if(BufTmp!=NULL)
  720. free(BufTmp);
  721. return result;
  722. }
  723. //=========================================
  724. // Sqlite3 related function
  725. //=========================================
  726. static int selectSqlCount = 0;
  727. static int callback(void *data, int argc, char **argv, char **azColName){
  728. int i;
  729. //printf("%s: ", (const char*)data);
  730. selectSqlCount = argc;
  731. for(i = 0; i<argc; i++){
  732. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  733. }
  734. //printf("\n");
  735. return 0;
  736. }
  737. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  738. //int i;
  739. //printf("%s:\n", (const char*)data);
  740. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  741. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  742. return 0;
  743. }
  744. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  745. //printf("%s:\n", (const char*)data);
  746. //idTag
  747. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  748. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  749. //parentIdTag
  750. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  751. //expir_date
  752. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  753. //status
  754. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  755. //version
  756. if(columenCount > 5)
  757. idTagQuery.listVersionInt = atoi(columnValue[5]);
  758. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  759. return 0;
  760. }
  761. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  762. {
  763. // localversion = argv[5] ? atoi(argv[5]) : 0;
  764. // printf("localversion=%d\n", localversion);
  765. return 0;
  766. }
  767. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  768. {
  769. for (int i = 0; i < n_columns; i++)
  770. {
  771. DEBUG_INFO("%s\t", col_values[i]);
  772. }
  773. DEBUG_INFO("\n");
  774. return 0;
  775. }
  776. int OCPP_cleanLocalCache()
  777. {
  778. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  779. char *errMsg = 0;
  780. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  781. if (SQLITE_OK != rc)
  782. {
  783. DEBUG_INFO("SQL error: %s\n",errMsg);
  784. return FALSE;
  785. }
  786. return TRUE;
  787. }
  788. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  789. {
  790. int isSuccess = TRUE;
  791. int ret = 0;
  792. //const char* data = "Callback function called";
  793. char sql[300];
  794. char zErrMsg[200];
  795. memset(sql, 0, 300);
  796. memset(zErrMsg, 0, 200);
  797. 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);
  798. //* Execute SQL statement */
  799. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  800. if( ret != SQLITE_OK )
  801. {
  802. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  803. isSuccess = FALSE;
  804. }
  805. return isSuccess;
  806. }
  807. void OCPP_getIdTagFromLocalCache(char idTag[])
  808. {
  809. int rc = 0;
  810. char sql[100];
  811. char zErrMsg[100];
  812. memset(sql, 0, 100);
  813. memset(zErrMsg, 0, 100);
  814. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  815. memset(&idTagQuery, 0, sizeof(idTagQuery));
  816. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  817. /* Execute SQL statement */
  818. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  819. if( rc != SQLITE_OK )
  820. {
  821. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  822. }
  823. }
  824. void OCPP_getListVerion()
  825. {
  826. int rc = 0;
  827. // const char* data = "Callback function called";
  828. char sql[100];
  829. char zErrMsg[100];
  830. memset(sql, 0, 100);
  831. memset(zErrMsg, 0, 100);
  832. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  833. /* Execute SQL statement */
  834. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  835. if( rc != SQLITE_OK )
  836. {
  837. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  838. }
  839. }
  840. void OCPP_get_TableAuthlocalAllData(void)
  841. {
  842. int rc = 0;
  843. char sql[100];
  844. char zErrMsg[100];
  845. memset(sql, 0, 100);
  846. memset(zErrMsg, 0, 100);
  847. sprintf(sql,"select * from ocpp_auth_local ");
  848. /* Execute SQL statement */
  849. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  850. if( rc != SQLITE_OK )
  851. {
  852. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  853. }
  854. //return ver;
  855. }
  856. int OCPP_cleanLocalList()
  857. {
  858. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  859. char *errMsg = 0;
  860. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  861. if (SQLITE_OK != rc)
  862. {
  863. DEBUG_INFO("%s\n",errMsg);
  864. return FALSE;
  865. }
  866. return TRUE;
  867. }
  868. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  869. {
  870. int isSuccess = FALSE;
  871. int ret = 0;
  872. //const char* data = "Callback function called";
  873. char sql[300];
  874. char zErrMsg[200];
  875. memset(sql, 0, 300);
  876. memset(zErrMsg, 0, 200);
  877. 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);
  878. //* Execute SQL statement */
  879. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  880. if( ret != SQLITE_OK )
  881. {
  882. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  883. return isSuccess;
  884. }
  885. memset(sql, 0, 300);
  886. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  887. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  888. if( ret != SQLITE_OK )
  889. {
  890. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  891. return isSuccess;
  892. }
  893. isSuccess = TRUE;
  894. return isSuccess;
  895. }
  896. void OCPP_getIdTagFromLocalList(char idTag[])
  897. {
  898. int rc = 0;
  899. // const char* data = "Callback function called";
  900. char sql[100];
  901. char zErrMsg[100];
  902. memset(sql, 0, 100);
  903. memset(zErrMsg, 0, 100);
  904. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  905. memset(&idTagQuery, 0, sizeof(idTagQuery));
  906. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  907. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  908. /* Execute SQL statement */
  909. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  910. if( rc != SQLITE_OK )
  911. {
  912. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  913. }
  914. //return ver;
  915. }
  916. void OCPP_deleteIdTagFromLocalList(char idTag[])
  917. {
  918. //int ver = 0;
  919. //int isSuccess = FALSE;
  920. int rc = 0;
  921. char sql[100];
  922. char zErrMsg[100];
  923. memset(sql, 0, 100);
  924. memset(zErrMsg, 0, 100);
  925. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  926. //* Execute SQL statement */
  927. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  928. if( rc != SQLITE_OK )
  929. {
  930. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  931. }
  932. }
  933. int getCurrentYear()
  934. {
  935. int result = 0;
  936. time_t CurrentTime;
  937. struct tm *tm;
  938. CurrentTime = time(NULL);
  939. tm=localtime(&CurrentTime);
  940. result = (tm->tm_year + 1900);
  941. return result;
  942. }
  943. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  944. {
  945. int result = PASS;
  946. char* errMsg = NULL;
  947. char sqlStr[8192];
  948. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  949. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  950. {
  951. result = FAIL;
  952. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  953. }
  954. 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));
  955. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  956. {
  957. result = FAIL;
  958. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  959. }
  960. return result;
  961. }
  962. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  963. {
  964. int isSuccess = TRUE;
  965. int tempIndex;
  966. json_object *EnergyDataTransfer = json_object_new_object();
  967. json_object *periodEnergys = json_object_new_object();
  968. char sql[1024];
  969. char zErrMsg[200];
  970. memset(sql, 0, ARRAY_SIZE(sql));
  971. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  972. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  973. {
  974. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  975. {
  976. tempIndex = ((gun_index==2) ? 1: 0);
  977. }
  978. else
  979. {
  980. tempIndex = gun_index;
  981. }
  982. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  983. {
  984. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  985. {
  986. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  987. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  988. {
  989. uint8_t period[3];
  990. sprintf((char*)period, "%d", idxPeriod);
  991. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  992. }
  993. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  994. } //end of the same index
  995. }//end of for CHAdeMO_QUANTITY
  996. }
  997. else if(gunType[gun_index] == GUN_TYPE_CCS)
  998. {
  999. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1000. {
  1001. tempIndex = ((gun_index==2) ? 1: 0);
  1002. }
  1003. else
  1004. {
  1005. tempIndex = gun_index;
  1006. }
  1007. for (int index = 0; index < CCS_QUANTITY; index++)
  1008. {
  1009. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1010. {
  1011. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1012. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1013. {
  1014. uint8_t period[3];
  1015. sprintf((char*)period, "%d", idxPeriod);
  1016. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1017. }
  1018. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1019. } //end of the same index
  1020. } // end of for CCS_QUANTITY
  1021. }
  1022. else if(gunType[gun_index] == GUN_TYPE_GBT)
  1023. {
  1024. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1025. {
  1026. tempIndex = ((gun_index==2) ? 1: 0);
  1027. }
  1028. else
  1029. {
  1030. tempIndex = gun_index;
  1031. }
  1032. for (int index = 0; index < GB_QUANTITY; index++)
  1033. {
  1034. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1035. {
  1036. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1037. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1038. {
  1039. uint8_t period[3];
  1040. sprintf((char*)period, "%d", idxPeriod);
  1041. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1042. }
  1043. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1044. } //end of the same index
  1045. } // end of for GB_QUANTITY
  1046. }
  1047. else if(gunType[gun_index] == GUN_TYPE_DO)
  1048. {
  1049. tempIndex = gun_index;
  1050. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1051. {
  1052. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1053. {
  1054. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1055. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1056. {
  1057. uint8_t period[3];
  1058. sprintf((char*)period, "%d", idxPeriod);
  1059. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1060. }
  1061. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1062. } //end of the same index
  1063. }
  1064. }
  1065. else
  1066. {
  1067. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1068. {
  1069. tempIndex = 2;
  1070. }
  1071. else
  1072. {
  1073. tempIndex = gun_index;
  1074. }
  1075. for (int index = 0; index < AC_QUANTITY; index++)
  1076. {
  1077. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1078. {
  1079. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1080. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1081. {
  1082. uint8_t period[3];
  1083. sprintf((char*)period, "%d", idxPeriod);
  1084. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1085. }
  1086. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1087. }//end of the same index
  1088. }//end of for AC_QUANTITY
  1089. }
  1090. 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));
  1091. json_object_put(EnergyDataTransfer);
  1092. //* Execute SQL statement */
  1093. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1094. {
  1095. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1096. isSuccess = FALSE;
  1097. }
  1098. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1099. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1100. {
  1101. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1102. isSuccess = FALSE;
  1103. }
  1104. return isSuccess;
  1105. }
  1106. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1107. {
  1108. int isSuccess = TRUE;
  1109. char sql[512];
  1110. char zErrMsg[200];
  1111. int rows, cols;
  1112. char **resultData;
  1113. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1114. /* Execute SQL statement */
  1115. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1116. {
  1117. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1118. isSuccess = FALSE;
  1119. }
  1120. else
  1121. {
  1122. if((rows > 0) && (atoi(resultData[4]) > 0))
  1123. {
  1124. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1125. }
  1126. else
  1127. {
  1128. DEBUG_WARN("There is not match transaction data.\n");
  1129. isSuccess = FALSE;
  1130. }
  1131. }
  1132. return isSuccess;
  1133. }
  1134. 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)
  1135. {
  1136. int result = PASS;
  1137. char* errMsg = NULL;
  1138. char sqlStr[8192];
  1139. 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');",
  1140. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1141. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1142. {
  1143. result = FAIL;
  1144. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1145. }
  1146. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1147. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1148. {
  1149. result = FAIL;
  1150. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1151. }
  1152. return result;
  1153. }
  1154. int OCPP_update_deduct_info(int txId, char *creditNo)
  1155. {
  1156. int result = PASS;
  1157. char* errMsg = NULL;
  1158. char sqlStr[8192];
  1159. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1160. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1161. {
  1162. result = FAIL;
  1163. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1164. }
  1165. return result;
  1166. }
  1167. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1168. {
  1169. json_object *dataBuf = json_object_new_object();
  1170. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1171. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1172. json_object_object_add(dataBuf, "txId", json_object_new_int(atoi(columnValue[1])));
  1173. json_object_object_add(dataBuf, "creditNo", json_object_new_string(columnValue[2]));
  1174. json_object_object_add(dataBuf, "deductResult", json_object_new_boolean(atoi(columnValue[3])));
  1175. json_object_object_add(dataBuf, "isDonateInvoice", json_object_new_boolean(atoi(columnValue[4])));
  1176. json_object_object_add(dataBuf, "amount", json_object_new_double(atof(columnValue[5])));
  1177. json_object_object_add(dataBuf, "approvalNo", json_object_new_string(columnValue[9]));
  1178. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1179. json_object_put(dataBuf);
  1180. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1181. return 0;
  1182. }
  1183. void OCPP_query_deduct_info()
  1184. {
  1185. int rc = 0;
  1186. char sql[100];
  1187. char zErrMsg[100];
  1188. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1189. /* Execute SQL statement */
  1190. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1191. if( rc != SQLITE_OK )
  1192. {
  1193. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1194. }
  1195. }
  1196. // Occupancy fee deduct queue process
  1197. int OCPP_insert_occupancyDeduct_info(char *occupancySN, char *creditNo, uint8_t deductResult, double amount, char *approvalNo)
  1198. {
  1199. int result = PASS;
  1200. char* errMsg = NULL;
  1201. char sqlStr[8192];
  1202. sprintf(sqlStr, "insert or replace into report_occupancyDeduct_info(occupancySN, creditNo, deductResult, amount, approvalNo, isUploaded) values('%s', '%s', '%d', '%.2f', '%s', '0');",
  1203. occupancySN, creditNo, deductResult, amount, approvalNo);
  1204. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1205. {
  1206. result = FAIL;
  1207. DEBUG_WARN( "Insert local report_occupancyDeduct_info error message: %s\n", errMsg);
  1208. }
  1209. sprintf(sqlStr, "delete from report_occupancyDeduct_info where (idx < (select idx from report_occupancyDeduct_info order by idx desc limit 1)-5000);");
  1210. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1211. {
  1212. result = FAIL;
  1213. DEBUG_WARN( "delete local report_occupancyDeduct_info error message: %s\n", errMsg);
  1214. }
  1215. return result;
  1216. }
  1217. int OCPP_update_occupancyDeduct_info(char *occupancySN)
  1218. {
  1219. int result = PASS;
  1220. char* errMsg = NULL;
  1221. char sqlStr[8192];
  1222. sprintf(sqlStr, "update report_occupancyDeduct_info set isUploaded='1' where occupancySN='%s';", occupancySN);
  1223. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1224. {
  1225. result = FAIL;
  1226. DEBUG_WARN( "Update local report_occupancyDeduct_info error message: %s\n", errMsg);
  1227. }
  1228. return result;
  1229. }
  1230. int queryOccupancyDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1231. {
  1232. json_object *dataBuf = json_object_new_object();
  1233. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1234. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_OccupancyDeductResult");
  1235. json_object_object_add(dataBuf, "occupancySN", json_object_new_string(columnValue[1]));
  1236. json_object_object_add(dataBuf, "creditNo", json_object_new_string(columnValue[2]));
  1237. json_object_object_add(dataBuf, "deductResult", json_object_new_boolean(atoi(columnValue[3])));
  1238. json_object_object_add(dataBuf, "amount", json_object_new_double(atof(columnValue[4])));
  1239. json_object_object_add(dataBuf, "approvalNo", json_object_new_string(columnValue[5]));
  1240. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1241. json_object_put(dataBuf);
  1242. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1243. return 0;
  1244. }
  1245. void OCPP_query_occupancyDeduct_info()
  1246. {
  1247. int rc = 0;
  1248. char sql[100];
  1249. char zErrMsg[100];
  1250. sprintf(sql,"select * from report_occupancyDeduct_info where isUploaded='0' order by idx limit 1");
  1251. /* Execute SQL statement */
  1252. rc = sqlite3_exec(db, sql, queryOccupancyDeductCallBack, 0, (char **)&zErrMsg);
  1253. if( rc != SQLITE_OK )
  1254. {
  1255. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1256. }
  1257. }
  1258. void reportReaderStatus(int gun_index)
  1259. {
  1260. struct timeval tmnow;
  1261. struct tm *tm;
  1262. char buf[28];//, usec_buf[6];
  1263. gettimeofday(&tmnow, NULL);
  1264. time_t t;
  1265. t = time(NULL);
  1266. /*UTC time and date*/
  1267. tm = gmtime(&t);
  1268. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1269. #if 0 // remove temporally
  1270. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1271. strcat(buf,".");
  1272. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1273. strcat(buf,usec_buf);
  1274. #endif
  1275. json_object *dataBuf = json_object_new_object();
  1276. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1277. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_ReaderStatus");
  1278. json_object_object_add(dataBuf, "ConnectorId", json_object_new_int((gun_index+1)));
  1279. json_object_object_add(dataBuf, "readerStatus", json_object_new_int(ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus));
  1280. json_object_object_add(dataBuf, "timestamp", json_object_new_string(buf));
  1281. json_object_object_add(dataBuf, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  1282. json_object_object_add(dataBuf, "creditNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo));
  1283. json_object_object_add(dataBuf, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  1284. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1285. json_object_put(dataBuf);
  1286. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1287. }
  1288. void getOccupancyFee(int gun_index)
  1289. {
  1290. struct timeval tmnow;
  1291. struct tm *tm;
  1292. char buf[28];//, usec_buf[6];
  1293. gettimeofday(&tmnow, NULL);
  1294. time_t t;
  1295. t = time(NULL);
  1296. /*UTC time and date*/
  1297. tm = gmtime(&t);
  1298. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1299. #if 0 // remove temporally
  1300. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1301. strcat(buf,".");
  1302. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1303. strcat(buf,usec_buf);
  1304. #endif
  1305. json_object *dataBuf = json_object_new_object();
  1306. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1307. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_GetOccupancyFee");
  1308. json_object_object_add(dataBuf, "ConnectorId", json_object_new_int((gun_index+1)));
  1309. json_object_object_add(dataBuf, "occupancySN", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.GetOccupancyFee[gun_index].occupancySN));
  1310. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1311. json_object_put(dataBuf);
  1312. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1313. }
  1314. //==========================================
  1315. // Check time passed since today
  1316. //==========================================
  1317. long long DiffTimebWithNow(struct timeb ST)
  1318. {
  1319. //return milli-second
  1320. struct timeb ET;
  1321. long long StartTime,StopTime;
  1322. ftime(&ET);
  1323. StartTime=(long long)ST.time;
  1324. StopTime=(long long)ET.time;
  1325. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1326. }
  1327. int getTimePassSinceToday(uint8_t gun_index)
  1328. {
  1329. int result = -1;
  1330. static time_t lastTime[4];
  1331. time_t t;
  1332. struct tm *tmStartToday;
  1333. struct timeb tbStartToday;
  1334. t=time(NULL);
  1335. if(difftime(t, lastTime[gun_index])>0)
  1336. {
  1337. tmStartToday=localtime(&t);
  1338. tmStartToday->tm_hour = 0;
  1339. tmStartToday->tm_min = 0;
  1340. tmStartToday->tm_sec = 0;
  1341. tbStartToday.time = mktime(tmStartToday);
  1342. tbStartToday.millitm = 0;
  1343. result = DiffTimebWithNow(tbStartToday)/1000;
  1344. lastTime[gun_index] = t;
  1345. }
  1346. return result;
  1347. }
  1348. void getNowDatetime(uint8_t *data)
  1349. {
  1350. time_t t = time(NULL);
  1351. struct tm tm = *localtime(&t);
  1352. 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);
  1353. }
  1354. int syncDateTimeRTC(uint8_t *data)
  1355. {
  1356. struct ParsingResult
  1357. {
  1358. int result;
  1359. int scanedElement;
  1360. int year;
  1361. int month;
  1362. int mday;
  1363. int hour;
  1364. int min;
  1365. int sec;
  1366. int tz_hour;
  1367. int tz_min;
  1368. float minSec;
  1369. }result;
  1370. struct tm tmOrg;
  1371. struct tm *tmTarget;
  1372. struct timeb tbTarget;
  1373. char buf[128];
  1374. memset(&result, 0x00, sizeof(struct ParsingResult));
  1375. result.result = PASS;
  1376. if(strstr((char*)data, ".") != NULL)
  1377. {
  1378. // Original data with mini second
  1379. if(strstr((char*)data, "Z") != NULL)
  1380. {
  1381. // Original data with Z
  1382. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1383. &result.year,
  1384. &result.month,
  1385. &result.mday,
  1386. &result.hour,
  1387. &result.min,
  1388. &result.sec,
  1389. &result.minSec);
  1390. }
  1391. else
  1392. {
  1393. // Original data without Z
  1394. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1395. &result.year,
  1396. &result.month,
  1397. &result.mday,
  1398. &result.hour,
  1399. &result.min,
  1400. &result.sec,
  1401. &result.minSec,
  1402. &result.tz_hour,
  1403. &result.tz_min);
  1404. }
  1405. }
  1406. else
  1407. {
  1408. // Original data without mini second
  1409. if(strstr((char*)data, "Z") != NULL)
  1410. {
  1411. // Original data with Z
  1412. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1413. &result.year,
  1414. &result.month,
  1415. &result.mday,
  1416. &result.hour,
  1417. &result.min,
  1418. &result.sec);
  1419. }
  1420. else
  1421. {
  1422. // Original data without Z
  1423. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1424. &result.year,
  1425. &result.month,
  1426. &result.mday,
  1427. &result.hour,
  1428. &result.min,
  1429. &result.sec,
  1430. &result.tz_hour,
  1431. &result.tz_min);
  1432. }
  1433. }
  1434. tmOrg.tm_year = result.year - 1900;
  1435. tmOrg.tm_mon = result.month - 1;
  1436. tmOrg.tm_mday = result.mday;
  1437. tmOrg.tm_hour = result.hour;
  1438. tmOrg.tm_min = result.min;
  1439. tmOrg.tm_sec = result.sec;
  1440. tmOrg.tm_gmtoff = 0;
  1441. tbTarget.time = mktime(&tmOrg);
  1442. tbTarget.timezone = 0;
  1443. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1444. tmTarget = gmtime(&tbTarget.time);
  1445. 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);
  1446. //DEBUG_INFO(" org date time: %s\n", data);
  1447. //DEBUG_INFO("parse date time: %s\n", buf);
  1448. system(buf);
  1449. system("/sbin/hwclock -w --systohc");
  1450. if(result.scanedElement < 6)
  1451. result.result = FAIL;
  1452. return result.result;
  1453. }
  1454. //==========================================
  1455. // Parse certificate content
  1456. //==========================================
  1457. int parseCertInfo(char *certPath, int parseType, char *data)
  1458. {
  1459. int result = FAIL;
  1460. memset(data, 0, ARRAY_SIZE(data));
  1461. if(access(certPath,F_OK) != -1)
  1462. {
  1463. char temp[512] = {0};
  1464. char capturedData[256] = {0};
  1465. char hashType[10] = "SHA256";
  1466. FILE *fp;
  1467. // Need to get hash type first
  1468. sprintf(temp ,"openssl x509 -noout -text -in %s", certPath);
  1469. fp = popen(temp, "r");
  1470. if(fp)
  1471. {
  1472. while(fgets(temp, sizeof(temp), fp) != NULL)
  1473. {
  1474. if(strstr(temp, "Signature Algorithm:") != NULL)
  1475. {
  1476. result = PASS;
  1477. if(strstr(temp, "sha256") != NULL || strstr(temp, "SHA256") != NULL)
  1478. sprintf((char*)hashType, "SHA256");
  1479. else if(strstr(temp, "sha384") != NULL || strstr(temp, "SHA384") != NULL)
  1480. sprintf((char*)hashType, "SHA384");
  1481. else if(strstr(temp, "sha512") != NULL || strstr(temp, "SHA512") != NULL)
  1482. sprintf((char*)hashType, "SHA512");
  1483. else
  1484. {
  1485. DEBUG_INFO("Error: hashAlgorithm is illegal or missing.\n");
  1486. result = FAIL;
  1487. }
  1488. break;
  1489. }
  1490. }
  1491. }
  1492. switch(parseType)
  1493. {
  1494. case CERT_PARSE_HashAlgorithm:
  1495. sprintf((char*)data, hashType);
  1496. DEBUG_INFO("hashAlgorithm: %s\n", hashType);
  1497. break;
  1498. case CERT_PARSE_SerialNumber:
  1499. sprintf(temp ,"openssl x509 -noout -serial -in %s", certPath);
  1500. fp = popen(temp, "r");
  1501. if(fp)
  1502. {
  1503. while(fgets(temp, sizeof(temp), fp) != NULL)
  1504. {
  1505. if(strstr(temp, "serial=") != NULL)
  1506. {
  1507. sscanf(temp, "%*[^=]=%s", capturedData);
  1508. result = PASS;
  1509. break;
  1510. }
  1511. }
  1512. DEBUG_INFO("serialNumber: %s\n", capturedData);
  1513. sprintf((char*)data, capturedData);
  1514. }
  1515. break;
  1516. case CERT_PARSE_IssuerNameHash:
  1517. sprintf(temp ,"openssl x509 -noout -issuer -in %s | openssl dgst -%s", certPath, (char*)hashType);
  1518. fp = popen(temp, "r");
  1519. if(fp)
  1520. {
  1521. while(fgets(temp, sizeof(temp), fp) != NULL)
  1522. {
  1523. if(strstr(temp, "(stdin)=") != NULL)
  1524. {
  1525. sscanf(temp, "%*[^=]=%s", capturedData);
  1526. result = PASS;
  1527. break;
  1528. }
  1529. }
  1530. stringtrimspace(capturedData);
  1531. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1532. sprintf((char*)data, capturedData);
  1533. }
  1534. break;
  1535. case CERT_PARSE_IssuerKeyHash:
  1536. sprintf(temp ,"openssl x509 -noout -pubkey -in %s | openssl dgst -%s", certPath, (char*)hashType);
  1537. fp = popen(temp, "r");
  1538. if(fp)
  1539. {
  1540. while(fgets(temp, sizeof(temp), fp) != NULL)
  1541. {
  1542. if(strstr(temp, "(stdin)=") != NULL)
  1543. {
  1544. sscanf(temp, "%*[^=]=%s", capturedData);
  1545. result = PASS;
  1546. break;
  1547. }
  1548. }
  1549. stringtrimspace(capturedData);
  1550. DEBUG_INFO("issuerKeyHash: %s\n", capturedData);
  1551. sprintf((char*)data, capturedData);
  1552. }
  1553. break;
  1554. case CERT_PARSE_OcspUrl:
  1555. //sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", certPath);
  1556. sprintf(temp ,"openssl crl2pkcs7 -nocrl -certfile %s | openssl pkcs7 -print_certs -text -noout", certPath);
  1557. fp = popen(temp, "r");
  1558. if(fp)
  1559. {
  1560. while(fgets(temp, sizeof(temp), fp) != NULL)
  1561. {
  1562. if(strstr(temp, "OCSP - URI:") != NULL)
  1563. {
  1564. //strcpy((char*)data, temp);
  1565. sscanf(temp, "%*[^:]:%s", capturedData);
  1566. sprintf((char*)data, capturedData);
  1567. DEBUG_INFO("OCSP_URI: %s\n", data);
  1568. result = PASS;
  1569. break;
  1570. }
  1571. }
  1572. }
  1573. break;
  1574. default:
  1575. DEBUG_INFO("Parse type is invalid.\n");
  1576. break;
  1577. }
  1578. pclose(fp);
  1579. }
  1580. return result;
  1581. }
  1582. //==========================================
  1583. // GetCompositeSchedule logic related function
  1584. //==========================================
  1585. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1586. {
  1587. //return milli-second
  1588. unsigned int StartTime,StopTime;
  1589. StartTime=(unsigned int)ST.time;
  1590. StopTime=(unsigned int)ET.time;
  1591. return (StopTime-StartTime);
  1592. }
  1593. int DiffTimebWithNowSec(struct timeb ST)
  1594. {
  1595. //return milli-second
  1596. struct timeb ET;
  1597. unsigned int StartTime,StopTime;
  1598. ftime(&ET);
  1599. StartTime=(unsigned int)ST.time;
  1600. StopTime=(unsigned int)ET.time;
  1601. return (StopTime-StartTime);
  1602. }
  1603. int getStartStop(uint8_t *start, uint8_t *stop)
  1604. {
  1605. struct ParsingResult
  1606. {
  1607. int result;
  1608. int scanedElement;
  1609. int year;
  1610. int month;
  1611. int mday;
  1612. int hour;
  1613. int min;
  1614. int sec;
  1615. int tz_hour;
  1616. int tz_min;
  1617. float minSec;
  1618. };
  1619. struct ParsingResult parseStart;
  1620. struct ParsingResult parseStop;
  1621. int result = -1;
  1622. struct tm tmStart;
  1623. struct timeb tbStart;
  1624. struct tm tmStop;
  1625. struct timeb tbStop;
  1626. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1627. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1628. // Scan start & stop date time
  1629. if(strstr((char*)start, ".") != NULL)
  1630. {
  1631. // Original data with mini second
  1632. if(strstr((char*)start, "Z") != NULL)
  1633. {
  1634. // Original data with Z
  1635. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1636. &parseStart.year,
  1637. &parseStart.month,
  1638. &parseStart.mday,
  1639. &parseStart.hour,
  1640. &parseStart.min,
  1641. &parseStart.sec,
  1642. &parseStart.minSec);
  1643. }
  1644. else
  1645. {
  1646. // Original data without Z
  1647. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1648. &parseStart.year,
  1649. &parseStart.month,
  1650. &parseStart.mday,
  1651. &parseStart.hour,
  1652. &parseStart.min,
  1653. &parseStart.sec,
  1654. &parseStart.minSec,
  1655. &parseStart.tz_hour,
  1656. &parseStart.tz_min);
  1657. }
  1658. }
  1659. else
  1660. {
  1661. // Original data without mini second
  1662. if(strstr((char*)start, "Z") != NULL)
  1663. {
  1664. // Original data with Z
  1665. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1666. &parseStart.year,
  1667. &parseStart.month,
  1668. &parseStart.mday,
  1669. &parseStart.hour,
  1670. &parseStart.min,
  1671. &parseStart.sec);
  1672. }
  1673. else
  1674. {
  1675. // Original data without Z
  1676. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1677. &parseStart.year,
  1678. &parseStart.month,
  1679. &parseStart.mday,
  1680. &parseStart.hour,
  1681. &parseStart.min,
  1682. &parseStart.sec,
  1683. &parseStart.tz_hour,
  1684. &parseStart.tz_min);
  1685. }
  1686. }
  1687. if(strstr((char*)stop, ".") != NULL)
  1688. {
  1689. // Original data with mini second
  1690. if(strstr((char*)stop, "Z") != NULL)
  1691. {
  1692. // Original data with Z
  1693. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1694. &parseStop.year,
  1695. &parseStop.month,
  1696. &parseStop.mday,
  1697. &parseStop.hour,
  1698. &parseStop.min,
  1699. &parseStop.sec,
  1700. &parseStop.minSec);
  1701. }
  1702. else
  1703. {
  1704. // Original data without Z
  1705. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1706. &parseStop.year,
  1707. &parseStop.month,
  1708. &parseStop.mday,
  1709. &parseStop.hour,
  1710. &parseStop.min,
  1711. &parseStop.sec,
  1712. &parseStop.minSec,
  1713. &parseStop.tz_hour,
  1714. &parseStop.tz_min);
  1715. }
  1716. }
  1717. else
  1718. {
  1719. // Original data without mini second
  1720. if(strstr((char*)stop, "Z") != NULL)
  1721. {
  1722. // Original data with Z
  1723. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1724. &parseStop.year,
  1725. &parseStop.month,
  1726. &parseStop.mday,
  1727. &parseStop.hour,
  1728. &parseStop.min,
  1729. &parseStop.sec);
  1730. }
  1731. else
  1732. {
  1733. // Original data without Z
  1734. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1735. &parseStop.year,
  1736. &parseStop.month,
  1737. &parseStop.mday,
  1738. &parseStop.hour,
  1739. &parseStop.min,
  1740. &parseStop.sec,
  1741. &parseStop.tz_hour,
  1742. &parseStop.tz_min);
  1743. }
  1744. }
  1745. // Calculate date time difference
  1746. if((parseStart.scanedElement >=6) &&
  1747. (parseStop.scanedElement >=6))
  1748. {
  1749. //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);
  1750. //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);
  1751. tmStart.tm_year = parseStart.year - 1900;
  1752. tmStart.tm_mon = parseStart.month - 1;
  1753. tmStart.tm_mday = parseStart.mday;
  1754. tmStart.tm_hour = parseStart.hour;
  1755. tmStart.tm_min = parseStart.min;
  1756. tmStart.tm_sec = parseStart.sec;
  1757. tmStart.tm_gmtoff = 0;
  1758. tbStart.time = mktime(&tmStart);
  1759. tbStart.timezone = 0;
  1760. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1761. tmStop.tm_year = parseStop.year - 1900;
  1762. tmStop.tm_mon = parseStop.month - 1;
  1763. tmStop.tm_mday = parseStop.mday;
  1764. tmStop.tm_hour = parseStop.hour;
  1765. tmStop.tm_min = parseStop.min;
  1766. tmStop.tm_sec = parseStop.sec;
  1767. tmStop.tm_gmtoff = 0;
  1768. tbStop.time = mktime(&tmStop);
  1769. tbStop.timezone = 0;
  1770. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1771. result = DiffTimebSec(tbStart, tbStop);
  1772. //DEBUG_INFO("getStartStop(): %d\n", result);
  1773. }
  1774. else
  1775. {
  1776. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1777. }
  1778. return result;
  1779. }
  1780. int isOvertNow(uint8_t *start)
  1781. {
  1782. int result = NO;
  1783. struct ParsingResult
  1784. {
  1785. int result;
  1786. int scanedElement;
  1787. int year;
  1788. int month;
  1789. int mday;
  1790. int hour;
  1791. int min;
  1792. int sec;
  1793. int tz_hour;
  1794. int tz_min;
  1795. float minSec;
  1796. }parsingResult;
  1797. struct tm tmStart;
  1798. struct timeb tbStart;
  1799. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1800. if(strstr((char*)start, ".") != NULL)
  1801. {
  1802. // Original data with mini second
  1803. if(strstr((char*)start, "Z") != NULL)
  1804. {
  1805. // Original data with Z
  1806. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1807. &parsingResult.year,
  1808. &parsingResult.month,
  1809. &parsingResult.mday,
  1810. &parsingResult.hour,
  1811. &parsingResult.min,
  1812. &parsingResult.sec,
  1813. &parsingResult.minSec);
  1814. }
  1815. else
  1816. {
  1817. // Original data without Z
  1818. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1819. &parsingResult.year,
  1820. &parsingResult.month,
  1821. &parsingResult.mday,
  1822. &parsingResult.hour,
  1823. &parsingResult.min,
  1824. &parsingResult.sec,
  1825. &parsingResult.minSec,
  1826. &parsingResult.tz_hour,
  1827. &parsingResult.tz_min);
  1828. }
  1829. }
  1830. else
  1831. {
  1832. // Original data without mini second
  1833. if(strstr((char*)start, "Z") != NULL)
  1834. {
  1835. // Original data with Z
  1836. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1837. &parsingResult.year,
  1838. &parsingResult.month,
  1839. &parsingResult.mday,
  1840. &parsingResult.hour,
  1841. &parsingResult.min,
  1842. &parsingResult.sec);
  1843. }
  1844. else
  1845. {
  1846. // Original data without Z
  1847. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1848. &parsingResult.year,
  1849. &parsingResult.month,
  1850. &parsingResult.mday,
  1851. &parsingResult.hour,
  1852. &parsingResult.min,
  1853. &parsingResult.sec,
  1854. &parsingResult.tz_hour,
  1855. &parsingResult.tz_min);
  1856. }
  1857. }
  1858. if(parsingResult.scanedElement >= 6)
  1859. {
  1860. tmStart.tm_year = parsingResult.year - 1900;
  1861. tmStart.tm_mon = parsingResult.month - 1;
  1862. tmStart.tm_mday = parsingResult.mday;
  1863. tmStart.tm_hour = parsingResult.hour;
  1864. tmStart.tm_min = parsingResult.min;
  1865. tmStart.tm_sec = parsingResult.sec;
  1866. tmStart.tm_gmtoff = 0;
  1867. tbStart.time = mktime(&tmStart);
  1868. tbStart.timezone = 0;
  1869. tbStart.millitm = 0;
  1870. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1871. if(DiffTimebWithNowSec(tbStart) <= 0)
  1872. result = NO;
  1873. else
  1874. result = YES;
  1875. }
  1876. else
  1877. {
  1878. DEBUG_WARN("Start date parsing error.\n");
  1879. }
  1880. return result;
  1881. }
  1882. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1883. {
  1884. struct ParsingResult
  1885. {
  1886. int result;
  1887. int scanedElement;
  1888. int year;
  1889. int month;
  1890. int mday;
  1891. int hour;
  1892. int min;
  1893. int sec;
  1894. int tz_hour;
  1895. int tz_min;
  1896. float minSec;
  1897. };
  1898. struct ParsingResult parseStart;
  1899. struct ParsingResult parseStop;
  1900. int result = -1;
  1901. struct tm tmStart;
  1902. struct timeb tbStart;
  1903. struct tm tmStop;
  1904. struct timeb tbStop;
  1905. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1906. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1907. // Scan start & stop date time
  1908. if(strstr((char*)start, ".") != NULL)
  1909. {
  1910. // Original data with mini second
  1911. if(strstr((char*)start, "Z") != NULL)
  1912. {
  1913. // Original data with Z
  1914. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1915. &parseStart.year,
  1916. &parseStart.month,
  1917. &parseStart.mday,
  1918. &parseStart.hour,
  1919. &parseStart.min,
  1920. &parseStart.sec,
  1921. &parseStart.minSec);
  1922. }
  1923. else
  1924. {
  1925. // Original data without Z
  1926. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1927. &parseStart.year,
  1928. &parseStart.month,
  1929. &parseStart.mday,
  1930. &parseStart.hour,
  1931. &parseStart.min,
  1932. &parseStart.sec,
  1933. &parseStart.minSec,
  1934. &parseStart.tz_hour,
  1935. &parseStart.tz_min);
  1936. }
  1937. }
  1938. else
  1939. {
  1940. // Original data without mini second
  1941. if(strstr((char*)start, "Z") != NULL)
  1942. {
  1943. // Original data with Z
  1944. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1945. &parseStart.year,
  1946. &parseStart.month,
  1947. &parseStart.mday,
  1948. &parseStart.hour,
  1949. &parseStart.min,
  1950. &parseStart.sec);
  1951. }
  1952. else
  1953. {
  1954. // Original data without Z
  1955. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1956. &parseStart.year,
  1957. &parseStart.month,
  1958. &parseStart.mday,
  1959. &parseStart.hour,
  1960. &parseStart.min,
  1961. &parseStart.sec,
  1962. &parseStart.tz_hour,
  1963. &parseStart.tz_min);
  1964. }
  1965. }
  1966. if(strstr((char*)stop, ".") != NULL)
  1967. {
  1968. // Original data with mini second
  1969. if(strstr((char*)stop, "Z") != NULL)
  1970. {
  1971. // Original data with Z
  1972. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1973. &parseStop.year,
  1974. &parseStop.month,
  1975. &parseStop.mday,
  1976. &parseStop.hour,
  1977. &parseStop.min,
  1978. &parseStop.sec,
  1979. &parseStop.minSec);
  1980. }
  1981. else
  1982. {
  1983. // Original data without Z
  1984. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1985. &parseStop.year,
  1986. &parseStop.month,
  1987. &parseStop.mday,
  1988. &parseStop.hour,
  1989. &parseStop.min,
  1990. &parseStop.sec,
  1991. &parseStop.minSec,
  1992. &parseStop.tz_hour,
  1993. &parseStop.tz_min);
  1994. }
  1995. }
  1996. else
  1997. {
  1998. // Original data without mini second
  1999. if(strstr((char*)stop, "Z") != NULL)
  2000. {
  2001. // Original data with Z
  2002. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  2003. &parseStop.year,
  2004. &parseStop.month,
  2005. &parseStop.mday,
  2006. &parseStop.hour,
  2007. &parseStop.min,
  2008. &parseStop.sec);
  2009. }
  2010. else
  2011. {
  2012. // Original data without Z
  2013. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  2014. &parseStop.year,
  2015. &parseStop.month,
  2016. &parseStop.mday,
  2017. &parseStop.hour,
  2018. &parseStop.min,
  2019. &parseStop.sec,
  2020. &parseStop.tz_hour,
  2021. &parseStop.tz_min);
  2022. }
  2023. }
  2024. // Calculate date time difference
  2025. if((parseStart.scanedElement >=6) &&
  2026. (parseStop.scanedElement >=6))
  2027. {
  2028. //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);
  2029. //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);
  2030. tmStart.tm_year = parseStart.year - 1900;
  2031. tmStart.tm_mon = parseStart.month - 1;
  2032. tmStart.tm_mday = parseStart.mday;
  2033. tmStart.tm_hour = parseStart.hour;
  2034. tmStart.tm_min = parseStart.min;
  2035. tmStart.tm_sec = parseStart.sec;
  2036. tmStart.tm_gmtoff = 0;
  2037. tbStart.time = mktime(&tmStart);
  2038. tbStart.timezone = 0;
  2039. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  2040. tmStop.tm_year = parseStop.year - 1900;
  2041. tmStop.tm_mon = parseStop.month - 1;
  2042. tmStop.tm_mday = parseStop.mday;
  2043. tmStop.tm_hour = parseStop.hour;
  2044. tmStop.tm_min = parseStop.min;
  2045. tmStop.tm_sec = parseStop.sec;
  2046. tmStop.tm_gmtoff = 0;
  2047. tbStop.time = mktime(&tmStop);
  2048. tbStop.timezone = 0;
  2049. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  2050. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  2051. //DEBUG_INFO("getStartStop(): %d\n", result);
  2052. }
  2053. else
  2054. {
  2055. DEBUG_WARN("Start or stop date parsing error.\r\n");
  2056. }
  2057. return result;
  2058. }
  2059. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2060. {
  2061. FILE *fp;
  2062. char profileFileName[128];
  2063. char *line = NULL;
  2064. size_t len = 0;
  2065. time_t CurrentTime;
  2066. struct tm *tmComposite;
  2067. struct StructChargingProfile maxProfile;
  2068. struct StructChargingProfile compositeProfile;
  2069. uint8_t limitMax=0;
  2070. int compositePeriodIdx = 0;
  2071. //uint8_t isDurationNull = FALSE;
  2072. CurrentTime = time(NULL);
  2073. tmComposite=localtime(&CurrentTime);
  2074. 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);
  2075. if(isUnitA)
  2076. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2077. else
  2078. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2079. compositeProfile.ChargingSchedule.Duration = durationReq;
  2080. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2081. {
  2082. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2083. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2084. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2085. }
  2086. compositeProfile.ChargingProfileId = 0;
  2087. compositeProfile.StackLevel = 99 ;
  2088. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2089. maxProfile.ChargingProfileId = -1;
  2090. maxProfile.ChargingSchedule.Duration = -1;
  2091. system("rm -f /tmp/*.json");
  2092. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2093. // Search max profile
  2094. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2095. if((access(profileFileName, F_OK))!=-1)
  2096. {
  2097. fp = fopen(profileFileName, "r");
  2098. while(getline(&line, &len, fp) != -1)
  2099. {
  2100. json_object *obj = NULL;
  2101. obj = json_tokener_parse(line);
  2102. if(is_error(obj))
  2103. {
  2104. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2105. }
  2106. else
  2107. {
  2108. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2109. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2110. )
  2111. {
  2112. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2113. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2114. )
  2115. {
  2116. struct tm tmFrom, tmTo;
  2117. struct timeb tbFrom, tbTo;
  2118. 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) &&
  2119. (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))
  2120. {
  2121. tmFrom.tm_year -= 1900;
  2122. tmFrom.tm_mon -= 1;
  2123. tbFrom.time = mktime(&tmFrom);
  2124. tmTo.tm_year -= 1900;
  2125. tmTo.tm_mon -= 1;
  2126. tbTo.time = mktime(&tmTo);
  2127. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2128. {
  2129. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2130. {
  2131. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2132. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2133. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2134. }
  2135. if(maxProfile.ChargingProfileId == -1)
  2136. DEBUG_INFO("MaxProfile found.\n");
  2137. else
  2138. DEBUG_INFO("MaxProfile updated.\n");
  2139. // Required item
  2140. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2141. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2142. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2143. if(isUnitA)
  2144. {
  2145. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2146. 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++)
  2147. {
  2148. 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"));
  2149. 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?
  2150. 3:
  2151. 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")));
  2152. 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")));
  2153. }
  2154. }
  2155. else
  2156. {
  2157. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2158. 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++)
  2159. {
  2160. 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"));
  2161. 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?
  2162. 3:
  2163. 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")));
  2164. 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));
  2165. }
  2166. }
  2167. // Optional item
  2168. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2169. {
  2170. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2171. }
  2172. else
  2173. {
  2174. sprintf((char*)maxProfile.ValidFrom, " ");
  2175. }
  2176. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2177. {
  2178. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2179. }
  2180. else
  2181. {
  2182. sprintf((char*)maxProfile.ValidTo, " ");
  2183. }
  2184. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2185. {
  2186. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2187. }
  2188. else
  2189. {
  2190. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2191. }
  2192. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2193. {
  2194. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2195. }
  2196. else
  2197. {
  2198. maxProfile.TransactionId = -1;
  2199. }
  2200. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2201. {
  2202. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2203. }
  2204. else
  2205. {
  2206. maxProfile.ChargingSchedule.Duration = 86400;
  2207. //isDurationNull = TRUE;
  2208. }
  2209. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2210. {
  2211. 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")));
  2212. }
  2213. else
  2214. {
  2215. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2216. }
  2217. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2218. {
  2219. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2220. }
  2221. else
  2222. {
  2223. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2224. }
  2225. }
  2226. }
  2227. }
  2228. else
  2229. {
  2230. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2231. {
  2232. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2233. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2234. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2235. }
  2236. if(maxProfile.ChargingProfileId == -1)
  2237. DEBUG_INFO("MaxProfile found.\n");
  2238. else
  2239. DEBUG_INFO("MaxProfile updated.\n");
  2240. // Required item
  2241. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2242. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2243. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2244. if(isUnitA)
  2245. {
  2246. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2247. 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++)
  2248. {
  2249. 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"));
  2250. 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?
  2251. 3:
  2252. 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")));
  2253. 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")));
  2254. }
  2255. }
  2256. else
  2257. {
  2258. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2259. 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++)
  2260. {
  2261. 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"));
  2262. 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?
  2263. 3:
  2264. 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")));
  2265. 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));
  2266. }
  2267. }
  2268. // Optional item
  2269. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2270. {
  2271. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2272. }
  2273. else
  2274. {
  2275. sprintf((char*)maxProfile.ValidFrom, " ");
  2276. }
  2277. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2278. {
  2279. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2280. }
  2281. else
  2282. {
  2283. sprintf((char*)maxProfile.ValidTo, " ");
  2284. }
  2285. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2286. {
  2287. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2288. }
  2289. else
  2290. {
  2291. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2292. }
  2293. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2294. {
  2295. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2296. }
  2297. else
  2298. {
  2299. maxProfile.TransactionId = -1;
  2300. }
  2301. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2302. {
  2303. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2304. }
  2305. else
  2306. {
  2307. maxProfile.ChargingSchedule.Duration = 86400;
  2308. //isDurationNull = TRUE;
  2309. }
  2310. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2311. {
  2312. 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")));
  2313. }
  2314. else
  2315. {
  2316. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2317. }
  2318. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2319. {
  2320. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2321. }
  2322. else
  2323. {
  2324. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2325. }
  2326. }
  2327. }
  2328. }
  2329. json_object_put(obj);
  2330. }
  2331. fclose(fp);
  2332. /*
  2333. if(maxProfile.ChargingProfileId !=-1)
  2334. {
  2335. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2336. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2337. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2338. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2339. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2340. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2341. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2342. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2343. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2344. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2345. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2346. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2347. {
  2348. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2349. {
  2350. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2351. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2352. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2353. }
  2354. }
  2355. }
  2356. else
  2357. DEBUG_INFO("MaxProfile not found.\n");
  2358. DEBUG_INFO("------------------------------------\n");*/
  2359. }
  2360. if(maxProfile.ChargingProfileId != -1)
  2361. {
  2362. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2363. {
  2364. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  2365. {
  2366. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2367. 0:
  2368. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2369. }
  2370. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2371. {
  2372. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2373. {
  2374. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2375. 0:
  2376. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2377. if(idxPeriod > 0)
  2378. {
  2379. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2380. {
  2381. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2382. }
  2383. }
  2384. }
  2385. }
  2386. }
  2387. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2388. {
  2389. if(maxProfile.ChargingSchedule.Duration != -1)
  2390. {
  2391. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2392. }
  2393. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2394. {
  2395. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2396. {
  2397. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2398. if(idxPeriod > 0)
  2399. {
  2400. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2401. {
  2402. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2403. }
  2404. }
  2405. }
  2406. }
  2407. }
  2408. else
  2409. {
  2410. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2411. {
  2412. if(maxProfile.ChargingSchedule.Duration != -1)
  2413. {
  2414. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2415. 0:
  2416. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2417. }
  2418. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2419. {
  2420. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2421. {
  2422. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2423. 0:
  2424. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2425. if(idxPeriod > 0)
  2426. {
  2427. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2428. {
  2429. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2430. }
  2431. }
  2432. }
  2433. }
  2434. }
  2435. else
  2436. {
  2437. if(maxProfile.ChargingSchedule.Duration != -1)
  2438. {
  2439. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2440. 0:
  2441. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2442. }
  2443. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2444. {
  2445. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2446. {
  2447. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2448. 0:
  2449. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2450. if(idxPeriod > 0)
  2451. {
  2452. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2453. {
  2454. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2455. }
  2456. }
  2457. }
  2458. }
  2459. }
  2460. }
  2461. /*
  2462. DEBUG_INFO("MaxProfile after align.\n");
  2463. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2464. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2465. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2466. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2467. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2468. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2469. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2470. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2471. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2472. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2473. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2474. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2475. {
  2476. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2477. {
  2478. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2479. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2480. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2481. }
  2482. }
  2483. DEBUG_INFO("------------------------------------\n");*/
  2484. }
  2485. // Find each profile period quantity
  2486. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2487. {
  2488. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2489. limitMax = idx+1;
  2490. }
  2491. if(maxProfile.ChargingProfileId != -1)
  2492. {
  2493. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2494. {
  2495. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2496. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2497. (maxProfile.ChargingSchedule.Duration > 0))
  2498. {
  2499. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2500. {
  2501. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2502. compositePeriodIdx++;
  2503. }
  2504. else
  2505. {
  2506. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2507. }
  2508. }
  2509. }
  2510. }
  2511. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2512. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2513. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2514. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2515. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2516. {
  2517. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2518. {
  2519. compositeProfile.ChargingProfileId = 1;
  2520. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2521. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2522. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2523. }
  2524. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2525. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2526. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2527. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2528. }
  2529. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2530. if(line)
  2531. free(line);
  2532. }
  2533. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2534. {
  2535. FILE *fp;
  2536. char profileFileName[128];
  2537. char *line = NULL;
  2538. size_t len = 0;
  2539. time_t CurrentTime;
  2540. struct tm *tmComposite;
  2541. struct StructChargingProfile maxProfile;
  2542. struct StructChargingProfile defaultTxProfile;
  2543. struct StructChargingProfile txProfile;
  2544. struct StructChargingProfile compositeProfile;
  2545. struct StructChargingSchedulePeriod tmpPeriod;
  2546. uint8_t limitMax=0;
  2547. uint8_t limitDef=0;
  2548. uint8_t limitTx=0;
  2549. int compositePeriodIdx = 0;
  2550. CurrentTime = time(NULL);
  2551. tmComposite=localtime(&CurrentTime);
  2552. 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);
  2553. if(isUnitA)
  2554. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2555. else
  2556. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2557. compositeProfile.ChargingSchedule.Duration = durationReq;
  2558. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2559. {
  2560. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2561. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2562. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2563. }
  2564. compositeProfile.ChargingProfileId = 0;
  2565. compositeProfile.StackLevel = 99 ;
  2566. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2567. maxProfile.ChargingProfileId = -1;
  2568. defaultTxProfile.ChargingProfileId = -1;
  2569. txProfile.ChargingProfileId = -1;
  2570. maxProfile.ChargingSchedule.Duration = -1;
  2571. defaultTxProfile.ChargingSchedule.Duration = -1;
  2572. txProfile.ChargingSchedule.Duration = -1;
  2573. system("rm -f /tmp/*.json");
  2574. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2575. /*
  2576. * Search valid charging profile
  2577. */
  2578. //DEBUG_INFO("====================================\n");
  2579. // Search tx profile
  2580. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2581. if((access(profileFileName, F_OK))!=-1)
  2582. {
  2583. fp = fopen(profileFileName, "r");
  2584. while(getline(&line, &len, fp) != -1)
  2585. {
  2586. json_object *obj = NULL;
  2587. obj = json_tokener_parse(line);
  2588. if(is_error(obj))
  2589. {
  2590. DEBUG_ERROR("Parse txProfile from file error.\n");
  2591. }
  2592. else
  2593. {
  2594. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2595. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2596. )
  2597. {
  2598. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2599. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2600. )
  2601. {
  2602. struct tm tmFrom, tmTo;
  2603. struct timeb tbFrom, tbTo;
  2604. 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) &&
  2605. (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))
  2606. {
  2607. tmFrom.tm_year -= 1900;
  2608. tmFrom.tm_mon -= 1;
  2609. tbFrom.time = mktime(&tmFrom);
  2610. tmTo.tm_year -= 1900;
  2611. tmTo.tm_mon -= 1;
  2612. tbTo.time = mktime(&tmTo);
  2613. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2614. {
  2615. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2616. {
  2617. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2618. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2619. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2620. }
  2621. if(txProfile.ChargingProfileId == -1)
  2622. DEBUG_INFO("TxProfile found.\n");
  2623. else
  2624. DEBUG_INFO("TxProfile updated.\n");
  2625. // Required item
  2626. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2627. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2628. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2629. if(isUnitA)
  2630. {
  2631. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2632. 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++)
  2633. {
  2634. 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"));
  2635. 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?
  2636. 3:
  2637. 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")));
  2638. 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")));
  2639. }
  2640. }
  2641. else
  2642. {
  2643. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2644. 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++)
  2645. {
  2646. 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"));
  2647. 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?
  2648. 3:
  2649. 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")));
  2650. 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));
  2651. }
  2652. }
  2653. // Optional item
  2654. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2655. {
  2656. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2657. }
  2658. else
  2659. {
  2660. sprintf((char*)txProfile.ValidFrom, " ");
  2661. }
  2662. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2663. {
  2664. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2665. }
  2666. else
  2667. {
  2668. sprintf((char*)txProfile.ValidTo, " ");
  2669. }
  2670. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2671. {
  2672. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2673. }
  2674. else
  2675. {
  2676. sprintf((char*)txProfile.RecurrencyKind, " ");
  2677. }
  2678. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2679. {
  2680. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2681. }
  2682. else
  2683. {
  2684. txProfile.TransactionId = -1;
  2685. }
  2686. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2687. {
  2688. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2689. }
  2690. else
  2691. {
  2692. txProfile.ChargingSchedule.Duration = 86400;
  2693. }
  2694. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2695. {
  2696. 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")));
  2697. }
  2698. else
  2699. {
  2700. 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));
  2701. }
  2702. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2703. {
  2704. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2705. }
  2706. else
  2707. {
  2708. txProfile.ChargingSchedule.MinChargingRate = -1;
  2709. }
  2710. }
  2711. }
  2712. }
  2713. else
  2714. {
  2715. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2716. {
  2717. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2718. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2719. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2720. }
  2721. if(txProfile.ChargingProfileId == -1)
  2722. DEBUG_INFO("TxProfile found.\n");
  2723. else
  2724. DEBUG_INFO("TxProfile updated.\n");
  2725. // Required item
  2726. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2727. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2728. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2729. if(isUnitA)
  2730. {
  2731. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2732. 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++)
  2733. {
  2734. 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"));
  2735. 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?
  2736. 3:
  2737. 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")));
  2738. 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")));
  2739. }
  2740. }
  2741. else
  2742. {
  2743. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2744. 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++)
  2745. {
  2746. 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"));
  2747. 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?
  2748. 3:
  2749. 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")));
  2750. 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));
  2751. }
  2752. }
  2753. // Optional item
  2754. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2755. {
  2756. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2757. }
  2758. else
  2759. {
  2760. sprintf((char*)txProfile.ValidFrom, " ");
  2761. }
  2762. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2763. {
  2764. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2765. }
  2766. else
  2767. {
  2768. sprintf((char*)txProfile.ValidTo, " ");
  2769. }
  2770. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2771. {
  2772. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2773. }
  2774. else
  2775. {
  2776. sprintf((char*)txProfile.RecurrencyKind, " ");
  2777. }
  2778. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2779. {
  2780. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2781. }
  2782. else
  2783. {
  2784. txProfile.TransactionId = -1;
  2785. }
  2786. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2787. {
  2788. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2789. }
  2790. else
  2791. {
  2792. txProfile.ChargingSchedule.Duration = 86400;
  2793. }
  2794. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2795. {
  2796. 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")));
  2797. }
  2798. else
  2799. {
  2800. 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));
  2801. }
  2802. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2803. {
  2804. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2805. }
  2806. else
  2807. {
  2808. txProfile.ChargingSchedule.MinChargingRate = -1;
  2809. }
  2810. }
  2811. }
  2812. }
  2813. json_object_put(obj);
  2814. }
  2815. fclose(fp);
  2816. /*
  2817. if(txProfile.ChargingProfileId != -1)
  2818. {
  2819. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2820. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2821. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2822. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2823. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2824. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2825. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2826. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2827. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2828. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2829. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2830. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2831. {
  2832. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2833. {
  2834. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2835. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2836. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2837. }
  2838. }
  2839. }
  2840. else
  2841. DEBUG_INFO("TxProfile not found.\n");*/
  2842. }
  2843. // Search default tx profile
  2844. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2845. if((access(profileFileName, F_OK))==-1)
  2846. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2847. if((access(profileFileName, F_OK))!=-1)
  2848. {
  2849. fp = fopen(profileFileName, "r");
  2850. while(getline(&line, &len, fp) != -1)
  2851. {
  2852. json_object *obj = NULL;
  2853. obj = json_tokener_parse(line);
  2854. if(is_error(obj))
  2855. {
  2856. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2857. }
  2858. else
  2859. {
  2860. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2861. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2862. )
  2863. {
  2864. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2865. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2866. )
  2867. {
  2868. struct tm tmFrom, tmTo;
  2869. struct timeb tbFrom, tbTo;
  2870. 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) &&
  2871. (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))
  2872. {
  2873. tmFrom.tm_year -= 1900;
  2874. tmFrom.tm_mon -= 1;
  2875. tbFrom.time = mktime(&tmFrom);
  2876. tmTo.tm_year -= 1900;
  2877. tmTo.tm_mon -= 1;
  2878. tbTo.time = mktime(&tmTo);
  2879. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2880. {
  2881. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2882. {
  2883. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2884. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2885. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2886. }
  2887. if(defaultTxProfile.ChargingProfileId == -1)
  2888. DEBUG_INFO("TxDefaultProfile found.\n");
  2889. else
  2890. DEBUG_INFO("TxDefaultProfile updated.\n");
  2891. // Required item
  2892. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2893. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2894. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2895. if(isUnitA)
  2896. {
  2897. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2898. 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++)
  2899. {
  2900. 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"));
  2901. 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?
  2902. 3:
  2903. 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")));
  2904. 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")));
  2905. }
  2906. }
  2907. else
  2908. {
  2909. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2910. 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++)
  2911. {
  2912. 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"));
  2913. 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?
  2914. 3:
  2915. 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")));
  2916. 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));
  2917. }
  2918. }
  2919. // Optional item
  2920. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2921. {
  2922. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2923. }
  2924. else
  2925. {
  2926. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2927. }
  2928. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2929. {
  2930. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2931. }
  2932. else
  2933. {
  2934. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2935. }
  2936. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2937. {
  2938. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2939. }
  2940. else
  2941. {
  2942. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2943. }
  2944. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2945. {
  2946. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2947. }
  2948. else
  2949. {
  2950. defaultTxProfile.TransactionId = -1;
  2951. }
  2952. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2953. {
  2954. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2955. }
  2956. else
  2957. {
  2958. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2959. }
  2960. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2961. {
  2962. 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")));
  2963. }
  2964. else
  2965. {
  2966. 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));
  2967. }
  2968. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2969. {
  2970. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2971. }
  2972. else
  2973. {
  2974. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2975. }
  2976. }
  2977. }
  2978. }
  2979. else
  2980. {
  2981. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2982. {
  2983. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2984. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2985. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2986. }
  2987. if(defaultTxProfile.ChargingProfileId == -1)
  2988. DEBUG_INFO("TxDefaultProfile found.\n");
  2989. else
  2990. DEBUG_INFO("TxDefaultProfile updated.\n");
  2991. // Required item
  2992. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2993. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2994. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2995. if(isUnitA)
  2996. {
  2997. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2998. 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++)
  2999. {
  3000. 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"));
  3001. 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?
  3002. 3:
  3003. 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")));
  3004. 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")));
  3005. }
  3006. }
  3007. else
  3008. {
  3009. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3010. 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++)
  3011. {
  3012. 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"));
  3013. 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?
  3014. 3:
  3015. 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")));
  3016. 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));
  3017. }
  3018. }
  3019. // Optional item
  3020. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3021. {
  3022. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3023. }
  3024. else
  3025. {
  3026. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  3027. }
  3028. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3029. {
  3030. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3031. }
  3032. else
  3033. {
  3034. sprintf((char*)defaultTxProfile.ValidTo, " ");
  3035. }
  3036. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3037. {
  3038. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3039. }
  3040. else
  3041. {
  3042. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  3043. }
  3044. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3045. {
  3046. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3047. }
  3048. else
  3049. {
  3050. defaultTxProfile.TransactionId = -1;
  3051. }
  3052. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3053. {
  3054. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3055. }
  3056. else
  3057. {
  3058. defaultTxProfile.ChargingSchedule.Duration = 86400;
  3059. }
  3060. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3061. {
  3062. 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")));
  3063. }
  3064. else
  3065. {
  3066. 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));
  3067. }
  3068. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3069. {
  3070. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3071. }
  3072. else
  3073. {
  3074. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  3075. }
  3076. }
  3077. }
  3078. }
  3079. json_object_put(obj);
  3080. }
  3081. fclose(fp);
  3082. /*
  3083. if(defaultTxProfile.ChargingProfileId != -1)
  3084. {
  3085. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3086. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3087. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3088. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3089. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3090. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3091. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3092. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  3093. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3094. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3095. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3096. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3097. {
  3098. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3099. {
  3100. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3101. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3102. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3103. }
  3104. }
  3105. }
  3106. else
  3107. DEBUG_INFO("TxDefaultProfile not found.\n");
  3108. DEBUG_INFO("------------------------------------\n");*/
  3109. }
  3110. // Search max profile
  3111. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  3112. if((access(profileFileName, F_OK))!=-1)
  3113. {
  3114. fp = fopen(profileFileName, "r");
  3115. while(getline(&line, &len, fp) != -1)
  3116. {
  3117. json_object *obj = NULL;
  3118. obj = json_tokener_parse(line);
  3119. if(is_error(obj))
  3120. {
  3121. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  3122. }
  3123. else
  3124. {
  3125. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  3126. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  3127. )
  3128. {
  3129. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3130. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3131. )
  3132. {
  3133. struct tm tmFrom, tmTo;
  3134. struct timeb tbFrom, tbTo;
  3135. 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) &&
  3136. (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))
  3137. {
  3138. tmFrom.tm_year -= 1900;
  3139. tmFrom.tm_mon -= 1;
  3140. tbFrom.time = mktime(&tmFrom);
  3141. tmTo.tm_year -= 1900;
  3142. tmTo.tm_mon -= 1;
  3143. tbTo.time = mktime(&tmTo);
  3144. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3145. {
  3146. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3147. {
  3148. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3149. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3150. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3151. }
  3152. if(maxProfile.ChargingProfileId == -1)
  3153. DEBUG_INFO("MaxProfile found.\n");
  3154. else
  3155. DEBUG_INFO("MaxProfile updated.\n");
  3156. // Required item
  3157. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3158. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3159. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3160. if(isUnitA)
  3161. {
  3162. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3163. 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++)
  3164. {
  3165. 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"));
  3166. 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?
  3167. 3:
  3168. 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")));
  3169. 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")));
  3170. }
  3171. }
  3172. else
  3173. {
  3174. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3175. 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++)
  3176. {
  3177. 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"));
  3178. 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?
  3179. 3:
  3180. 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")));
  3181. 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));
  3182. }
  3183. }
  3184. // Optional item
  3185. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3186. {
  3187. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3188. }
  3189. else
  3190. {
  3191. sprintf((char*)maxProfile.ValidFrom, " ");
  3192. }
  3193. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3194. {
  3195. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3196. }
  3197. else
  3198. {
  3199. sprintf((char*)maxProfile.ValidTo, " ");
  3200. }
  3201. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3202. {
  3203. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3204. }
  3205. else
  3206. {
  3207. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3208. }
  3209. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3210. {
  3211. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3212. }
  3213. else
  3214. {
  3215. maxProfile.TransactionId = -1;
  3216. }
  3217. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3218. {
  3219. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3220. }
  3221. else
  3222. {
  3223. maxProfile.ChargingSchedule.Duration = 86400;
  3224. }
  3225. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3226. {
  3227. 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")));
  3228. }
  3229. else
  3230. {
  3231. 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));
  3232. }
  3233. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3234. {
  3235. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3236. }
  3237. else
  3238. {
  3239. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3240. }
  3241. }
  3242. }
  3243. }
  3244. else
  3245. {
  3246. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3247. {
  3248. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3249. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3250. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3251. }
  3252. if(maxProfile.ChargingProfileId == -1)
  3253. DEBUG_INFO("MaxProfile found.\n");
  3254. else
  3255. DEBUG_INFO("MaxProfile updated.\n");
  3256. // Required item
  3257. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3258. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3259. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3260. if(isUnitA)
  3261. {
  3262. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3263. 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++)
  3264. {
  3265. 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"));
  3266. 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?
  3267. 3:
  3268. 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")));
  3269. 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")));
  3270. }
  3271. }
  3272. else
  3273. {
  3274. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3275. 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++)
  3276. {
  3277. 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"));
  3278. 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?
  3279. 3:
  3280. 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")));
  3281. 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));
  3282. }
  3283. }
  3284. // Optional item
  3285. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3286. {
  3287. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3288. }
  3289. else
  3290. {
  3291. sprintf((char*)maxProfile.ValidFrom, " ");
  3292. }
  3293. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3294. {
  3295. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3296. }
  3297. else
  3298. {
  3299. sprintf((char*)maxProfile.ValidTo, " ");
  3300. }
  3301. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3302. {
  3303. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3304. }
  3305. else
  3306. {
  3307. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3308. }
  3309. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3310. {
  3311. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3312. }
  3313. else
  3314. {
  3315. maxProfile.TransactionId = -1;
  3316. }
  3317. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3318. {
  3319. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3320. }
  3321. else
  3322. {
  3323. maxProfile.ChargingSchedule.Duration = 86400;
  3324. }
  3325. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3326. {
  3327. 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")));
  3328. }
  3329. else
  3330. {
  3331. 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));
  3332. }
  3333. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3334. {
  3335. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3336. }
  3337. else
  3338. {
  3339. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3340. }
  3341. }
  3342. }
  3343. }
  3344. json_object_put(obj);
  3345. }
  3346. fclose(fp);
  3347. /*
  3348. if(maxProfile.ChargingProfileId !=-1)
  3349. {
  3350. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3351. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3352. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3353. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3354. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3355. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3356. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3357. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3358. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3359. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3360. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3361. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3362. {
  3363. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3364. {
  3365. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3366. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3367. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3368. }
  3369. }
  3370. }
  3371. else
  3372. DEBUG_INFO("MaxProfile not found.\n");
  3373. DEBUG_INFO("------------------------------------\n");*/
  3374. }
  3375. /*
  3376. * Align found profile start schedule & periods
  3377. */
  3378. //DEBUG_INFO("====================================\n");
  3379. /*
  3380. // For local test usage, force modify found profile start schedule info
  3381. 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);
  3382. 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);
  3383. 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);
  3384. */
  3385. if(txProfile.ChargingProfileId != -1)
  3386. {
  3387. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3388. {
  3389. if(txProfile.ChargingSchedule.Duration != -1)
  3390. {
  3391. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3392. 0:
  3393. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3394. }
  3395. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3396. {
  3397. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3398. {
  3399. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3400. 0:
  3401. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3402. if(idxPeriod > 0)
  3403. {
  3404. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3405. {
  3406. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3407. }
  3408. }
  3409. }
  3410. }
  3411. }
  3412. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3413. {
  3414. if(txProfile.ChargingSchedule.Duration != -1)
  3415. {
  3416. 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?
  3417. 0:
  3418. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3419. }
  3420. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3421. {
  3422. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3423. {
  3424. 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?
  3425. 0:
  3426. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3427. if(idxPeriod > 0)
  3428. {
  3429. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3430. {
  3431. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3432. }
  3433. }
  3434. }
  3435. }
  3436. }
  3437. else
  3438. {
  3439. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3440. {
  3441. if(txProfile.ChargingSchedule.Duration != -1)
  3442. {
  3443. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3444. 0:
  3445. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3446. }
  3447. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3448. {
  3449. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3450. {
  3451. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3452. 0:
  3453. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3454. if(idxPeriod > 0)
  3455. {
  3456. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3457. {
  3458. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3459. }
  3460. }
  3461. }
  3462. }
  3463. }
  3464. else
  3465. {
  3466. if(txProfile.ChargingSchedule.Duration != -1)
  3467. {
  3468. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3469. 0:
  3470. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3471. }
  3472. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3473. {
  3474. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3475. {
  3476. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3477. 0:
  3478. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3479. if(idxPeriod > 0)
  3480. {
  3481. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3482. {
  3483. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3484. }
  3485. }
  3486. }
  3487. }
  3488. }
  3489. }
  3490. /*
  3491. DEBUG_INFO("txProfile after align.\n");
  3492. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3493. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3494. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3495. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3496. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3497. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3498. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3499. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3500. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3501. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3502. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3503. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3504. {
  3505. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3506. {
  3507. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3508. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3509. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3510. }
  3511. }*/
  3512. }
  3513. if(defaultTxProfile.ChargingProfileId != -1)
  3514. {
  3515. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3516. {
  3517. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3518. {
  3519. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3520. 0:
  3521. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3522. }
  3523. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3524. {
  3525. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3526. {
  3527. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3528. 0:
  3529. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3530. if(idxPeriod > 0)
  3531. {
  3532. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3533. {
  3534. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3535. }
  3536. }
  3537. }
  3538. }
  3539. }
  3540. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3541. {
  3542. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3543. {
  3544. 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?
  3545. 0:
  3546. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3547. }
  3548. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3549. {
  3550. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3551. {
  3552. 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?
  3553. 0:
  3554. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3555. if(idxPeriod > 0)
  3556. {
  3557. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3558. {
  3559. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3560. }
  3561. }
  3562. }
  3563. }
  3564. }
  3565. else
  3566. {
  3567. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3568. {
  3569. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3570. {
  3571. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3572. 0:
  3573. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3574. }
  3575. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3576. {
  3577. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3578. {
  3579. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3580. 0:
  3581. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3582. if(idxPeriod > 0)
  3583. {
  3584. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3585. {
  3586. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3587. }
  3588. }
  3589. }
  3590. }
  3591. }
  3592. else
  3593. {
  3594. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3595. {
  3596. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3597. 0:
  3598. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3599. }
  3600. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3601. {
  3602. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3603. {
  3604. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3605. 0:
  3606. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3607. if(idxPeriod > 0)
  3608. {
  3609. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3610. {
  3611. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3612. }
  3613. }
  3614. }
  3615. }
  3616. }
  3617. }
  3618. /*
  3619. DEBUG_INFO("defaultTxProfile after align.\n");
  3620. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3621. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3622. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3623. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3624. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3625. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3626. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3627. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3628. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3629. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3630. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3631. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3632. {
  3633. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3634. {
  3635. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3636. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3637. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3638. }
  3639. }
  3640. DEBUG_INFO("------------------------------------\n");*/
  3641. }
  3642. if(maxProfile.ChargingProfileId != -1)
  3643. {
  3644. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3645. {
  3646. if(maxProfile.ChargingSchedule.Duration != -1)
  3647. {
  3648. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3649. 0:
  3650. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3651. }
  3652. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3653. {
  3654. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3655. {
  3656. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3657. 0:
  3658. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3659. if(idxPeriod > 0)
  3660. {
  3661. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3662. {
  3663. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3664. }
  3665. }
  3666. }
  3667. }
  3668. }
  3669. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3670. {
  3671. if(maxProfile.ChargingSchedule.Duration != -1)
  3672. {
  3673. 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?
  3674. 0:
  3675. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3676. }
  3677. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3678. {
  3679. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3680. {
  3681. 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?
  3682. 0:
  3683. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3684. if(idxPeriod > 0)
  3685. {
  3686. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3687. {
  3688. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3689. }
  3690. }
  3691. }
  3692. }
  3693. }
  3694. else
  3695. {
  3696. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3697. {
  3698. if(maxProfile.ChargingSchedule.Duration != -1)
  3699. {
  3700. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3701. 0:
  3702. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3703. }
  3704. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3705. {
  3706. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3707. {
  3708. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3709. 0:
  3710. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3711. if(idxPeriod > 0)
  3712. {
  3713. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3714. {
  3715. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3716. }
  3717. }
  3718. }
  3719. }
  3720. }
  3721. else
  3722. {
  3723. if(maxProfile.ChargingSchedule.Duration != -1)
  3724. {
  3725. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3726. 0:
  3727. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3728. }
  3729. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3730. {
  3731. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3732. {
  3733. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3734. 0:
  3735. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3736. if(idxPeriod > 0)
  3737. {
  3738. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3739. {
  3740. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3741. }
  3742. }
  3743. }
  3744. }
  3745. }
  3746. }
  3747. /*
  3748. DEBUG_INFO("MaxProfile after align.\n");
  3749. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3750. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3751. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3752. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3753. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3754. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3755. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3756. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3757. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3758. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3759. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3760. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3761. {
  3762. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3763. {
  3764. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3765. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3766. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3767. }
  3768. }
  3769. DEBUG_INFO("------------------------------------\n");*/
  3770. }
  3771. /*
  3772. * Merge to conposite schedule
  3773. */
  3774. //DEBUG_INFO("====================================\n");
  3775. // Find each profile period quantity
  3776. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3777. {
  3778. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3779. limitMax = idx+1;
  3780. }
  3781. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3782. {
  3783. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3784. limitDef = idx+1;
  3785. }
  3786. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3787. {
  3788. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3789. limitTx = idx+1;
  3790. }
  3791. // TxProfile found, composite schedule based on it
  3792. if(txProfile.ChargingProfileId != -1)
  3793. {
  3794. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3795. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3796. {
  3797. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3798. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3799. (txProfile.ChargingSchedule.Duration > 0))
  3800. {
  3801. if(maxProfile.ChargingProfileId != -1)
  3802. {
  3803. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3804. {
  3805. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3806. {
  3807. if((maxProfile.ChargingSchedule.Duration > 0))
  3808. {
  3809. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3810. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3811. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3812. }
  3813. else
  3814. {
  3815. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3816. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3817. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3818. }
  3819. }
  3820. if(idxMaxPeriod == (limitMax-1))
  3821. {
  3822. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3823. {
  3824. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3825. {
  3826. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3827. compositePeriodIdx++;
  3828. }
  3829. else
  3830. {
  3831. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3832. }
  3833. }
  3834. }
  3835. }
  3836. }
  3837. else
  3838. {
  3839. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3840. {
  3841. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3842. compositePeriodIdx++;
  3843. }
  3844. else
  3845. {
  3846. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3847. }
  3848. }
  3849. }
  3850. if(idxTxPeriod == (limitTx-1))
  3851. {
  3852. if(defaultTxProfile.ChargingProfileId != -1)
  3853. {
  3854. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3855. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3856. {
  3857. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3858. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3859. (defaultTxProfile.ChargingSchedule.Duration>0))
  3860. {
  3861. if(maxProfile.ChargingProfileId != -1)
  3862. {
  3863. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3864. {
  3865. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3866. {
  3867. if((maxProfile.ChargingSchedule.Duration > 0))
  3868. {
  3869. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3870. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3871. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3872. }
  3873. else
  3874. {
  3875. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3876. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3877. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3878. }
  3879. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3880. {
  3881. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3882. {
  3883. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3884. compositePeriodIdx++;
  3885. }
  3886. else
  3887. {
  3888. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3889. }
  3890. }
  3891. // Delete duplicate period
  3892. if(compositePeriodIdx > 1)
  3893. {
  3894. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3895. {
  3896. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3897. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3898. compositePeriodIdx -= 1;
  3899. }
  3900. }
  3901. }
  3902. else
  3903. {
  3904. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3905. {
  3906. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3907. compositePeriodIdx++;
  3908. }
  3909. else
  3910. {
  3911. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3912. }
  3913. break;
  3914. }
  3915. }
  3916. }
  3917. else
  3918. {
  3919. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3920. {
  3921. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3922. compositePeriodIdx++;
  3923. }
  3924. else
  3925. {
  3926. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3927. }
  3928. }
  3929. }
  3930. }
  3931. }
  3932. }
  3933. }
  3934. }
  3935. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3936. else if(defaultTxProfile.ChargingProfileId != -1)
  3937. {
  3938. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3939. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3940. {
  3941. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3942. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3943. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3944. {
  3945. if(maxProfile.ChargingProfileId != -1)
  3946. {
  3947. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3948. {
  3949. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3950. {
  3951. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3952. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3953. if((maxProfile.ChargingSchedule.Duration > 0))
  3954. {
  3955. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3956. }
  3957. else
  3958. {
  3959. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3960. }
  3961. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3962. {
  3963. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3964. {
  3965. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3966. compositePeriodIdx++;
  3967. }
  3968. else
  3969. {
  3970. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3971. }
  3972. }
  3973. // Delete duplicate period
  3974. if(compositePeriodIdx > 1)
  3975. {
  3976. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3977. {
  3978. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3979. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3980. compositePeriodIdx -= 1;
  3981. }
  3982. }
  3983. }
  3984. else
  3985. {
  3986. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3987. {
  3988. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3989. compositePeriodIdx++;
  3990. }
  3991. else
  3992. {
  3993. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3994. }
  3995. break;
  3996. }
  3997. }
  3998. }
  3999. else
  4000. {
  4001. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4002. {
  4003. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4004. compositePeriodIdx++;
  4005. }
  4006. else
  4007. {
  4008. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4009. }
  4010. }
  4011. }
  4012. }
  4013. }
  4014. // Fill other period by MaxProfile
  4015. if(maxProfile.ChargingProfileId != -1)
  4016. {
  4017. if(compositePeriodIdx==0)
  4018. {
  4019. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  4020. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  4021. {
  4022. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  4023. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  4024. (maxProfile.ChargingSchedule.Duration > 0))
  4025. {
  4026. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4027. {
  4028. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  4029. compositePeriodIdx++;
  4030. }
  4031. else
  4032. {
  4033. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  4034. }
  4035. }
  4036. }
  4037. }
  4038. else
  4039. {
  4040. int lastCompositePeriodIdx = compositePeriodIdx;
  4041. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4042. {
  4043. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  4044. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  4045. (maxProfile.ChargingSchedule.Duration > 0))
  4046. {
  4047. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  4048. {
  4049. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  4050. {
  4051. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  4052. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  4053. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  4054. }
  4055. else
  4056. {
  4057. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  4058. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  4059. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  4060. }
  4061. }
  4062. if(tmpPeriod.Limit != -1)
  4063. {
  4064. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  4065. {
  4066. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  4067. {
  4068. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4069. compositePeriodIdx++;
  4070. }
  4071. else
  4072. {
  4073. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4074. }
  4075. }
  4076. // Delete duplicate period
  4077. if(compositePeriodIdx > 1)
  4078. {
  4079. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4080. {
  4081. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4082. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4083. compositePeriodIdx -= 1;
  4084. }
  4085. }
  4086. }
  4087. }
  4088. }
  4089. }
  4090. }
  4091. compositeProfile.ChargingSchedule.Duration = durationReq;
  4092. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  4093. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  4094. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  4095. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  4096. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  4097. {
  4098. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4099. {
  4100. compositeProfile.ChargingProfileId = 1;
  4101. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4102. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  4103. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4104. }
  4105. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  4106. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  4107. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  4108. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  4109. }
  4110. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  4111. if(line)
  4112. free(line);
  4113. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  4114. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  4115. }
  4116. //==========================================
  4117. // Init all share memory
  4118. //==========================================
  4119. int InitShareMemory()
  4120. {
  4121. int result = PASS;
  4122. int MeterSMId;
  4123. //creat ShmSysConfigAndInfo
  4124. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  4125. {
  4126. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  4127. result = FAIL;
  4128. }
  4129. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4130. {
  4131. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  4132. result = FAIL;
  4133. }
  4134. else
  4135. {}
  4136. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  4137. {
  4138. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  4139. result = FAIL;
  4140. }
  4141. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4142. {
  4143. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  4144. result = FAIL;
  4145. }
  4146. else
  4147. {}
  4148. //creat ShmPsuData
  4149. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  4150. {
  4151. DEBUG_ERROR("shmget ShmPsuData NG\n");
  4152. result = FAIL;
  4153. }
  4154. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4155. {
  4156. DEBUG_ERROR("shmat ShmPsuData NG\n");
  4157. result = FAIL;
  4158. }
  4159. else
  4160. {}
  4161. //creat ShmOCPP16Data
  4162. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  4163. {
  4164. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  4165. result = FAIL;
  4166. }
  4167. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4168. {
  4169. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  4170. result = FAIL;
  4171. }
  4172. else
  4173. {}
  4174. /****************************** For Initial Settings************************************************/
  4175. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  4176. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  4177. // allocate Configuration memory address
  4178. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  4179. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  4180. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  4181. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  4182. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  4183. //offline MeterValue Interval
  4184. TempMeterValueInterval = 0;
  4185. return result;
  4186. }
  4187. int ProcessShareMemory()
  4188. {
  4189. int result = PASS;
  4190. if(InitShareMemory() == FAIL)
  4191. {
  4192. DEBUG_ERROR("InitShareMemory NG\n");
  4193. if(ShmStatusCodeData!=NULL)
  4194. {
  4195. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  4196. }
  4197. result = FAIL;
  4198. }
  4199. // Model name parsing
  4200. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  4201. {
  4202. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  4203. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  4204. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  4205. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  4206. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  4207. ) // 'D' means DC
  4208. {
  4209. // DO series
  4210. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  4211. {
  4212. gunTotalNumber += 1;
  4213. gunType[gun_index] = GUN_TYPE_DO;
  4214. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4215. {
  4216. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  4217. {
  4218. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4219. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4220. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  4221. }
  4222. }
  4223. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4224. {
  4225. case Gun_Type_Chademo:
  4226. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  4227. break;
  4228. case Gun_Type_CCS_2:
  4229. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  4230. break;
  4231. case Gun_Type_GB:
  4232. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  4233. break;
  4234. case Gun_Type_AC:
  4235. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  4236. break;
  4237. default:
  4238. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  4239. break;
  4240. }
  4241. }
  4242. }
  4243. else
  4244. {
  4245. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  4246. {
  4247. gunTotalNumber += 1;
  4248. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4249. {
  4250. case Gun_Type_Chademo:
  4251. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  4252. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  4253. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  4254. {
  4255. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4256. {
  4257. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4258. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4259. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4260. }
  4261. }
  4262. break;
  4263. case Gun_Type_CCS_2:
  4264. gunType[gun_index] = GUN_TYPE_CCS;
  4265. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4266. for (int index = 0; index < CCS_QUANTITY; index++)
  4267. {
  4268. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4269. {
  4270. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4271. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4272. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4273. }
  4274. }
  4275. break;
  4276. case Gun_Type_GB:
  4277. gunType[gun_index] = GUN_TYPE_GBT;
  4278. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4279. for (int index = 0; index < GB_QUANTITY; index++)
  4280. {
  4281. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4282. {
  4283. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4284. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4285. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4286. }
  4287. }
  4288. break;
  4289. case Gun_Type_AC:
  4290. gunType[gun_index] = GUN_TYPE_AC;
  4291. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4292. for (int index = 0; index < AC_QUANTITY; index++)
  4293. {
  4294. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4295. {
  4296. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4297. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4298. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4299. }
  4300. }
  4301. break;
  4302. default:
  4303. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4304. break;
  4305. }
  4306. }
  4307. }
  4308. }
  4309. else
  4310. {
  4311. DEBUG_ERROR("Model name parsing fail.\n");
  4312. result = FAIL;
  4313. }
  4314. if(result != PASS)sleep(5);
  4315. return result;
  4316. }
  4317. void checkRemoteStart(uint8_t connectorIdInt)
  4318. {
  4319. uint8_t tempIndex;
  4320. int result = PASS;
  4321. char cmdBuf[512];
  4322. //check Transaction active
  4323. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4324. {
  4325. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4326. {
  4327. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4328. }
  4329. else
  4330. {
  4331. tempIndex = connectorIdInt -1;
  4332. }
  4333. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4334. {
  4335. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4336. {
  4337. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4338. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4339. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4340. {
  4341. //Reserved
  4342. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4343. }
  4344. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4345. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4346. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4347. {
  4348. //Reserved
  4349. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4350. result = FAIL;
  4351. goto end;
  4352. }
  4353. else
  4354. {
  4355. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4356. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4357. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4358. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4359. {
  4360. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4361. result = FAIL;
  4362. goto end;
  4363. }
  4364. }//END FOR ELSE
  4365. }
  4366. }// END FOR CHAdeMO_QUANTITY
  4367. }
  4368. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4369. {
  4370. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4371. {
  4372. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4373. }
  4374. else
  4375. {
  4376. tempIndex = connectorIdInt -1;
  4377. }
  4378. for (int index = 0; index < CCS_QUANTITY; index++)
  4379. {
  4380. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4381. {
  4382. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4383. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4384. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4385. {
  4386. //Reserved
  4387. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4388. }
  4389. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4390. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4391. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4392. {
  4393. //Reserved
  4394. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4395. result = FAIL;
  4396. goto end;
  4397. }
  4398. else
  4399. {
  4400. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4401. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4402. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4403. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4404. {
  4405. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4406. result = FAIL;
  4407. goto end;
  4408. }
  4409. }// END FOR ELSE
  4410. }
  4411. }// END FOR CCS_QUANTITY
  4412. }
  4413. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4414. {
  4415. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4416. {
  4417. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4418. }
  4419. else
  4420. {
  4421. tempIndex = connectorIdInt -1;
  4422. }
  4423. for (int index = 0; index < GB_QUANTITY; index++)
  4424. {
  4425. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4426. {
  4427. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4428. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4429. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4430. {
  4431. //Reserved
  4432. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4433. }
  4434. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4435. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4436. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4437. {
  4438. //Reserved
  4439. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4440. result = FAIL;
  4441. goto end;
  4442. }
  4443. else
  4444. {
  4445. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4446. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4447. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4448. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4449. {
  4450. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4451. result = FAIL;
  4452. goto end;
  4453. }
  4454. }// END FOR ELSE
  4455. }
  4456. } // END FOR GB_QUANTITY
  4457. }
  4458. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4459. {
  4460. tempIndex = connectorIdInt -1;
  4461. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4462. {
  4463. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4464. {
  4465. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4466. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4467. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4468. {
  4469. //Reserved
  4470. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4471. }
  4472. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4473. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4474. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4475. {
  4476. //Reserved
  4477. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4478. result = FAIL;
  4479. goto end;
  4480. }
  4481. else
  4482. {
  4483. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4484. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4485. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4486. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4487. {
  4488. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4489. result = FAIL;
  4490. goto end;
  4491. }
  4492. }// END FOR ELSE
  4493. }
  4494. } // END FOR GB_QUANTITY
  4495. }
  4496. else
  4497. {
  4498. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4499. {
  4500. tempIndex = 2;
  4501. }
  4502. else
  4503. {
  4504. tempIndex = connectorIdInt -1;
  4505. }
  4506. for (int index = 0; index < AC_QUANTITY; index++)
  4507. {
  4508. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4509. {
  4510. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4511. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4512. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4513. {
  4514. //Reserved
  4515. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4516. }
  4517. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4518. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4519. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4520. {
  4521. //Reserved
  4522. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4523. result = FAIL;
  4524. goto end;
  4525. }
  4526. else
  4527. {
  4528. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4529. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4530. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4531. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4532. {
  4533. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4534. result = FAIL;
  4535. goto end;
  4536. }
  4537. }//END FOR ELSE
  4538. }
  4539. }// END FOR AC_QUANTITY
  4540. }
  4541. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4542. {
  4543. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4544. {
  4545. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4546. {
  4547. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4548. system(cmdBuf);
  4549. }
  4550. }
  4551. else
  4552. {
  4553. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4554. result = FAIL;
  4555. }
  4556. }
  4557. end:
  4558. if(result == PASS)
  4559. {
  4560. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4561. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4562. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4563. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4564. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4565. }
  4566. }
  4567. int isConnector0Unavailable()
  4568. {
  4569. uint8_t result = YES;
  4570. uint8_t tempIndex;
  4571. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4572. {
  4573. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4574. {
  4575. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4576. {
  4577. tempIndex = ((gun_index==2) ? 1: 0);
  4578. }
  4579. else
  4580. {
  4581. tempIndex = gun_index;
  4582. }
  4583. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4584. {
  4585. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4586. {
  4587. 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))
  4588. {
  4589. result = NO;
  4590. }
  4591. }
  4592. }
  4593. }
  4594. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4595. {
  4596. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4597. {
  4598. tempIndex = ((gun_index==2) ? 1: 0);
  4599. }
  4600. else
  4601. {
  4602. tempIndex = gun_index;
  4603. }
  4604. for (int index = 0; index < CCS_QUANTITY; index++)
  4605. {
  4606. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4607. {
  4608. 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))
  4609. {
  4610. result = NO;
  4611. }
  4612. }
  4613. }
  4614. }
  4615. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4616. {
  4617. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4618. {
  4619. tempIndex = ((gun_index==2) ? 1: 0);
  4620. }
  4621. else
  4622. {
  4623. tempIndex = gun_index;
  4624. }
  4625. for (int index = 0; index < GB_QUANTITY; index++)
  4626. {
  4627. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4628. {
  4629. 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))
  4630. {
  4631. result = NO;
  4632. }
  4633. }
  4634. }
  4635. }
  4636. else if(gunType[gun_index] == GUN_TYPE_DO)
  4637. {
  4638. tempIndex = gun_index;
  4639. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4640. {
  4641. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4642. {
  4643. 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))
  4644. {
  4645. result = NO;
  4646. }
  4647. }
  4648. }
  4649. }
  4650. else
  4651. {
  4652. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4653. {
  4654. tempIndex = 2;
  4655. }
  4656. else
  4657. {
  4658. tempIndex = gun_index;
  4659. }
  4660. for (int index = 0; index < AC_QUANTITY; index++)
  4661. {
  4662. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4663. {
  4664. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].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))
  4665. {
  4666. result = NO;
  4667. }
  4668. }
  4669. }// END
  4670. }
  4671. }
  4672. return result;
  4673. }
  4674. void CheckSystemValue(void)
  4675. {
  4676. char filenmae[100]={0};
  4677. char str[100]={0};
  4678. int tempIndex = 0;
  4679. //===============================
  4680. // send Heartbeat
  4681. //===============================
  4682. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4683. {
  4684. //parameter for test
  4685. sendHeartbeatRequest(0);
  4686. //===========================
  4687. // Reset Waiting Time
  4688. //===========================
  4689. HeartBeatWithNOResponse += 1;
  4690. }
  4691. //===============================
  4692. // Tcci credit deduct report
  4693. //===============================
  4694. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4695. {
  4696. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4697. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4698. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4699. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4700. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4701. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4702. }
  4703. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[0].DataTransferReq != TRUE) && getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4704. {
  4705. OCPP_query_deduct_info();
  4706. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4707. }
  4708. if(ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq)
  4709. {
  4710. OCPP_insert_occupancyDeduct_info((char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.occupancySN, (char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.creditNo,
  4711. ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.deductResult, ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.amount,
  4712. (char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.approvalNo);
  4713. ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq = FALSE;
  4714. }
  4715. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[0].DataTransferReq != TRUE) && getDiffSecNow(clientTime.TcciQueryOccupancyDeduct) > 5)
  4716. {
  4717. OCPP_query_occupancyDeduct_info();
  4718. refreshStartTimer(&clientTime.TcciQueryOccupancyDeduct);
  4719. }
  4720. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4721. {
  4722. // ClockAlign MeterValue
  4723. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4724. {
  4725. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4726. {
  4727. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4728. {
  4729. tempIndex = ((gun_index==2) ? 1: 0);
  4730. }
  4731. else
  4732. {
  4733. tempIndex = gun_index;
  4734. }
  4735. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4736. {
  4737. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4738. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4739. {
  4740. reqClockAlignMeter[gun_index] = 1;
  4741. }
  4742. }// End for CHAdeMO
  4743. }
  4744. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4745. {
  4746. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4747. {
  4748. tempIndex = ((gun_index==2) ? 1: 0);
  4749. }
  4750. else
  4751. {
  4752. tempIndex = gun_index;
  4753. }
  4754. for (int index = 0; index < CCS_QUANTITY; index++)
  4755. {
  4756. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4757. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4758. {
  4759. reqClockAlignMeter[gun_index] = 1;
  4760. }
  4761. } // End for CCS
  4762. }
  4763. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4764. {
  4765. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4766. {
  4767. tempIndex = ((gun_index==2) ? 1: 0);
  4768. }
  4769. else
  4770. {
  4771. tempIndex = gun_index;
  4772. }
  4773. for (int index = 0; index < GB_QUANTITY; index++)
  4774. {
  4775. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4776. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4777. {
  4778. reqClockAlignMeter[gun_index] = 1;
  4779. }
  4780. }// End for GB
  4781. }
  4782. else if(gunType[gun_index] == GUN_TYPE_DO)
  4783. {
  4784. tempIndex = gun_index;
  4785. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4786. {
  4787. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4788. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4789. {
  4790. reqClockAlignMeter[gun_index] = 1;
  4791. }
  4792. }
  4793. }
  4794. else
  4795. {
  4796. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4797. {
  4798. tempIndex = 2;
  4799. }
  4800. else
  4801. {
  4802. tempIndex = gun_index;
  4803. }
  4804. for (int index = 0; index < AC_QUANTITY; index++)
  4805. {
  4806. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4807. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4808. {
  4809. reqClockAlignMeter[gun_index] = 1;
  4810. }
  4811. }//End for AC
  4812. }
  4813. }
  4814. }
  4815. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4816. {
  4817. //==========================================
  4818. // Check remote start without connector id
  4819. //==========================================
  4820. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4821. {
  4822. int connectorIdInt = -1;
  4823. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4824. {
  4825. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4826. {
  4827. connectorIdInt = (gun_index+1);
  4828. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4829. checkRemoteStart(connectorIdInt);
  4830. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4831. break;
  4832. }
  4833. }
  4834. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4835. {
  4836. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4837. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4838. }
  4839. }
  4840. //==========================================
  4841. // csu trigger DataTransferReq
  4842. //==========================================
  4843. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4844. {
  4845. sendDataTransferRequest(gun_index);
  4846. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4847. }
  4848. //==========================================
  4849. // CSU Trigger Authorize Request
  4850. //==========================================
  4851. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4852. {
  4853. sendAuthorizeRequest(0);
  4854. authorizeRetryTimes = authorizeRetryTimes + 1;
  4855. if(authorizeRetryTimes < 3)
  4856. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4857. }
  4858. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4859. {
  4860. authorizeRetryTimes = 0;
  4861. SetOcppConnStatus(FALSE);
  4862. server_sign = FALSE;
  4863. }
  4864. 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))
  4865. {
  4866. sendAuthorizeRequest(0);
  4867. }
  4868. //==========================================
  4869. // Charger start transaction
  4870. //==========================================
  4871. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4872. {
  4873. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4874. sendStartTransactionRequest(gun_index);
  4875. refreshStartTimer(&clientTime.StartTransaction);
  4876. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4877. storeTempStopTransaction(gun_index);
  4878. }
  4879. //==========================================
  4880. // Charger stop transaction
  4881. //==========================================
  4882. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4883. {
  4884. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4885. sendStopTransactionRequest(gun_index);
  4886. OCPP_updatePeriodEnergy(gun_index);
  4887. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4888. refreshStartTimer(&clientTime.StopTransaction);
  4889. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4890. }
  4891. //==========================================
  4892. // Charger OCMF message
  4893. //==========================================
  4894. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq == 1)))
  4895. {
  4896. sendOcmfByDataTransferRequest(gun_index);
  4897. ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq = 0;
  4898. }
  4899. //==========================================
  4900. // Charger status report
  4901. //==========================================
  4902. //--- Check Mode Change ---//
  4903. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4904. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4905. {
  4906. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4907. {
  4908. tempIndex = ((gun_index==2) ? 1: 0);
  4909. }
  4910. else
  4911. {
  4912. tempIndex = gun_index;
  4913. }
  4914. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4915. {
  4916. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4917. {
  4918. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4919. {
  4920. // Sent unplug message for California pricing logic
  4921. 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])
  4922. {
  4923. uint8_t ts[36];
  4924. getNowDatetime(ts);
  4925. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4926. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4927. if(strcmp((char*)dmsVersion, "2.0")==0)
  4928. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4929. else
  4930. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4931. sendUnplugByDataTransferRequest(gun_index);
  4932. interLock.isSentUnplug[gun_index] = 1;
  4933. }
  4934. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4935. {
  4936. interLock.isSentUnplug[gun_index] = 0;
  4937. }
  4938. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4939. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4940. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4941. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4942. {
  4943. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4944. if((access(filenmae,F_OK))!=-1)
  4945. {
  4946. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4947. sprintf(str,"rm -f %s",filenmae);
  4948. system(str);
  4949. }
  4950. }
  4951. }
  4952. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4953. #if 1 // for TempStopTransaction
  4954. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4955. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4956. {
  4957. checkTempStopTransaction(gun_index);
  4958. }
  4959. #endif
  4960. }
  4961. }
  4962. }
  4963. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4964. {
  4965. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4966. {
  4967. tempIndex = ((gun_index==2) ? 1: 0);
  4968. }
  4969. else
  4970. {
  4971. tempIndex = gun_index;
  4972. }
  4973. for (int index = 0; index < CCS_QUANTITY; index++)
  4974. {
  4975. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4976. {
  4977. 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]*/ )
  4978. {
  4979. // Sent unplug message for California pricing logic
  4980. 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])
  4981. {
  4982. uint8_t ts[36];
  4983. getNowDatetime(ts);
  4984. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4985. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4986. if(strcmp((char*)dmsVersion, "2.0")==0)
  4987. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4988. else
  4989. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4990. sendUnplugByDataTransferRequest(gun_index);
  4991. interLock.isSentUnplug[gun_index] = 1;
  4992. }
  4993. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4994. {
  4995. interLock.isSentUnplug[gun_index] = 0;
  4996. }
  4997. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4998. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4999. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5000. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5001. {
  5002. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5003. if((access(filenmae,F_OK))!=-1)
  5004. {
  5005. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5006. sprintf(str,"rm -f %s",filenmae);
  5007. system(str);
  5008. }
  5009. }
  5010. }
  5011. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5012. #if 1 // for TempStopTransaction
  5013. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5014. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5015. {
  5016. checkTempStopTransaction(gun_index);
  5017. }
  5018. #endif
  5019. }
  5020. }
  5021. }
  5022. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5023. {
  5024. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5025. {
  5026. tempIndex = ((gun_index==2) ? 1: 0);
  5027. }
  5028. else
  5029. {
  5030. tempIndex = gun_index;
  5031. }
  5032. for (int index = 0; index < GB_QUANTITY; index++)
  5033. {
  5034. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5035. {
  5036. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  5037. {
  5038. // Sent unplug message for California pricing logic
  5039. 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])
  5040. {
  5041. uint8_t ts[36];
  5042. getNowDatetime(ts);
  5043. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5044. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5045. if(strcmp((char*)dmsVersion, "2.0")==0)
  5046. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5047. else
  5048. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5049. sendUnplugByDataTransferRequest(gun_index);
  5050. interLock.isSentUnplug[gun_index] = 1;
  5051. }
  5052. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5053. {
  5054. interLock.isSentUnplug[gun_index] = 0;
  5055. }
  5056. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  5057. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  5058. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5059. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5060. {
  5061. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5062. if((access(filenmae,F_OK))!=-1)
  5063. {
  5064. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5065. sprintf(str,"rm -f %s",filenmae);
  5066. system(str);
  5067. }
  5068. }
  5069. }
  5070. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5071. #if 1 // for TempStopTransaction
  5072. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5073. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5074. {
  5075. checkTempStopTransaction(gun_index);
  5076. }
  5077. #endif
  5078. }
  5079. }
  5080. }
  5081. else if(gunType[gun_index] == GUN_TYPE_DO)
  5082. {
  5083. tempIndex = gun_index;
  5084. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5085. {
  5086. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5087. {
  5088. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  5089. {
  5090. // Sent unplug message for California pricing logic
  5091. 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])
  5092. {
  5093. uint8_t ts[36];
  5094. getNowDatetime(ts);
  5095. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5096. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5097. if(strcmp((char*)dmsVersion, "2.0")==0)
  5098. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5099. else
  5100. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5101. sendUnplugByDataTransferRequest(gun_index);
  5102. interLock.isSentUnplug[gun_index] = 1;
  5103. }
  5104. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  5105. {
  5106. interLock.isSentUnplug[gun_index] = 0;
  5107. }
  5108. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  5109. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  5110. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5111. 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
  5112. {
  5113. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5114. if((access(filenmae,F_OK))!=-1)
  5115. {
  5116. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5117. sprintf(str,"rm -f %s",filenmae);
  5118. system(str);
  5119. }
  5120. }
  5121. }
  5122. 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);
  5123. #if 1 // for TempStopTransaction
  5124. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  5125. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5126. {
  5127. checkTempStopTransaction(gun_index);
  5128. }
  5129. #endif
  5130. }
  5131. }
  5132. }
  5133. else
  5134. {
  5135. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5136. {
  5137. tempIndex = 2;
  5138. }
  5139. else
  5140. {
  5141. tempIndex = gun_index;
  5142. }
  5143. for (int index = 0; index < AC_QUANTITY; index++)
  5144. {
  5145. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5146. {
  5147. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  5148. {
  5149. // Sent unplug message for California pricing logic
  5150. 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])
  5151. {
  5152. uint8_t ts[36];
  5153. getNowDatetime(ts);
  5154. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5155. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5156. if(strcmp((char*)dmsVersion, "2.0")==0)
  5157. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5158. else
  5159. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5160. sendUnplugByDataTransferRequest(gun_index);
  5161. interLock.isSentUnplug[gun_index] = 1;
  5162. }
  5163. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5164. {
  5165. interLock.isSentUnplug[gun_index] = 0;
  5166. }
  5167. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  5168. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  5169. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5170. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5171. {
  5172. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5173. if((access(filenmae,F_OK))!=-1)
  5174. {
  5175. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5176. sprintf(str,"rm -f %s",filenmae);
  5177. system(str);
  5178. }
  5179. }
  5180. }
  5181. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5182. #if 1 // for TempStopTransaction
  5183. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5184. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5185. {
  5186. checkTempStopTransaction(gun_index);
  5187. }
  5188. #endif
  5189. }
  5190. }// END
  5191. }
  5192. if(isWebsocketSendable && (server_sign == TRUE) && (isConnector0Unavailable() != Connector0PreviousSystemStatus))
  5193. {
  5194. sendConnector0StatusNotificationRequest();
  5195. Connector0PreviousSystemStatus = isConnector0Unavailable();
  5196. }
  5197. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf != 1) &&
  5198. (
  5199. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  5200. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  5201. )
  5202. )
  5203. {
  5204. sendStatusNotificationRequest(gun_index);
  5205. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  5206. }
  5207. //==============================================
  5208. // TCCI related DataTransfer messages
  5209. //==============================================
  5210. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  5211. {
  5212. reportReaderStatus(gun_index);
  5213. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  5214. }
  5215. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.GetOccupancyFee[gun_index].GetOccupancyFeeReq == 1))
  5216. {
  5217. getOccupancyFee(gun_index);
  5218. }
  5219. //==============================================
  5220. // CSU Trigger or timer timeout refresh Smart Charging Profile
  5221. //==============================================
  5222. if((ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  5223. ((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))))
  5224. {
  5225. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  5226. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  5227. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  5228. }
  5229. //==============================================
  5230. // Meter report
  5231. //==============================================
  5232. // Trigger MeterValue
  5233. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  5234. {
  5235. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  5236. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  5237. }
  5238. // Clock-aligned Meter value
  5239. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  5240. {
  5241. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  5242. reqClockAlignMeter[gun_index] = 0;
  5243. }
  5244. // Sample period MeterValue
  5245. 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))))
  5246. {
  5247. //check Transaction active
  5248. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5249. {
  5250. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5251. {
  5252. tempIndex = ((gun_index==2) ? 1: 0);
  5253. }
  5254. else
  5255. {
  5256. tempIndex = gun_index;
  5257. }
  5258. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5259. {
  5260. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5261. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5262. {
  5263. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5264. {
  5265. reqSampleMeter[gun_index] = 1;
  5266. }
  5267. }
  5268. }// End for CHAdeMO
  5269. }
  5270. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5271. {
  5272. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5273. {
  5274. tempIndex = ((gun_index==2) ? 1: 0);
  5275. }
  5276. else
  5277. {
  5278. tempIndex = gun_index;
  5279. }
  5280. for (int index = 0; index < CCS_QUANTITY; index++)
  5281. {
  5282. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5283. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5284. {
  5285. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5286. {
  5287. reqSampleMeter[gun_index] = 1;
  5288. }
  5289. }
  5290. } // End for CCS
  5291. }
  5292. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5293. {
  5294. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5295. {
  5296. tempIndex = ((gun_index==2) ? 1: 0);
  5297. }
  5298. else
  5299. {
  5300. tempIndex = gun_index;
  5301. }
  5302. for (int index = 0; index < GB_QUANTITY; index++)
  5303. {
  5304. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5305. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5306. {
  5307. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5308. {
  5309. reqSampleMeter[gun_index] = 1;
  5310. }
  5311. }
  5312. }// End for GB
  5313. }
  5314. else if(gunType[gun_index] == GUN_TYPE_DO)
  5315. {
  5316. tempIndex = gun_index;
  5317. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5318. {
  5319. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5320. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5321. {
  5322. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  5323. {
  5324. reqSampleMeter[gun_index] = 1;
  5325. }
  5326. }
  5327. }
  5328. }
  5329. else
  5330. {
  5331. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5332. {
  5333. tempIndex = 2;
  5334. }
  5335. else
  5336. {
  5337. tempIndex = gun_index;
  5338. }
  5339. for (int index = 0; index < AC_QUANTITY; index++)
  5340. {
  5341. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5342. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5343. {
  5344. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  5345. {
  5346. reqSampleMeter[gun_index] = 1;
  5347. }
  5348. }
  5349. }//End for AC
  5350. }
  5351. if(reqSampleMeter[gun_index] == 1)
  5352. {
  5353. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  5354. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  5355. storeTempStopTransaction(gun_index);
  5356. reqSampleMeter[gun_index] = 0;
  5357. }
  5358. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5359. }
  5360. //==============================================
  5361. // Check Connector reserved
  5362. //==============================================
  5363. //===============================
  5364. // Check if Reserve is expired
  5365. //===============================
  5366. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  5367. {
  5368. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  5369. {
  5370. DEBUG_INFO("reserve expired.\n");
  5371. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  5372. }
  5373. }//END OF Check if Reserve is expired
  5374. //==========================================
  5375. // csu trigger FirmwareStatusNotificationReq
  5376. //==========================================
  5377. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  5378. {
  5379. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  5380. }
  5381. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq == 1))
  5382. {
  5383. sendSignedFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status);
  5384. }
  5385. //==========================================
  5386. // csu trigger DiagnosticsStatusNotificationReq
  5387. //==========================================
  5388. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  5389. {
  5390. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  5391. }
  5392. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq == 1))
  5393. {
  5394. sendLogStatusNotificationRequest((char *)ShmOCPP16Data->LogStatusNotification.status);
  5395. }
  5396. //==========================================
  5397. // csu trigger CancelReservationConf
  5398. //==========================================
  5399. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  5400. {
  5401. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  5402. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  5403. }
  5404. //==========================================
  5405. // csu trigger ChangeAvailabilityConf
  5406. //==========================================
  5407. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  5408. {
  5409. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  5410. }
  5411. //==========================================
  5412. // csu trigger UnlockConnectorConf
  5413. //==========================================
  5414. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  5415. {
  5416. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5417. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5418. }
  5419. //==========================================
  5420. // csu trigger ReserveNowConf
  5421. //==========================================
  5422. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5423. {
  5424. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5425. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5426. }
  5427. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access(CSR_CP,F_OK) != -1))
  5428. {
  5429. sendSignCertificateRequest();
  5430. }
  5431. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq == 1))
  5432. {
  5433. sendSecurityEventNotificationRequest();
  5434. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5435. }
  5436. // Support 15118
  5437. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.SignCertificateReq == 1) && (access(CSR_V2G,F_OK) != -1))
  5438. {
  5439. json_object *data = json_object_new_object();
  5440. // Read csr file content
  5441. memset(ShmOCPP16Data->v2g_extend.SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5442. FILE *fp=fopen(CSR_V2G,"r");
  5443. char *line = NULL;
  5444. size_t len = 0;
  5445. while(getline(&line, &len, fp) != -1)
  5446. {
  5447. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5448. {
  5449. memcpy(&ShmOCPP16Data->v2g_extend.SignCertificate.csr[strlen((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr)], line, (strlen(line)-1));
  5450. }
  5451. }
  5452. fclose(fp);
  5453. json_object_object_add(data, "csr", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5454. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5455. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"SignCertificate");
  5456. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5457. json_object_put(data);
  5458. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5459. ShmOCPP16Data->v2g_extend.SignCertificateReq = 0;
  5460. }
  5461. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.AuthorizeReq == 1))
  5462. {
  5463. memset(&ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo,0,sizeof(struct IdTokenInfoType));
  5464. int parseCertResult = FAIL;
  5465. json_object *data = json_object_new_object();
  5466. json_object *idToken = json_object_new_object();
  5467. json_object *iso15118CertificateHashData = json_object_new_array();
  5468. // Read CERTIFICATE_PnCAuth file content
  5469. if(access(CERTIFICATE_PnCAuth,F_OK) != -1)
  5470. {
  5471. memset(ShmOCPP16Data->v2g_extend.Authorize.certificate, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5472. FILE *fp=fopen(CERTIFICATE_PnCAuth,"r");
  5473. char *line = NULL;
  5474. size_t len = 0;
  5475. while(getline(&line, &len, fp) != -1)
  5476. {
  5477. //memcpy(&ShmOCPP16Data->v2g_extend.Authorize.certificate[strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate)], line, (strlen(line)-1));
  5478. strcat((char *)ShmOCPP16Data->v2g_extend.Authorize.certificate, line);
  5479. }
  5480. fclose(fp);
  5481. }
  5482. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate) > 0)
  5483. json_object_object_add(data, "certificate", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5484. //strcpy((char *)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5485. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken));
  5486. json_object_object_add(data, "idToken", idToken);
  5487. char parseData[512] = {0};
  5488. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  5489. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].hashAlgorithm, parseData);
  5490. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_SerialNumber, parseData) == PASS)
  5491. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].serialNumber, parseData);
  5492. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  5493. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerNameHash, parseData);
  5494. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  5495. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerKeyHash, parseData);
  5496. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_OcspUrl, parseData) == PASS && strlen((char*)parseData) >= 7)
  5497. strcpy((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].responderURL, parseData);
  5498. for(int idx=0; idx < 4; idx++)
  5499. {
  5500. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm) > 0)
  5501. {
  5502. json_object *OCSPRequestDataType = json_object_new_object();
  5503. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm));
  5504. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerNameHash));
  5505. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerKeyHash));
  5506. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].serialNumber));
  5507. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].responderURL));
  5508. json_object_array_add(iso15118CertificateHashData, OCSPRequestDataType);
  5509. parseCertResult = PASS;
  5510. }
  5511. }
  5512. if(parseCertResult == PASS)
  5513. {
  5514. json_object_object_add(data, "iso15118CertificateHashData", iso15118CertificateHashData);
  5515. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5516. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Authorize");
  5517. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5518. json_object_put(data);
  5519. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5520. ShmOCPP16Data->v2g_extend.AuthorizeReq = 0;
  5521. }
  5522. else
  5523. {
  5524. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "NoCertificateAvailable");
  5525. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.status, "Invalid");
  5526. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  5527. }
  5528. }
  5529. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq == 1))
  5530. {
  5531. json_object *data = json_object_new_object();
  5532. json_object_object_add(data, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.iso15118SchemaVersion));
  5533. json_object_object_add(data, "action", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.action));
  5534. json_object_object_add(data, "exiRequest", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.exiRequest));
  5535. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5536. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Get15118EVCertificate");
  5537. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5538. json_object_put(data);
  5539. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5540. ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq = 0;
  5541. }
  5542. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.GetCertificateStatusReq == 1))
  5543. {
  5544. json_object *data = json_object_new_object();
  5545. json_object *OCSPRequestDataType = json_object_new_object();
  5546. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.hashAlgorithm));
  5547. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerNameHash));
  5548. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerKeyHash));
  5549. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.serialNumber));
  5550. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.responderURL));
  5551. json_object_object_add(data, "ocspRequestData", OCSPRequestDataType);
  5552. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5553. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"GetInstalledCertificateIds");
  5554. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5555. json_object_put(data);
  5556. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5557. ShmOCPP16Data->v2g_extend.GetCertificateStatusReq = 0;
  5558. }
  5559. }
  5560. }
  5561. //==========================================
  5562. // send request routine
  5563. //==========================================
  5564. int sendAuthorizeRequest(int gun_index)
  5565. {
  5566. mtrace();
  5567. int result = FAIL;
  5568. char message[100]={0};
  5569. char guid[37];
  5570. char tempdata[65]={0};
  5571. DEBUG_INFO("sendAuthorizeRequest...\n");
  5572. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5573. //Local Authorize
  5574. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5575. {
  5576. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5577. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5578. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5579. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5580. result = PASS;
  5581. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5582. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5583. authorizeRetryTimes = 0;
  5584. return result;
  5585. }
  5586. 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))||
  5587. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5588. {
  5589. // Query from cache
  5590. DEBUG_INFO("Authorize from cache.\n");
  5591. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5592. // Query from list
  5593. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strstr(idTagQuery.idTagstatus,"Accepted") == NULL) )
  5594. {
  5595. DEBUG_INFO("Authorize from list.\n");
  5596. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5597. }
  5598. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strstr(idTagQuery.idTagstatus,"Accepted") == NULL) )
  5599. {
  5600. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5601. {
  5602. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5603. }
  5604. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5605. {
  5606. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5607. }
  5608. if(!GetOcppConnStatus())
  5609. {
  5610. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5611. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5612. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5613. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5614. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5615. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5616. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5617. authorizeRetryTimes = 0;
  5618. return result;
  5619. }
  5620. }
  5621. else
  5622. {
  5623. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5624. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5625. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5626. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5627. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5628. else
  5629. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5630. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5631. result = PASS;
  5632. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5633. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5634. authorizeRetryTimes = 0;
  5635. return result;
  5636. }
  5637. }
  5638. //initialize struct Authorize
  5639. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5640. //get data from shared memory
  5641. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5642. random_uuid(guid);
  5643. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5644. LWS_Send(message);
  5645. sprintf(tempdata, "Authorize,%d", gun_index);
  5646. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5647. {
  5648. result = PASS;
  5649. DEBUG_INFO("Authorize mapItem pass\n");
  5650. }
  5651. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5652. return result;
  5653. }
  5654. int sendBootNotificationRequest(void)
  5655. {
  5656. mtrace();
  5657. int result = FAIL;
  5658. char message[500]={0}, payload[700]={0};
  5659. char guid[37]={0};
  5660. char tempdata[65]={0};
  5661. // Fill BootNotification fields
  5662. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5663. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5664. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5665. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5666. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5667. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5668. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5669. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5670. ShmOCPP16Data->ChargeBoxId
  5671. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5672. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5673. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5674. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5675. ,ShmOCPP16Data->BootNotification.CpIccid
  5676. ,ShmOCPP16Data->BootNotification.CpImsi);
  5677. random_uuid(guid);
  5678. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5679. LWS_Send(message);
  5680. sprintf(tempdata, "BootNotification,0");
  5681. 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*/)
  5682. {
  5683. result = PASS;
  5684. }
  5685. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5686. strcpy(queuedata,message);
  5687. return result;
  5688. }
  5689. int sendDataTransferRequest(int gun_index)
  5690. {
  5691. mtrace();
  5692. char message[10240]={0};
  5693. char guid[37]={0};
  5694. char tempdata[65]={0};
  5695. int result = FAIL;
  5696. json_object *DataTransfer = json_object_new_object();
  5697. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5698. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5699. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].Data));
  5700. random_uuid(guid);
  5701. sprintf(message,"[%d,\"%s\",\"DataTransfer\",%s]", MESSAGE_TYPE_CALL,
  5702. guid,
  5703. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5704. json_object_put(DataTransfer);
  5705. LWS_Send(message);
  5706. sprintf(tempdata, "DataTransfer,%d", gun_index);
  5707. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5708. {
  5709. result = PASS;
  5710. DEBUG_INFO("DataTransfer mapItem pass\n");
  5711. }
  5712. return result;
  5713. }
  5714. int sendUnplugByDataTransferRequest(int gun_index)
  5715. {
  5716. mtrace();
  5717. char message[10752]={0};
  5718. char guid[37]={0};
  5719. char tempdata[65]={0};
  5720. int result = FAIL;
  5721. random_uuid(guid);
  5722. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5723. (gun_index+1),
  5724. MESSAGE_TYPE_CALL,
  5725. guid,
  5726. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5727. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5728. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5729. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5730. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5731. {
  5732. result = PASS;
  5733. DEBUG_INFO("DataTransfer mapItem pass\n");
  5734. }
  5735. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5736. return result;
  5737. }
  5738. int sendOcmfByDataTransferRequest(int gun_index)
  5739. {
  5740. mtrace();
  5741. json_object *DataTransfer = json_object_new_object();
  5742. json_object *data = json_object_new_object();
  5743. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5744. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ID_OCMF");
  5745. json_object_object_add(data, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  5746. json_object_object_add(data, "dataString", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].DataString));
  5747. json_object_object_add(data, "publicKey", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].PublicKey));
  5748. json_object_object_add(DataTransfer, "data", data);
  5749. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5750. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5751. char message[3000]={0};
  5752. char guid[37]={0};
  5753. char tempdata[65]={0};
  5754. int result = FAIL;
  5755. random_uuid(guid);
  5756. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",%s]",
  5757. (gun_index+1),
  5758. MESSAGE_TYPE_CALL,
  5759. guid,
  5760. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5761. json_object_put(DataTransfer);
  5762. sprintf(tempdata, "DataTransfer,%d", gun_index );
  5763. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5764. {
  5765. result = PASS;
  5766. DEBUG_INFO("DataTransfer mapItem pass\n");
  5767. }
  5768. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5769. return result;
  5770. }
  5771. int sendDiagnosticsStatusNotificationRequest(char *status)
  5772. {
  5773. mtrace();
  5774. int result = FAIL;
  5775. char message[110]={0};
  5776. char guid[37]={0};
  5777. char tempdata[65]={0};
  5778. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5779. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5780. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5781. random_uuid(guid);
  5782. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5783. LWS_SendNow(message);
  5784. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5785. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5786. {
  5787. result = PASS;
  5788. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5789. }
  5790. //#ifdef SystemLogMessage
  5791. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5792. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5793. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5794. //#endif
  5795. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5796. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5797. //record status
  5798. if(strcmp(status,"Idle")==0)
  5799. {
  5800. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5801. }
  5802. else if(strcmp(status,"Uploaded")==0)
  5803. {
  5804. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5805. }
  5806. else if(strcmp(status,"UploadFailed")==0)
  5807. {
  5808. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5809. }
  5810. else if(strcmp(status,"Uploading")==0)
  5811. {
  5812. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5813. }
  5814. return result;
  5815. }
  5816. int sendFirmwareStatusNotificationRequest(char *status)
  5817. {
  5818. mtrace();
  5819. int result = FAIL;
  5820. char message[110]={0};
  5821. char guid[37]={0};
  5822. char tempdata[65]={0};
  5823. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5824. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5825. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5826. random_uuid(guid);
  5827. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5828. LWS_SendNow(message);
  5829. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5830. 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*/)
  5831. {
  5832. result = PASS;
  5833. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5834. }
  5835. //#ifdef SystemLogMessage
  5836. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5837. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5838. //#endif
  5839. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5840. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5841. //record status
  5842. if(strcmp(status,"Downloaded")==0)
  5843. {
  5844. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  5845. }
  5846. else if(strcmp(status,"DownloadFailed")==0)
  5847. {
  5848. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  5849. }
  5850. else if(strcmp(status,"Downloading")==0)
  5851. {
  5852. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  5853. }
  5854. else if(strcmp(status,"Idle")==0)
  5855. {
  5856. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  5857. }
  5858. else if(strcmp(status,"InstallationFailed")==0)
  5859. {
  5860. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  5861. }
  5862. else if(strcmp(status,"Installing")==0)
  5863. {
  5864. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  5865. }
  5866. else if(strcmp(status,"Installed")==0)
  5867. {
  5868. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  5869. }
  5870. return result;
  5871. }
  5872. int sendHeartbeatRequest(int gun_index)
  5873. {
  5874. mtrace();
  5875. int result = FAIL;
  5876. char message[80]={0};
  5877. char guid[37]={0};
  5878. char tempdata[65]={0};
  5879. random_uuid(guid);
  5880. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  5881. , MESSAGE_TYPE_CALL
  5882. , guid );
  5883. LWS_Send(message);
  5884. sprintf(tempdata, "Heartbeat,%d", 0);
  5885. 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*/)
  5886. {
  5887. result = PASS;
  5888. }
  5889. return result;
  5890. }
  5891. int sendStartTransactionRequest(int gun_index)
  5892. {
  5893. mtrace();
  5894. int result = FAIL;
  5895. char message[250]={0};
  5896. char guid[37]={0};
  5897. struct timeval tmnow;
  5898. struct tm *tm;
  5899. char buf[28];//, usec_buf[6];
  5900. char tempdata[65]={0};
  5901. int tempIndex = 0;
  5902. DEBUG_INFO("sendStartTransactionRequest...\n");
  5903. gettimeofday(&tmnow, NULL);
  5904. time_t t;
  5905. t = time(NULL);
  5906. /*UTC time and date*/
  5907. tm = gmtime(&t);
  5908. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5909. #if 0 // remove temporally
  5910. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5911. strcat(buf,".");
  5912. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5913. strcat(buf,usec_buf);
  5914. #endif
  5915. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  5916. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  5917. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5918. // clear StartTransaction Response
  5919. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  5920. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  5921. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  5922. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  5923. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5924. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5925. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5926. {
  5927. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5928. {
  5929. tempIndex = ((gun_index==2) ? 1: 0);
  5930. }
  5931. else
  5932. {
  5933. tempIndex = gun_index;
  5934. }
  5935. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5936. {
  5937. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5938. {
  5939. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5940. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  5941. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5942. }
  5943. }
  5944. }
  5945. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5946. {
  5947. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5948. {
  5949. tempIndex = ((gun_index==2) ? 1: 0);
  5950. }
  5951. else
  5952. {
  5953. tempIndex = gun_index;
  5954. }
  5955. for (int index = 0; index < CCS_QUANTITY; index++)
  5956. {
  5957. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5958. {
  5959. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5960. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5961. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5962. }
  5963. }
  5964. }
  5965. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5966. {
  5967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5968. {
  5969. tempIndex = ((gun_index==2) ? 1: 0);
  5970. }
  5971. else
  5972. {
  5973. tempIndex = gun_index;
  5974. }
  5975. for (int index = 0; index < GB_QUANTITY; index++)
  5976. {
  5977. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5978. {
  5979. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5980. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5981. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5982. }
  5983. }
  5984. }
  5985. else if(gunType[gun_index] == GUN_TYPE_DO)
  5986. {
  5987. tempIndex = gun_index;
  5988. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5989. {
  5990. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5991. {
  5992. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5993. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5994. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5995. }
  5996. }
  5997. }
  5998. else
  5999. {
  6000. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6001. {
  6002. tempIndex = 2;
  6003. }
  6004. else
  6005. {
  6006. tempIndex = gun_index;
  6007. }
  6008. for (int index = 0; index < AC_QUANTITY; index++)
  6009. {
  6010. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6011. {
  6012. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6013. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  6014. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6015. }
  6016. }
  6017. }
  6018. random_uuid(guid);
  6019. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  6020. {
  6021. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  6022. , gun_index +1
  6023. , MESSAGE_TYPE_CALL
  6024. , guid
  6025. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  6026. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  6027. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  6028. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  6029. }
  6030. else
  6031. {
  6032. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  6033. , gun_index +1
  6034. , MESSAGE_TYPE_CALL
  6035. , guid
  6036. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  6037. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  6038. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  6039. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  6040. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  6041. }
  6042. #if 1
  6043. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  6044. 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*/)
  6045. {
  6046. result = PASS;
  6047. }
  6048. #endif
  6049. strcpy(queuedata, message);
  6050. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6051. OCPP_insert_transaction_msg(YES, queuedata);
  6052. return result;
  6053. }
  6054. int sendConnector0StatusNotificationRequest()
  6055. {
  6056. mtrace();
  6057. int result = FAIL;
  6058. char message[600]={0};
  6059. char guid[37];
  6060. struct timeval tmnow;
  6061. struct tm *tm;
  6062. char buf[28];//, usec_buf[6];
  6063. char tempdata[65]={0};
  6064. DEBUG_INFO("sendConnector0StatusNotificationRequest...\n");
  6065. gettimeofday(&tmnow, NULL);
  6066. time_t t;
  6067. t = time(NULL);
  6068. /*UTC time and date*/
  6069. tm = gmtime(&t);
  6070. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6071. random_uuid(guid);
  6072. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":0,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6073. , MESSAGE_TYPE_CALL
  6074. , guid
  6075. , "NoError"
  6076. , ""
  6077. , (isConnector0Unavailable()==YES?"Unavailable":"Available")
  6078. , buf
  6079. , ShmSysConfigAndInfo->SysConfig.chargePointVendor
  6080. , "");
  6081. LWS_Send(message);
  6082. sprintf(tempdata, "StatusNotification,%d", 99);
  6083. 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*/)
  6084. {
  6085. //DEBUG_ERROR("statusNotification mapitem pass");
  6086. result = PASS;
  6087. }
  6088. return result;
  6089. }
  6090. int sendStatusNotificationRequest(int gun_index)
  6091. {
  6092. mtrace();
  6093. int result = FAIL;
  6094. char message[600]={0};
  6095. char guid[37];
  6096. int currentStatus = 0;
  6097. struct timeval tmnow;
  6098. struct tm *tm;
  6099. char buf[28];//, usec_buf[6];
  6100. char tempdata[65]={0};
  6101. int tempIndex = 0;
  6102. uint8_t isStateChanged = TRUE;
  6103. uint8_t isContentIllegal = TRUE;
  6104. DEBUG_INFO("sendStatusNotificationRequest...\n");
  6105. gettimeofday(&tmnow, NULL);
  6106. time_t t;
  6107. t = time(NULL);
  6108. /*UTC time and date*/
  6109. tm = gmtime(&t);
  6110. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6111. #if 0 // remove temporally
  6112. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  6113. strcat(buf,".");
  6114. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  6115. strcat(buf,usec_buf);
  6116. #endif
  6117. //printf("%s",buf);
  6118. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  6119. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  6120. // it's option
  6121. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  6122. /*
  6123. enum _SYSTEM_STATUS
  6124. {
  6125. S_BOOTING = 0,
  6126. S_IDLE, = 1
  6127. S_AUTHORIZING, =2
  6128. S_REASSIGN_CHECK, =3
  6129. S_REASSIGN, =4
  6130. S_PRECHARGE, =5
  6131. S_PREPARING_FOR_EV, =6
  6132. S_PREPARING_FOR_EVSE, =7
  6133. S_CHARGING, =8
  6134. S_TERMINATING, =9
  6135. S_COMPLETE, =10
  6136. S_ALARM, =11
  6137. S_FAULT =12
  6138. }
  6139. */
  6140. //check Transaction active
  6141. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6142. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6143. {
  6144. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6145. {
  6146. tempIndex = ((gun_index==2) ? 1: 0);
  6147. }
  6148. else
  6149. {
  6150. tempIndex = gun_index;
  6151. }
  6152. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6153. {
  6154. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  6155. {
  6156. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  6157. {
  6158. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6159. {
  6160. currentStatus = Preparing; //OCPP Status: Preparing
  6161. }
  6162. else
  6163. {
  6164. currentStatus = Available; //OCPP Status: Available
  6165. }
  6166. }
  6167. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6168. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6169. ) //S_PRECHARGE
  6170. {
  6171. currentStatus = Preparing; //OCPP Status: Preparing
  6172. }
  6173. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6174. {
  6175. currentStatus = Charging; //OCPP Status: Charging
  6176. }
  6177. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6178. {
  6179. currentStatus = Finishing; //OCPP Status: Finishing
  6180. }
  6181. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6182. {
  6183. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6184. }
  6185. 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
  6186. {
  6187. currentStatus = Unavailable; //OCPP Status: Unavailable
  6188. }
  6189. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6190. {
  6191. currentStatus = Faulted; //OCPP Status: Faulted
  6192. }
  6193. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6194. {
  6195. currentStatus = Reserved; //OCPP Status: Reserved
  6196. }
  6197. } //end of the same index
  6198. }//end of for CHAdeMO_QUANTITY
  6199. }
  6200. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6201. {
  6202. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6203. {
  6204. tempIndex = ((gun_index==2) ? 1: 0);
  6205. }
  6206. else
  6207. {
  6208. tempIndex = gun_index;
  6209. }
  6210. for (int index = 0; index < CCS_QUANTITY; index++)
  6211. {
  6212. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6213. {
  6214. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6215. {
  6216. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  6217. {
  6218. currentStatus = Preparing; //OCPP Status: Preparing
  6219. }
  6220. else
  6221. {
  6222. currentStatus = Available; //OCPP Status: Available
  6223. }
  6224. }
  6225. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6226. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6227. ) //S_PRECHARGE
  6228. {
  6229. currentStatus = Preparing; //OCPP Status: Preparing
  6230. }
  6231. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6232. {
  6233. currentStatus = Charging; //OCPP Status: Charging
  6234. }
  6235. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6236. {
  6237. currentStatus = Finishing; //OCPP Status: Finishing
  6238. }
  6239. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  6240. {
  6241. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6242. }
  6243. 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
  6244. {
  6245. currentStatus = Unavailable; //OCPP Status : Unavailable
  6246. }
  6247. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6248. {
  6249. currentStatus = Faulted; //OCPP Status: Faulted
  6250. }
  6251. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6252. {
  6253. currentStatus = Reserved; //OCPP Status: Reserved
  6254. }
  6255. } //end of the same index
  6256. } // end of for CCS_QUANTITY
  6257. }
  6258. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6259. {
  6260. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6261. {
  6262. tempIndex = ((gun_index==2) ? 1: 0);
  6263. }
  6264. else
  6265. {
  6266. tempIndex = gun_index;
  6267. }
  6268. for (int index = 0; index < GB_QUANTITY; index++)
  6269. {
  6270. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6271. {
  6272. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6273. {
  6274. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6275. {
  6276. currentStatus = Preparing; //OCPP Status: Preparing
  6277. }
  6278. else
  6279. {
  6280. currentStatus = Available; //OCPP Status: Available
  6281. }
  6282. }
  6283. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6284. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6285. ) //S_PRECHARGE
  6286. {
  6287. currentStatus = Preparing; //OCPP Status: Preparing
  6288. }
  6289. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6290. {
  6291. currentStatus = Charging; //OCPP Status: Charging
  6292. }
  6293. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6294. {
  6295. currentStatus = Finishing; //OCPP Status: Finishing
  6296. }
  6297. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6298. {
  6299. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6300. }
  6301. 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
  6302. {
  6303. currentStatus = Unavailable; //OCPP Status: Unavailable
  6304. }
  6305. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6306. {
  6307. currentStatus = Faulted; //OCPP Status: Faulted
  6308. }
  6309. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6310. {
  6311. currentStatus = Reserved; //OCPP Status: Reserved
  6312. }
  6313. } //end of the same index
  6314. } // end of for GB_QUANTITY
  6315. }
  6316. else if(gunType[gun_index] == GUN_TYPE_DO)
  6317. {
  6318. tempIndex = gun_index;
  6319. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6320. {
  6321. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6322. {
  6323. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6324. {
  6325. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6326. {
  6327. currentStatus = Preparing; //OCPP Status: Preparing
  6328. }
  6329. else
  6330. {
  6331. currentStatus = Available; //OCPP Status: Available
  6332. }
  6333. }
  6334. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6335. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6336. ) //S_PRECHARGE
  6337. {
  6338. currentStatus = Preparing; //OCPP Status: Preparing
  6339. }
  6340. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6341. {
  6342. currentStatus = Charging; //OCPP Status: Charging
  6343. }
  6344. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6345. {
  6346. currentStatus = Finishing; //OCPP Status: Finishing
  6347. }
  6348. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6349. {
  6350. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6351. }
  6352. 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
  6353. {
  6354. currentStatus = Unavailable; //OCPP Status: Unavailable
  6355. }
  6356. 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
  6357. {
  6358. currentStatus = Faulted; //OCPP Status: Faulted
  6359. }
  6360. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6361. {
  6362. currentStatus = Reserved; //OCPP Status: Reserved
  6363. }
  6364. } //end of the same index
  6365. }
  6366. }
  6367. else
  6368. {
  6369. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6370. {
  6371. tempIndex = 2;
  6372. }
  6373. else
  6374. {
  6375. tempIndex = gun_index;
  6376. }
  6377. for (int index = 0; index < AC_QUANTITY; index++)
  6378. {
  6379. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6380. {
  6381. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  6382. {
  6383. 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))
  6384. {
  6385. currentStatus = Preparing; //OCPP Status: Preparing
  6386. }
  6387. else
  6388. {
  6389. currentStatus = Available; //OCPP Status: Available
  6390. }
  6391. }
  6392. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  6393. {
  6394. currentStatus = Preparing; //OCPP Status: Preparing
  6395. }
  6396. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  6397. {
  6398. currentStatus = Charging; //OCPP Status: Charging
  6399. }
  6400. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  6401. {
  6402. currentStatus = Finishing; //OCPP Status: Finishing
  6403. }
  6404. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6405. {
  6406. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  6407. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6408. else
  6409. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  6410. }
  6411. 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
  6412. {
  6413. currentStatus = Unavailable; //OCPP Status: Unavailable
  6414. }
  6415. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6416. {
  6417. currentStatus = Faulted; //OCPP Status: Faulted
  6418. }
  6419. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6420. {
  6421. currentStatus = Reserved; //OCPP Status: Reserved
  6422. }
  6423. }//end of the same index
  6424. }//end of for AC_QUANTITY
  6425. }
  6426. //it's option
  6427. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  6428. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  6429. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  6430. {
  6431. isStateChanged = FALSE;
  6432. }
  6433. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6434. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  6435. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6436. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  6437. isContentIllegal = TRUE;
  6438. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  6439. {
  6440. if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  6441. {
  6442. isContentIllegal = FALSE;
  6443. break;
  6444. }
  6445. }
  6446. if(isContentIllegal)
  6447. {
  6448. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  6449. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  6450. }
  6451. random_uuid(guid);
  6452. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6453. , MESSAGE_TYPE_CALL
  6454. , guid
  6455. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  6456. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  6457. , ShmOCPP16Data->StatusNotification[gun_index].Info
  6458. , ShmOCPP16Data->StatusNotification[gun_index].Status
  6459. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  6460. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  6461. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  6462. if((server_sign == TRUE) && isStateChanged)
  6463. {
  6464. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6465. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6466. LWS_Send(message);
  6467. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  6468. 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*/)
  6469. {
  6470. //DEBUG_ERROR("statusNotification mapitem pass");
  6471. result = PASS;
  6472. }
  6473. }
  6474. else
  6475. {
  6476. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6477. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6478. result = PASS;
  6479. }
  6480. return result;
  6481. }
  6482. int sendStopTransactionRequest(int gun_index)
  6483. {
  6484. mtrace();
  6485. int result = FAIL;
  6486. //char message[1500]={0};
  6487. char guid[37]={0};
  6488. char tempdata[65]={0};
  6489. int tempIndex = 0;
  6490. char TempStopTransaction[256];
  6491. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  6492. //int idx_sample=0;
  6493. DEBUG_INFO("sendStopTransactionRequest \n");
  6494. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6495. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  6496. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  6497. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6498. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6499. {
  6500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6501. {
  6502. tempIndex = ((gun_index==2) ? 1: 0);
  6503. }
  6504. else
  6505. {
  6506. tempIndex = gun_index;
  6507. }
  6508. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6509. {
  6510. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6511. {
  6512. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6513. }
  6514. }// END OF CHAdeMO_QUANTITY
  6515. }
  6516. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6517. {
  6518. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6519. {
  6520. tempIndex = ((gun_index==2) ? 1: 0);
  6521. }
  6522. else
  6523. {
  6524. tempIndex = gun_index;
  6525. }
  6526. for (int index = 0; index < CCS_QUANTITY; index++)
  6527. {
  6528. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6529. {
  6530. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6531. }
  6532. }// END OF CCS_QUANTITY
  6533. }
  6534. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6535. {
  6536. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6537. {
  6538. tempIndex = ((gun_index==2) ? 1: 0);
  6539. }
  6540. else
  6541. {
  6542. tempIndex = gun_index;
  6543. }
  6544. for (int index = 0; index < GB_QUANTITY; index++)
  6545. {
  6546. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6547. {
  6548. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6549. }
  6550. }// END OF GB_QUANTITY
  6551. }
  6552. else if(gunType[gun_index] == GUN_TYPE_DO)
  6553. {
  6554. tempIndex = gun_index;
  6555. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6556. {
  6557. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6558. {
  6559. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6560. }
  6561. }// END OF GB_QUANTITY
  6562. }
  6563. else
  6564. {
  6565. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6566. {
  6567. tempIndex = 2;
  6568. }
  6569. else
  6570. {
  6571. tempIndex = gun_index;
  6572. }
  6573. for (int index = 0; index < AC_QUANTITY; index++)
  6574. {
  6575. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6576. {
  6577. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6578. }
  6579. }// END OF AC_QUANTITY
  6580. }
  6581. //====================================== Stop Transaction Time =====================================================
  6582. struct timeval tmnow;
  6583. struct tm *tm;
  6584. char buf[28];//, usec_buf[6];
  6585. gettimeofday(&tmnow, NULL);
  6586. time_t t;
  6587. t = time(NULL);
  6588. /*UTC time and date*/
  6589. tm = gmtime(&t);
  6590. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  6592. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  6593. random_uuid(guid);
  6594. /***********************************transactionData******************************************************/
  6595. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  6596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  6597. //=================================
  6598. // Transaction_Begin
  6599. //=================================
  6600. //=================================
  6601. // Transaction_End
  6602. //=================================
  6603. // ================================= Current.Import L1 ===============================================
  6604. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6605. {
  6606. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  6607. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6608. {
  6609. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6610. {
  6611. tempIndex = ((gun_index==2) ? 1: 0);
  6612. }
  6613. else
  6614. {
  6615. tempIndex = gun_index;
  6616. }
  6617. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6618. {
  6619. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6620. {
  6621. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6622. }
  6623. }// End of for CHAdeMO_QUANTITY
  6624. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6625. }
  6626. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6627. {
  6628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6629. {
  6630. tempIndex = ((gun_index==2) ? 1: 0);
  6631. }
  6632. else
  6633. {
  6634. tempIndex = gun_index;
  6635. }
  6636. for (int index = 0; index < CCS_QUANTITY; index++)
  6637. {
  6638. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6639. {
  6640. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6641. }
  6642. }// End of for CCS_QUANTITY
  6643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6644. }
  6645. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6646. {
  6647. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6648. {
  6649. tempIndex = ((gun_index==2) ? 1: 0);
  6650. }
  6651. else
  6652. {
  6653. tempIndex = gun_index;
  6654. }
  6655. for (int index = 0; index < GB_QUANTITY; index++)
  6656. {
  6657. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6658. {
  6659. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6660. }
  6661. }// End of for GB_QUANTITY
  6662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6663. }
  6664. else if(gunType[gun_index] == GUN_TYPE_DO)
  6665. {
  6666. tempIndex = gun_index;
  6667. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6668. {
  6669. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6670. {
  6671. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6672. }
  6673. }
  6674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6675. }
  6676. else
  6677. {
  6678. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6679. {
  6680. tempIndex = 2;
  6681. }
  6682. else
  6683. {
  6684. tempIndex = gun_index;
  6685. }
  6686. for (int index = 0; index < AC_QUANTITY; index++)
  6687. {
  6688. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6689. {
  6690. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  6691. }
  6692. }// End of for AC_QUANTITY
  6693. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  6694. }
  6695. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6696. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  6697. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  6698. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  6699. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6700. }
  6701. // ================================= Energy.Active.Import.Interval ==============================================
  6702. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  6703. {
  6704. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6705. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6706. {
  6707. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6708. {
  6709. tempIndex = ((gun_index==2) ? 1: 0);
  6710. }
  6711. else
  6712. {
  6713. tempIndex = gun_index;
  6714. }
  6715. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6716. {
  6717. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6718. {
  6719. 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
  6720. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6721. }
  6722. }// END OF CHAdeMO_QUANTITY
  6723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6724. }
  6725. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6726. {
  6727. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6728. {
  6729. tempIndex = ((gun_index==2) ? 1: 0);
  6730. }
  6731. else
  6732. {
  6733. tempIndex = gun_index;
  6734. }
  6735. for (int index = 0; index < CCS_QUANTITY; index++)
  6736. {
  6737. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6738. {
  6739. 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
  6740. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6741. }
  6742. }// END OF CCS_QUANTITY
  6743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6744. }
  6745. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6746. {
  6747. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6748. {
  6749. tempIndex = ((gun_index==2) ? 1: 0);
  6750. }
  6751. else
  6752. {
  6753. tempIndex = gun_index;
  6754. }
  6755. for (int index = 0; index < GB_QUANTITY; index++)
  6756. {
  6757. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6758. {
  6759. 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
  6760. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6761. }
  6762. }// END OF GB_QUANTITY
  6763. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6764. }
  6765. else if(gunType[gun_index] == GUN_TYPE_DO)
  6766. {
  6767. tempIndex = gun_index;
  6768. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6769. {
  6770. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6771. {
  6772. 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
  6773. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6774. }
  6775. }
  6776. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6777. }
  6778. else
  6779. {
  6780. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6781. {
  6782. tempIndex = 2;
  6783. }
  6784. else
  6785. {
  6786. tempIndex = gun_index;
  6787. }
  6788. for (int index = 0; index < AC_QUANTITY; index++)
  6789. {
  6790. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6791. {
  6792. 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
  6793. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6794. }
  6795. }// END OF AC_QUANTITY
  6796. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  6797. }
  6798. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6799. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  6800. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  6801. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  6802. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6803. }
  6804. //=================================== Power.Active.Import ==================================================
  6805. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  6806. {
  6807. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6808. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6809. {
  6810. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6811. {
  6812. tempIndex = ((gun_index==2) ? 1: 0);
  6813. }
  6814. else
  6815. {
  6816. tempIndex = gun_index;
  6817. }
  6818. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6819. {
  6820. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6821. {
  6822. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6823. }
  6824. } // End for CHAdeMO_QUANTITY
  6825. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6826. }
  6827. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6828. {
  6829. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6830. {
  6831. tempIndex = ((gun_index==2) ? 1: 0);
  6832. }
  6833. else
  6834. {
  6835. tempIndex = gun_index;
  6836. }
  6837. for (int index = 0; index < CCS_QUANTITY; index++)
  6838. {
  6839. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6840. {
  6841. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6842. }
  6843. } // END for CCS_QUANTITY
  6844. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6845. }
  6846. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6847. {
  6848. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6849. {
  6850. tempIndex = ((gun_index==2) ? 1: 0);
  6851. }
  6852. else
  6853. {
  6854. tempIndex = gun_index;
  6855. }
  6856. for (int index = 0; index < GB_QUANTITY; index++)
  6857. {
  6858. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6859. {
  6860. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6861. }
  6862. }// END for GB_QUANTITY
  6863. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6864. }
  6865. else if(gunType[gun_index] == GUN_TYPE_DO)
  6866. {
  6867. tempIndex = gun_index;
  6868. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6869. {
  6870. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6871. {
  6872. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6873. }
  6874. }
  6875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6876. }
  6877. else
  6878. {
  6879. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6880. {
  6881. tempIndex = 2;
  6882. }
  6883. else
  6884. {
  6885. tempIndex = gun_index;
  6886. }
  6887. for (int index = 0; index < AC_QUANTITY; index++)
  6888. {
  6889. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6890. {
  6891. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6892. }
  6893. } // END for AC_QUANTITY
  6894. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  6895. }
  6896. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6897. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  6898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  6899. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  6900. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  6901. }
  6902. //============================ Voltage L1 ====================================
  6903. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6904. {
  6905. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6906. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6907. {
  6908. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6909. {
  6910. tempIndex = ((gun_index==2) ? 1: 0);
  6911. }
  6912. else
  6913. {
  6914. tempIndex = gun_index;
  6915. }
  6916. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6917. {
  6918. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6919. {
  6920. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6921. }
  6922. } // END OF FOR CHAdeMO_QUANTITY
  6923. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6924. }
  6925. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6926. {
  6927. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6928. {
  6929. tempIndex = ((gun_index==2) ? 1: 0);
  6930. }
  6931. else
  6932. {
  6933. tempIndex = gun_index;
  6934. }
  6935. for (int index = 0; index < CCS_QUANTITY; index++)
  6936. {
  6937. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6938. {
  6939. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6940. }
  6941. } // END OF FOR CCS_QUANTITY
  6942. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6943. }
  6944. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6945. {
  6946. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6947. {
  6948. tempIndex = ((gun_index==2) ? 1: 0);
  6949. }
  6950. else
  6951. {
  6952. tempIndex = gun_index;
  6953. }
  6954. for (int index = 0; index < GB_QUANTITY; index++)
  6955. {
  6956. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6957. {
  6958. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6959. }
  6960. } // END OF FOR GB_QUANTITY
  6961. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6962. }
  6963. else if(gunType[gun_index] == GUN_TYPE_DO)
  6964. {
  6965. tempIndex = gun_index;
  6966. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6967. {
  6968. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6969. {
  6970. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6971. }
  6972. }
  6973. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6974. }
  6975. else
  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[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//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[4].Phase,PhaseStr[L1_N]);
  6993. }
  6994. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6998. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6999. }
  7000. //====================== End SoC ================================
  7001. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  7002. {
  7003. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7004. 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))
  7005. {
  7006. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7007. {
  7008. tempIndex = ((gun_index==2) ? 1: 0);
  7009. }
  7010. else
  7011. {
  7012. tempIndex = gun_index;
  7013. }
  7014. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7015. {
  7016. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7017. {
  7018. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7019. {
  7020. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  7021. }
  7022. }
  7023. }
  7024. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7025. {
  7026. for (int index = 0; index < CCS_QUANTITY; index++)
  7027. {
  7028. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7029. {
  7030. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  7031. }
  7032. }
  7033. }
  7034. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7035. {
  7036. for (int index = 0; index < GB_QUANTITY; index++)
  7037. {
  7038. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7039. {
  7040. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  7041. }
  7042. }
  7043. }
  7044. else if(gunType[gun_index] == GUN_TYPE_DO)
  7045. {
  7046. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7047. {
  7048. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7049. {
  7050. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  7051. }
  7052. }
  7053. }
  7054. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  7055. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  7056. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  7057. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  7058. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  7059. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  7060. } // END FOR DC CASE
  7061. }
  7062. // ================================= Current.Import L2 ===============================================
  7063. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  7064. {
  7065. // AC 3 phse L2 current
  7066. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7067. {
  7068. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7069. {
  7070. tempIndex = 2;
  7071. }
  7072. else
  7073. {
  7074. tempIndex = gun_index;
  7075. }
  7076. for (int index = 0; index < AC_QUANTITY; index++)
  7077. {
  7078. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7079. {
  7080. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  7081. }
  7082. }// End of for AC_QUANTITY
  7083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  7084. }
  7085. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  7086. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  7087. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  7088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  7089. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7090. }
  7091. // ================================= Current.Import L3 ===============================================
  7092. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  7093. {
  7094. // AC 3 phse L3 current
  7095. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7096. {
  7097. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7098. {
  7099. tempIndex = 2;
  7100. }
  7101. else
  7102. {
  7103. tempIndex = gun_index;
  7104. }
  7105. for (int index = 0; index < AC_QUANTITY; index++)
  7106. {
  7107. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7108. {
  7109. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  7110. }
  7111. }// End of for AC_QUANTITY
  7112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  7113. }
  7114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  7115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  7116. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  7117. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  7118. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7119. }
  7120. //============================ Voltage L2 ====================================
  7121. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  7122. {
  7123. // AC 3 phse L2 voltage
  7124. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7125. {
  7126. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7127. {
  7128. tempIndex = 2;
  7129. }
  7130. else
  7131. {
  7132. tempIndex = gun_index;
  7133. }
  7134. for (int index = 0; index < AC_QUANTITY; index++)
  7135. {
  7136. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7137. {
  7138. 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
  7139. }
  7140. } // END OF FOR AC_QUANTITY
  7141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  7142. }
  7143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  7144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  7145. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  7146. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  7147. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7148. }
  7149. //============================ Voltage L3 ====================================
  7150. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  7151. {
  7152. // AC 3 phse L3 voltage
  7153. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7154. {
  7155. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7156. {
  7157. tempIndex = 2;
  7158. }
  7159. else
  7160. {
  7161. tempIndex = gun_index;
  7162. }
  7163. for (int index = 0; index < AC_QUANTITY; index++)
  7164. {
  7165. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7166. {
  7167. 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
  7168. }
  7169. } // END OF FOR AC_QUANTITY
  7170. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  7171. }
  7172. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  7173. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  7174. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  7175. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  7176. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7177. }
  7178. //====================== Start SoC ================================
  7179. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  7180. {
  7181. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7182. 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))
  7183. {
  7184. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7185. {
  7186. tempIndex = ((gun_index==2) ? 1: 0);
  7187. }
  7188. else
  7189. {
  7190. tempIndex = gun_index;
  7191. }
  7192. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7193. {
  7194. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7195. {
  7196. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7197. {
  7198. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  7199. }
  7200. }
  7201. }
  7202. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7203. {
  7204. for (int index = 0; index < CCS_QUANTITY; index++)
  7205. {
  7206. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7207. {
  7208. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  7209. }
  7210. }
  7211. }
  7212. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7213. {
  7214. for (int index = 0; index < GB_QUANTITY; index++)
  7215. {
  7216. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7217. {
  7218. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  7219. }
  7220. }
  7221. }
  7222. else if(gunType[gun_index] == GUN_TYPE_DO)
  7223. {
  7224. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7225. {
  7226. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7227. {
  7228. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  7229. }
  7230. }
  7231. }
  7232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  7233. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  7234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  7235. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  7236. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  7237. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  7238. } // END FOR DC CASE
  7239. }
  7240. //================================================ Message create ====================================================
  7241. json_object *StopTransaction = json_object_new_object();
  7242. json_object *transactionDatas = json_object_new_array();
  7243. json_object *sampledValues = json_object_new_array();
  7244. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  7245. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  7246. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  7247. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  7248. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  7249. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  7250. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  7251. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  7252. {
  7253. json_object *transactionData = json_object_new_object();
  7254. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  7255. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  7256. {
  7257. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  7258. {
  7259. json_object *sampledValue = json_object_new_object();
  7260. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  7261. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  7262. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  7263. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  7264. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  7265. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  7266. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  7267. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  7268. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  7269. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  7270. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  7271. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  7272. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  7273. json_object_array_add(sampledValues, sampledValue);
  7274. }
  7275. }
  7276. json_object_object_add(transactionData, "sampledValue", sampledValues);
  7277. json_object_array_add(transactionDatas, transactionData);
  7278. }
  7279. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  7280. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  7281. ,MESSAGE_TYPE_CALL
  7282. ,guid
  7283. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  7284. json_object_put(StopTransaction);
  7285. #if 1 // for TempStopTransaction
  7286. //Delete TempStopTransaction
  7287. if((access(TempStopTransaction,F_OK))!=-1)
  7288. {
  7289. remove(TempStopTransaction); // remove file "TempStopTransaction"
  7290. }
  7291. #endif
  7292. #if 1
  7293. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  7294. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  7295. {
  7296. result = PASS;
  7297. //DEBUG_INFO("StopTransaction mapitem pass\n");
  7298. }
  7299. #endif
  7300. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  7301. OCPP_insert_transaction_msg(NO, queuedata);
  7302. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  7303. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  7304. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  7305. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  7306. {
  7307. //SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  7308. }
  7309. //for test
  7310. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  7311. return result;
  7312. }
  7313. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  7314. {
  7315. mtrace();
  7316. int result = FAIL;
  7317. char guid[37]={0};
  7318. char tempdata[65]={0};
  7319. int tempIndex = 0;
  7320. DEBUG_INFO("sendMeterValuesRequest ...\n");
  7321. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  7322. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  7323. //set value
  7324. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  7325. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  7326. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  7327. -1);
  7328. random_uuid(guid);
  7329. //UTC Date time
  7330. struct timeval tmnow;
  7331. struct tm *tm;
  7332. char buf[28];//, usec_buf[6];
  7333. gettimeofday(&tmnow, NULL);
  7334. time_t t;
  7335. t = time(NULL);
  7336. /*UTC time and date*/
  7337. tm = gmtime(&t);
  7338. if(dataType == ReadingContext_Sample_Clock)
  7339. {
  7340. struct tm *tmTarget;
  7341. struct timeb tbTarget;
  7342. tbTarget.time = mktime(tm);
  7343. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  7344. tmTarget = gmtime(&tbTarget.time);
  7345. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  7346. }
  7347. else
  7348. {
  7349. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  7350. }
  7351. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  7352. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  7353. //********************************(1)Current.Import L1************************************************/
  7354. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7355. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7356. (dataType == ReadingContext_Trigger))
  7357. {
  7358. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7359. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7360. {
  7361. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7362. {
  7363. tempIndex = ((gun_index==2) ? 1: 0);
  7364. }
  7365. else
  7366. {
  7367. tempIndex = gun_index;
  7368. }
  7369. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7370. {
  7371. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7372. {
  7373. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  7374. }
  7375. }
  7376. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  7377. }
  7378. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7379. {
  7380. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7381. {
  7382. tempIndex = ((gun_index==2) ? 1: 0);
  7383. }
  7384. else
  7385. {
  7386. tempIndex = gun_index;
  7387. }
  7388. for (int index = 0; index < CCS_QUANTITY; index++)
  7389. {
  7390. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7391. {
  7392. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  7393. }
  7394. }
  7395. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  7396. }
  7397. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7398. {
  7399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7400. {
  7401. tempIndex = ((gun_index==2) ? 1: 0);
  7402. }
  7403. else
  7404. {
  7405. tempIndex = gun_index;
  7406. }
  7407. for (int index = 0; index < GB_QUANTITY; index++)
  7408. {
  7409. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7410. {
  7411. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  7412. }
  7413. }
  7414. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  7415. }
  7416. else if(gunType[gun_index] == GUN_TYPE_DO)
  7417. {
  7418. tempIndex = gun_index;
  7419. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7420. {
  7421. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7422. {
  7423. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  7424. }
  7425. }
  7426. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  7427. }
  7428. else
  7429. {
  7430. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7431. {
  7432. tempIndex = 2;
  7433. }
  7434. else
  7435. {
  7436. tempIndex = gun_index;
  7437. }
  7438. for (int index = 0; index < AC_QUANTITY; index++)
  7439. {
  7440. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7441. {
  7442. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  7443. }
  7444. }
  7445. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  7446. }
  7447. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  7448. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  7449. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  7450. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  7451. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7452. }
  7453. //********************************(2)Energy.Active.Import.Register ************************************************/
  7454. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  7455. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  7456. (dataType == ReadingContext_Trigger))
  7457. {
  7458. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7459. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7460. {
  7461. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7462. {
  7463. tempIndex = ((gun_index==2) ? 1: 0);
  7464. }
  7465. else
  7466. {
  7467. tempIndex = gun_index;
  7468. }
  7469. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7470. {
  7471. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7472. {
  7473. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  7474. }
  7475. }
  7476. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7477. }
  7478. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7479. {
  7480. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7481. {
  7482. tempIndex = ((gun_index==2) ? 1: 0);
  7483. }
  7484. else
  7485. {
  7486. tempIndex = gun_index;
  7487. }
  7488. for (int index = 0; index < CCS_QUANTITY; index++)
  7489. {
  7490. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7491. {
  7492. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  7493. }
  7494. }
  7495. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7496. }
  7497. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7498. {
  7499. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7500. {
  7501. tempIndex = ((gun_index==2) ? 1: 0);
  7502. }
  7503. else
  7504. {
  7505. tempIndex = gun_index;
  7506. }
  7507. for (int index = 0; index < GB_QUANTITY; index++)
  7508. {
  7509. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7510. {
  7511. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  7512. }
  7513. }
  7514. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7515. }
  7516. else if(gunType[gun_index] == GUN_TYPE_DO)
  7517. {
  7518. tempIndex = gun_index;
  7519. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7520. {
  7521. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7522. {
  7523. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  7524. }
  7525. }
  7526. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7527. }
  7528. else
  7529. {
  7530. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7531. {
  7532. tempIndex = 2;
  7533. }
  7534. else
  7535. {
  7536. tempIndex = gun_index;
  7537. }
  7538. for (int index = 0; index < AC_QUANTITY; index++)
  7539. {
  7540. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7541. {
  7542. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  7543. }
  7544. }
  7545. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  7546. }
  7547. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  7548. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  7549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  7550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  7551. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7552. }
  7553. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  7554. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7555. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7556. (dataType == ReadingContext_Trigger))
  7557. {
  7558. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7559. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7560. {
  7561. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7562. {
  7563. tempIndex = ((gun_index==2) ? 1: 0);
  7564. }
  7565. else
  7566. {
  7567. tempIndex = gun_index;
  7568. }
  7569. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7570. {
  7571. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7572. {
  7573. if(dataType == ReadingContext_Sample_Clock)
  7574. {
  7575. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7576. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7577. }
  7578. else if(dataType == ReadingContext_Sample_Periodic)
  7579. {
  7580. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7581. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7582. }
  7583. else
  7584. {
  7585. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7586. }
  7587. }
  7588. } // END OF FOR CHAdeMO_QUANTITY
  7589. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7590. }
  7591. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7592. {
  7593. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7594. {
  7595. tempIndex = ((gun_index==2) ? 1: 0);
  7596. }
  7597. else
  7598. {
  7599. tempIndex = gun_index;
  7600. }
  7601. for (int index = 0; index < CCS_QUANTITY; index++)
  7602. {
  7603. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7604. {
  7605. if(dataType == ReadingContext_Sample_Clock)
  7606. {
  7607. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7608. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7609. }
  7610. else if(dataType == ReadingContext_Sample_Periodic)
  7611. {
  7612. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7613. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7614. }
  7615. else
  7616. {
  7617. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7618. }
  7619. }
  7620. } // END OF CCS_QUANTITY
  7621. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7622. }
  7623. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7624. {
  7625. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7626. {
  7627. tempIndex = ((gun_index==2) ? 1: 0);
  7628. }
  7629. else
  7630. {
  7631. tempIndex = gun_index;
  7632. }
  7633. for (int index = 0; index < GB_QUANTITY; index++)
  7634. {
  7635. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7636. {
  7637. if(dataType == ReadingContext_Sample_Clock)
  7638. {
  7639. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7640. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7641. }
  7642. else if(dataType == ReadingContext_Sample_Periodic)
  7643. {
  7644. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7645. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7646. }
  7647. else
  7648. {
  7649. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7650. }
  7651. }
  7652. } // END OF GB_QUANTITY
  7653. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7654. }
  7655. else if(gunType[gun_index] == GUN_TYPE_DO)
  7656. {
  7657. tempIndex = gun_index;
  7658. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7659. {
  7660. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7661. {
  7662. if(dataType == ReadingContext_Sample_Clock)
  7663. {
  7664. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7665. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7666. }
  7667. else if(dataType == ReadingContext_Sample_Periodic)
  7668. {
  7669. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7670. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7671. }
  7672. else
  7673. {
  7674. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7675. }
  7676. }
  7677. }
  7678. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7679. }
  7680. else
  7681. {
  7682. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7683. {
  7684. tempIndex = 2;
  7685. }
  7686. else
  7687. {
  7688. tempIndex = gun_index;
  7689. }
  7690. for (int index = 0; index < AC_QUANTITY; index++)
  7691. {
  7692. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7693. {
  7694. if(dataType == ReadingContext_Sample_Clock)
  7695. {
  7696. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7697. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7698. }
  7699. else if(dataType == ReadingContext_Sample_Periodic)
  7700. {
  7701. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7702. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7703. }
  7704. else
  7705. {
  7706. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7707. }
  7708. }
  7709. }
  7710. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7711. }
  7712. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7713. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7714. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7715. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7716. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7717. }
  7718. //********************************(4)Power.Active.Import************************************************/
  7719. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7720. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7721. (dataType == ReadingContext_Trigger))
  7722. {
  7723. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7724. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7725. {
  7726. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7727. {
  7728. tempIndex = ((gun_index==2) ? 1: 0);
  7729. }
  7730. else
  7731. {
  7732. tempIndex = gun_index;
  7733. }
  7734. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7735. {
  7736. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7737. {
  7738. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7739. }
  7740. } // END OF FOR
  7741. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7742. }
  7743. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7744. {
  7745. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7746. {
  7747. tempIndex = ((gun_index==2) ? 1: 0);
  7748. }
  7749. else
  7750. {
  7751. tempIndex = gun_index;
  7752. }
  7753. for (int index = 0; index < CCS_QUANTITY; index++)
  7754. {
  7755. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7756. {
  7757. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7758. }
  7759. }
  7760. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7761. }
  7762. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7763. {
  7764. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7765. {
  7766. tempIndex = ((gun_index==2) ? 1: 0);
  7767. }
  7768. else
  7769. {
  7770. tempIndex = gun_index;
  7771. }
  7772. for (int index = 0; index < GB_QUANTITY; index++)
  7773. {
  7774. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7775. {
  7776. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7777. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7778. }
  7779. }
  7780. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7781. }
  7782. else if(gunType[gun_index] == GUN_TYPE_DO)
  7783. {
  7784. tempIndex = gun_index;
  7785. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7786. {
  7787. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7788. {
  7789. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7790. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7791. }
  7792. }
  7793. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7794. }
  7795. else
  7796. {
  7797. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7798. {
  7799. tempIndex = 2;
  7800. }
  7801. else
  7802. {
  7803. tempIndex = gun_index;
  7804. }
  7805. for (int index = 0; index < AC_QUANTITY; index++)
  7806. {
  7807. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7808. {
  7809. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7810. }
  7811. }
  7812. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7813. }
  7814. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7815. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7816. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7817. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7818. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7819. }
  7820. //***********************************************(5)VOLTAGE L1******************************************************/
  7821. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7822. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7823. (dataType == ReadingContext_Trigger))
  7824. {
  7825. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7826. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7827. {
  7828. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7829. {
  7830. tempIndex = ((gun_index==2) ? 1: 0);
  7831. }
  7832. else
  7833. {
  7834. tempIndex = gun_index;
  7835. }
  7836. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7837. {
  7838. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7839. {
  7840. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7841. }
  7842. }
  7843. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7844. }
  7845. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7846. {
  7847. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7848. {
  7849. tempIndex = ((gun_index==2) ? 1: 0);
  7850. }
  7851. else
  7852. {
  7853. tempIndex = gun_index;
  7854. }
  7855. for (int index = 0; index < CCS_QUANTITY; index++)
  7856. {
  7857. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7858. {
  7859. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7860. }
  7861. }
  7862. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7863. }
  7864. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7865. {
  7866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7867. {
  7868. tempIndex = ((gun_index==2) ? 1: 0);
  7869. }
  7870. else
  7871. {
  7872. tempIndex = gun_index;
  7873. }
  7874. for (int index = 0; index < GB_QUANTITY; index++)
  7875. {
  7876. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7877. {
  7878. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7879. }
  7880. }
  7881. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7882. }
  7883. else if(gunType[gun_index] == GUN_TYPE_DO)
  7884. {
  7885. tempIndex = gun_index;
  7886. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7887. {
  7888. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7889. {
  7890. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7891. }
  7892. }
  7893. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7894. }
  7895. else
  7896. {
  7897. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7898. {
  7899. tempIndex = 2;
  7900. }
  7901. else
  7902. {
  7903. tempIndex = gun_index;
  7904. }
  7905. for (int index = 0; index < AC_QUANTITY; index++)
  7906. {
  7907. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7908. {
  7909. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7910. }
  7911. }
  7912. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7913. }
  7914. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7915. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7916. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7917. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7918. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7919. }
  7920. //***********************************************(6)SOC******************************************************/
  7921. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7922. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7923. (dataType == ReadingContext_Trigger))
  7924. {
  7925. 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))
  7926. {
  7927. //idx_sample=5;
  7928. //sampledValue = NULL;
  7929. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7930. {
  7931. tempIndex = ((gun_index==2) ? 1: 0);
  7932. }
  7933. else
  7934. {
  7935. tempIndex = gun_index;
  7936. }
  7937. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7938. {
  7939. //tempIndex = ((gun_index==2) ? 1: 0);
  7940. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7941. {
  7942. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7943. {
  7944. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7945. }
  7946. }
  7947. }
  7948. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7949. {
  7950. //tempIndex = ((gun_index==2) ? 1: 0);
  7951. for (int index = 0; index < CCS_QUANTITY; index++)
  7952. {
  7953. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7954. {
  7955. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7956. }
  7957. }
  7958. }
  7959. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7960. {
  7961. //tempIndex = ((gun_index==2) ? 1: 0);
  7962. for (int index = 0; index < GB_QUANTITY; index++)
  7963. {
  7964. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7965. {
  7966. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7967. }
  7968. }
  7969. }
  7970. else if(gunType[gun_index] == GUN_TYPE_DO)
  7971. {
  7972. //tempIndex = ((gun_index==2) ? 1: 0);
  7973. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7974. {
  7975. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7976. {
  7977. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7978. }
  7979. }
  7980. }
  7981. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7982. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7983. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7984. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7985. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7986. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7987. }
  7988. }
  7989. //********************************(7)Current.Import L2************************************************/
  7990. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7991. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7992. (dataType == ReadingContext_Trigger))
  7993. {
  7994. // Only for AC 3 phase
  7995. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7996. {
  7997. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7998. {
  7999. tempIndex = 2;
  8000. }
  8001. else
  8002. {
  8003. tempIndex = gun_index;
  8004. }
  8005. for (int index = 0; index < AC_QUANTITY; index++)
  8006. {
  8007. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8008. {
  8009. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  8010. }
  8011. }
  8012. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  8013. }
  8014. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  8015. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  8016. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  8017. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  8018. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  8019. }
  8020. //********************************(8)Current.Import L3************************************************/
  8021. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  8022. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  8023. (dataType == ReadingContext_Trigger))
  8024. {
  8025. // Only for AC 3 phase
  8026. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  8027. {
  8028. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8029. {
  8030. tempIndex = 2;
  8031. }
  8032. else
  8033. {
  8034. tempIndex = gun_index;
  8035. }
  8036. for (int index = 0; index < AC_QUANTITY; index++)
  8037. {
  8038. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8039. {
  8040. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  8041. }
  8042. }
  8043. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  8044. }
  8045. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  8046. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  8047. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  8048. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  8049. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  8050. }
  8051. //***********************************************(9)VOLTAGE L2******************************************************/
  8052. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  8053. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  8054. (dataType == ReadingContext_Trigger))
  8055. {
  8056. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  8057. {
  8058. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8059. {
  8060. tempIndex = 2;
  8061. }
  8062. else
  8063. {
  8064. tempIndex = gun_index;
  8065. }
  8066. for (int index = 0; index < AC_QUANTITY; index++)
  8067. {
  8068. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8069. {
  8070. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  8071. }
  8072. }
  8073. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  8074. }
  8075. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  8076. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  8077. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  8078. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  8079. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  8080. }
  8081. //***********************************************(10)VOLTAGE L3******************************************************/
  8082. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  8083. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  8084. (dataType == ReadingContext_Trigger))
  8085. {
  8086. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  8087. {
  8088. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8089. {
  8090. tempIndex = 2;
  8091. }
  8092. else
  8093. {
  8094. tempIndex = gun_index;
  8095. }
  8096. for (int index = 0; index < AC_QUANTITY; index++)
  8097. {
  8098. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8099. {
  8100. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  8101. }
  8102. }
  8103. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  8104. }
  8105. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  8106. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  8107. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  8108. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  8109. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  8110. }
  8111. //***********************************************(11)Current.Offered******************************************************/
  8112. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  8113. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  8114. (dataType == ReadingContext_Trigger))
  8115. {
  8116. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8117. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8118. {
  8119. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8120. {
  8121. tempIndex = ((gun_index==2) ? 1: 0);
  8122. }
  8123. else
  8124. {
  8125. tempIndex = gun_index;
  8126. }
  8127. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8128. {
  8129. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8130. {
  8131. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  8132. }
  8133. } // END OF FOR CHAdeMO_QUANTITY
  8134. }
  8135. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8136. {
  8137. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8138. {
  8139. tempIndex = ((gun_index==2) ? 1: 0);
  8140. }
  8141. else
  8142. {
  8143. tempIndex = gun_index;
  8144. }
  8145. for (int index = 0; index < CCS_QUANTITY; index++)
  8146. {
  8147. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8148. {
  8149. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  8150. }
  8151. } // END OF CCS_QUANTITY
  8152. }
  8153. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8154. {
  8155. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8156. {
  8157. tempIndex = ((gun_index==2) ? 1: 0);
  8158. }
  8159. else
  8160. {
  8161. tempIndex = gun_index;
  8162. }
  8163. for (int index = 0; index < GB_QUANTITY; index++)
  8164. {
  8165. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8166. {
  8167. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  8168. }
  8169. } // END OF GB_QUANTITY
  8170. }
  8171. else if(gunType[gun_index] == GUN_TYPE_DO)
  8172. {
  8173. tempIndex = gun_index;
  8174. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8175. {
  8176. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8177. {
  8178. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  8179. }
  8180. }
  8181. }
  8182. else
  8183. {
  8184. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8185. {
  8186. tempIndex = 2;
  8187. }
  8188. else
  8189. {
  8190. tempIndex = gun_index;
  8191. }
  8192. for (int index = 0; index < AC_QUANTITY; index++)
  8193. {
  8194. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8195. {
  8196. uint16_t currentOffer;
  8197. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  8198. {
  8199. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  8200. }
  8201. else
  8202. {
  8203. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  8204. }
  8205. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  8206. }
  8207. }
  8208. }
  8209. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  8210. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  8211. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  8212. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  8213. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  8214. }
  8215. //***********************************************(12)Power.Offered******************************************************/
  8216. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  8217. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  8218. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  8219. {
  8220. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8221. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8222. {
  8223. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8224. {
  8225. tempIndex = ((gun_index==2) ? 1: 0);
  8226. }
  8227. else
  8228. {
  8229. tempIndex = gun_index;
  8230. }
  8231. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8232. {
  8233. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8234. {
  8235. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  8236. }
  8237. } // END OF FOR CHAdeMO_QUANTITY
  8238. }
  8239. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8240. {
  8241. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8242. {
  8243. tempIndex = ((gun_index==2) ? 1: 0);
  8244. }
  8245. else
  8246. {
  8247. tempIndex = gun_index;
  8248. }
  8249. for (int index = 0; index < CCS_QUANTITY; index++)
  8250. {
  8251. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8252. {
  8253. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  8254. }
  8255. } // END OF CCS_QUANTITY
  8256. }
  8257. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8258. {
  8259. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8260. {
  8261. tempIndex = ((gun_index==2) ? 1: 0);
  8262. }
  8263. else
  8264. {
  8265. tempIndex = gun_index;
  8266. }
  8267. for (int index = 0; index < GB_QUANTITY; index++)
  8268. {
  8269. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8270. {
  8271. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  8272. }
  8273. } // END OF GB_QUANTITY
  8274. }
  8275. else if(gunType[gun_index] == GUN_TYPE_DO)
  8276. {
  8277. tempIndex = gun_index;
  8278. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8279. {
  8280. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8281. {
  8282. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  8283. }
  8284. }
  8285. }
  8286. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  8287. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  8288. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  8289. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  8290. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  8291. }
  8292. // Message create ====================================================================================================
  8293. if(TRUE)
  8294. {
  8295. json_object *MeterValueReq = json_object_new_object();
  8296. json_object *MeterValues = json_object_new_array();
  8297. json_object *sampledValues = json_object_new_array();
  8298. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  8299. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  8300. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  8301. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  8302. {
  8303. json_object *MeterValue = json_object_new_object();
  8304. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  8305. {
  8306. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  8307. {
  8308. json_object *sampledValue = json_object_new_object();
  8309. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  8310. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  8311. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  8312. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  8313. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  8314. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  8315. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  8316. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  8317. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  8318. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  8319. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  8320. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  8321. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  8322. json_object_array_add(sampledValues, sampledValue);
  8323. }
  8324. }
  8325. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  8326. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  8327. json_object_array_add(MeterValues, MeterValue);
  8328. }
  8329. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  8330. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  8331. ,gun_index + 1
  8332. ,MESSAGE_TYPE_CALL
  8333. ,guid
  8334. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  8335. json_object_put(MeterValueReq);
  8336. }
  8337. // Put request guid to hash map
  8338. sprintf(tempdata, "MeterValues,%d", (gun_index));
  8339. 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*/)
  8340. {
  8341. result = PASS;
  8342. //DEBUG_INFO("MeterValues mapitem pass\n");
  8343. }
  8344. if((dataType != ReadingContext_Trigger) &&
  8345. (dataType != ReadingContext_Sample_Clock) &&
  8346. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  8347. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  8348. else
  8349. {
  8350. if(FirstHeartBeat)
  8351. LWS_Send(queuedata +2);
  8352. }
  8353. return result;
  8354. }
  8355. int sendLogStatusNotificationRequest(char *status)
  8356. {
  8357. mtrace();
  8358. int result = PASS;
  8359. char message[4096]={0};
  8360. char guid[37]={0};
  8361. char tempdata[128]={0};
  8362. json_object *LogStatusNotification = json_object_new_object();
  8363. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  8364. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  8365. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  8366. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  8367. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  8368. random_uuid(guid);
  8369. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  8370. json_object_put(LogStatusNotification);
  8371. LWS_Send(message);
  8372. sprintf(tempdata, "LogStatusNotification,%d", 0);
  8373. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8374. {
  8375. result = PASS;
  8376. }
  8377. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  8378. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  8379. return result;
  8380. }
  8381. int sendSecurityEventNotificationRequest()
  8382. {
  8383. mtrace();
  8384. int result = PASS;
  8385. char message[4096]={0};
  8386. char guid[37]={0};
  8387. char tempdata[128]={0};
  8388. json_object *SecurityEventNotification = json_object_new_object();
  8389. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  8390. //Stop Transaction Time
  8391. struct timeval tmnow;
  8392. struct tm *tm;
  8393. gettimeofday(&tmnow, NULL);
  8394. time_t t;
  8395. t = time(NULL);
  8396. /*UTC time and date*/
  8397. tm = gmtime(&t);
  8398. strftime((char *)ShmOCPP16Data->SecurityEventNotification.timestamp, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.timestamp), "%Y-%m-%dT%H:%M:%SZ", tm);
  8399. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  8400. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  8401. if(strlen((char*)ShmOCPP16Data->SecurityEventNotification.techInfo) > 0)
  8402. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  8403. random_uuid(guid);
  8404. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  8405. json_object_put(SecurityEventNotification);
  8406. LWS_Send(message);
  8407. sprintf(tempdata, "SecurityEventNotification,0");
  8408. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8409. {
  8410. result = PASS;
  8411. }
  8412. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  8413. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  8414. return result;
  8415. }
  8416. int sendSignCertificateRequest()
  8417. {
  8418. mtrace();
  8419. int result = PASS;
  8420. char message[4096]={0};
  8421. char guid[37]={0};
  8422. char tempdata[128]={0};
  8423. json_object *SignCertificate = json_object_new_object();
  8424. DEBUG_INFO("sendSignCertificateRequest...\n");
  8425. // Read csr file content
  8426. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  8427. FILE *fp=fopen(CSR_CP,"r");
  8428. char *line = NULL;
  8429. size_t len = 0;
  8430. while(getline(&line, &len, fp) != -1)
  8431. {
  8432. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  8433. {
  8434. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  8435. }
  8436. }
  8437. fclose(fp);
  8438. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  8439. random_uuid(guid);
  8440. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  8441. json_object_put(SignCertificate);
  8442. LWS_Send(message);
  8443. sprintf(tempdata, "SignCertificate,0");
  8444. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8445. {
  8446. result = PASS;
  8447. }
  8448. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  8449. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  8450. return result;
  8451. }
  8452. int sendSignedFirmwareStatusNotificationRequest(char *status)
  8453. {
  8454. mtrace();
  8455. int result = PASS;
  8456. char message[4096]={0};
  8457. char guid[37]={0};
  8458. char tempdata[128]={0};
  8459. json_object *SignedFirmwareStatusNotification = json_object_new_object();
  8460. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  8461. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  8462. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  8463. json_object_object_add(SignedFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  8464. json_object_object_add(SignedFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  8465. random_uuid(guid);
  8466. sprintf(message,"[%d,\"%s\",\"SignedFirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(SignedFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  8467. json_object_put(SignedFirmwareStatusNotification);
  8468. LWS_Send(message);
  8469. sprintf(tempdata, "SignedFirmwareStatusNotification,%d", 0);
  8470. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8471. {
  8472. result = PASS;
  8473. }
  8474. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  8475. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  8476. return result;
  8477. }
  8478. //==========================================
  8479. // send confirm routine
  8480. //==========================================
  8481. int sendCancelReservationConfirmation(char *uuid,char *payload)
  8482. {
  8483. mtrace();
  8484. int result = FAIL;
  8485. char message[100]={0};
  8486. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  8487. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8488. LWS_Send(message);
  8489. result = TRUE;
  8490. return result;
  8491. }
  8492. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  8493. {
  8494. mtrace();
  8495. int result = FAIL;
  8496. char message[100]={0};
  8497. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  8498. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8499. LWS_Send(message);
  8500. result = TRUE;
  8501. return result;
  8502. }
  8503. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  8504. {
  8505. mtrace();
  8506. int result = FAIL;
  8507. char message[100]={0};
  8508. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  8509. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8510. LWS_Send(message);
  8511. result = TRUE;
  8512. return result;
  8513. }
  8514. int sendClearCacheConfirmation(char *uuid,char *payload)
  8515. {
  8516. mtrace();
  8517. int result = FAIL;
  8518. char message[500]={0};
  8519. DEBUG_INFO("sendClearCacheConfirmation...\n");
  8520. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8521. LWS_Send(message);
  8522. return result;
  8523. }
  8524. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  8525. {
  8526. mtrace();
  8527. int result = FAIL;
  8528. char message[500]={0};
  8529. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  8530. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8531. LWS_Send(message);
  8532. return result;
  8533. }
  8534. int sendDataTransferConfirmation(char *uuid,char *payload)
  8535. {
  8536. mtrace();
  8537. char statusStr[20]={0};
  8538. char dataStr[10]={0};
  8539. char sstr[20]={0};
  8540. int c = 0;
  8541. char *loc;
  8542. int result = FAIL;
  8543. DEBUG_INFO("sendDataTransferConfirmation...\n");
  8544. /**********************status**************************/
  8545. loc = strstr(payload, "status");
  8546. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8547. c = 0;
  8548. while (loc[3+strlen("status")+c] != '\"')
  8549. {
  8550. sstr[c] = loc[3+strlen("status")+c];
  8551. c++;
  8552. }
  8553. sstr[c] = '\0';
  8554. strcpy(statusStr, sstr);
  8555. /**********************data**************************/
  8556. loc = strstr(payload, "data");
  8557. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8558. c = 0;
  8559. while (loc[3+strlen("data")+c] != '\"')
  8560. {
  8561. sstr[c] = loc[3+strlen("data")+c];
  8562. c++;
  8563. }
  8564. sstr[c] = '\0';
  8565. strcpy(dataStr, sstr);
  8566. return result;
  8567. }
  8568. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  8569. {
  8570. mtrace();
  8571. int result = FAIL;
  8572. char message[1000]={0};
  8573. int CompositeScheduleIndex = 0;
  8574. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  8575. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  8576. if(nPeriod == 0)
  8577. {
  8578. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  8579. {
  8580. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  8581. ,MESSAGE_TYPE_CALLRESULT
  8582. ,uuid
  8583. ,payload
  8584. ,connectorIdInt);
  8585. }
  8586. else
  8587. {
  8588. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  8589. ,MESSAGE_TYPE_CALLRESULT
  8590. ,uuid
  8591. ,payload
  8592. ,connectorIdInt
  8593. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8594. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8595. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8596. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  8597. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  8598. }
  8599. }
  8600. else
  8601. {
  8602. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  8603. ,MESSAGE_TYPE_CALLRESULT
  8604. ,uuid
  8605. ,payload
  8606. ,connectorIdInt
  8607. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8608. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8609. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8610. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  8611. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  8612. {
  8613. if (idx_sample == 0)
  8614. {
  8615. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8616. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8617. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8618. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8619. }
  8620. else
  8621. {
  8622. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8623. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8624. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8625. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8626. }
  8627. }
  8628. sprintf(message + strlen(message), "]}}]");
  8629. }
  8630. LWS_Send(message);
  8631. result = TRUE;
  8632. return result;
  8633. }
  8634. int sendGetConfigurationConfirmation(char *uuid)
  8635. {
  8636. mtrace();
  8637. int result = FAIL;
  8638. int MaxKeySupported = 0;
  8639. int sentConfigurationNumber= 0;
  8640. int sentunConfigurationNumber= 0;
  8641. char message[1024*10]={0};
  8642. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  8643. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8644. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  8645. ,MESSAGE_TYPE_CALLRESULT
  8646. ,uuid );
  8647. //configuration key
  8648. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  8649. {
  8650. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  8651. {
  8652. if (sentConfigurationNumber == 0)
  8653. {
  8654. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8655. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8656. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8657. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8658. }
  8659. else
  8660. {
  8661. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8662. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8663. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8664. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8665. }
  8666. sentConfigurationNumber = sentConfigurationNumber + 1;
  8667. }
  8668. }
  8669. sprintf(message + strlen(message), "]");
  8670. if(UnknownKeynum != 0)
  8671. {
  8672. sprintf(message + strlen(message), ",\"unknownKey\":[");
  8673. //unkown key
  8674. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8675. {
  8676. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  8677. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8678. if(sentunConfigurationNumber == 0)
  8679. {
  8680. sprintf(message + strlen(message), "\"%s\""
  8681. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8682. }
  8683. else
  8684. {
  8685. sprintf(message + strlen(message), ",\"%s\""
  8686. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8687. }
  8688. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8689. }
  8690. sprintf(message + strlen(message), "]");
  8691. }
  8692. sprintf(message + strlen(message), "}]");
  8693. LWS_Send(message);
  8694. return result;
  8695. }
  8696. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8697. {
  8698. mtrace();
  8699. int result = FAIL;
  8700. char message[400]={0};
  8701. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8702. if(strcmp(payload,"")==0)
  8703. {
  8704. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8705. }
  8706. else
  8707. {
  8708. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8709. }
  8710. LWS_Send(message);
  8711. result = TRUE;
  8712. return result;
  8713. }
  8714. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8715. {
  8716. mtrace();
  8717. int result = FAIL;
  8718. char message[80]={0};
  8719. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8720. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8721. LWS_Send(message);
  8722. result = TRUE;
  8723. return result;
  8724. }
  8725. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8726. {
  8727. mtrace();
  8728. int result = FAIL;
  8729. char message[80]={0};
  8730. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8731. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8732. LWS_Send(message);
  8733. result = TRUE;
  8734. return result;
  8735. }
  8736. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8737. {
  8738. mtrace();
  8739. int result = FAIL;
  8740. char message[80]={0};
  8741. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8742. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8743. LWS_Send(message);
  8744. result = TRUE;
  8745. return result;
  8746. }
  8747. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8748. {
  8749. mtrace();
  8750. int result = FAIL;
  8751. char message[80]={0};
  8752. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8753. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8754. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8755. LWS_Send(message);
  8756. result = TRUE;
  8757. return result;
  8758. }
  8759. int sendResetConfirmation(char *uuid,char *payload)
  8760. {
  8761. mtrace();
  8762. int result = FAIL;
  8763. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8764. char message[80]={0};
  8765. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8766. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8767. LWS_Send(message);
  8768. result = TRUE;
  8769. return result;
  8770. }
  8771. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8772. {
  8773. mtrace();
  8774. int result = FAIL;
  8775. char message[500]={0};
  8776. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8777. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8778. LWS_Send(message);
  8779. result = TRUE;
  8780. return result;
  8781. }
  8782. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8783. {
  8784. mtrace();
  8785. int result = FAIL;
  8786. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8787. char message[80]={0};
  8788. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8789. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8790. LWS_Send(message);
  8791. result = TRUE;
  8792. return result;
  8793. }
  8794. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8795. {
  8796. mtrace();
  8797. int result = FAIL;
  8798. char message[80]={0};
  8799. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8800. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8801. LWS_Send(message);
  8802. result = TRUE;
  8803. return result;
  8804. }
  8805. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8806. {
  8807. mtrace();
  8808. int result = FAIL;
  8809. char message[80]={0};
  8810. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8811. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8812. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8813. LWS_Send(message);
  8814. result = TRUE;
  8815. return result;
  8816. }
  8817. int sendUpdateFirmwareConfirmation(char *uuid)
  8818. {
  8819. mtrace();
  8820. int result = FAIL;
  8821. char message[60]={0};
  8822. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8823. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8824. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8825. LWS_Send(message);
  8826. result = TRUE;
  8827. return result;
  8828. }
  8829. int sendCertificateSignedConfirmation(char *uuid)
  8830. {
  8831. mtrace();
  8832. int result = PASS;
  8833. char message[4096]={0};
  8834. json_object *CertificateSigned = json_object_new_object();
  8835. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8836. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8837. sprintf(message,"[%d,\"%s\",%s]"
  8838. ,MESSAGE_TYPE_CALLRESULT
  8839. ,uuid
  8840. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8841. json_object_put(CertificateSigned);
  8842. LWS_Send(message);
  8843. return result;
  8844. }
  8845. int sendDeleteCertificateConfirmation(char *uuid)
  8846. {
  8847. mtrace();
  8848. int result = PASS;
  8849. char message[4096]={0};
  8850. json_object *DeleteCertificate = json_object_new_object();
  8851. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8852. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8853. sprintf(message,"[%d,\"%s\",%s]"
  8854. ,MESSAGE_TYPE_CALLRESULT
  8855. ,uuid
  8856. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8857. json_object_put(DeleteCertificate);
  8858. LWS_Send(message);
  8859. return result;
  8860. }
  8861. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8862. {
  8863. mtrace();
  8864. int result = PASS;
  8865. char message[4096]={0};
  8866. json_object *ExtendedTriggerMessage = json_object_new_object();
  8867. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8868. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8869. sprintf(message,"[%d,\"%s\",%s]"
  8870. ,MESSAGE_TYPE_CALLRESULT
  8871. ,uuid
  8872. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8873. json_object_put(ExtendedTriggerMessage);
  8874. LWS_Send(message);
  8875. return result;
  8876. }
  8877. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8878. {
  8879. mtrace();
  8880. int result = PASS;
  8881. char message[4096]={0};
  8882. json_object *GetInstalledCertificateIds = json_object_new_object();
  8883. json_object *certificateHashDataDatas = json_object_new_array();
  8884. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8885. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8886. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8887. {
  8888. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8889. {
  8890. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm) > 0)
  8891. {
  8892. json_object *certificateHashData = json_object_new_object();
  8893. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8894. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8895. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8896. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8897. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8898. }
  8899. }
  8900. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8901. }
  8902. else
  8903. {
  8904. json_object_put(certificateHashDataDatas);
  8905. }
  8906. sprintf(message,"[%d,\"%s\",%s]"
  8907. ,MESSAGE_TYPE_CALLRESULT
  8908. ,uuid
  8909. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8910. json_object_put(GetInstalledCertificateIds);
  8911. LWS_Send(message);
  8912. return result;
  8913. }
  8914. int sendGetLogConfirmation(char *uuid)
  8915. {
  8916. mtrace();
  8917. int result = PASS;
  8918. char message[4096]={0};
  8919. json_object *GetLog = json_object_new_object();
  8920. DEBUG_INFO("sendGetLogConfirmation...\n");
  8921. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8922. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8923. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8924. sprintf(message,"[%d,\"%s\",%s]"
  8925. ,MESSAGE_TYPE_CALLRESULT
  8926. ,uuid
  8927. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8928. json_object_put(GetLog);
  8929. LWS_Send(message);
  8930. return result;
  8931. }
  8932. int sendInstallCertificateConfirmation(char *uuid)
  8933. {
  8934. mtrace();
  8935. int result = PASS;
  8936. char message[4096]={0};
  8937. json_object *InstallCertificate = json_object_new_object();
  8938. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8939. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8940. sprintf(message,"[%d,\"%s\",%s]"
  8941. ,MESSAGE_TYPE_CALLRESULT
  8942. ,uuid
  8943. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8944. json_object_put(InstallCertificate);
  8945. LWS_Send(message);
  8946. return result;
  8947. }
  8948. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8949. {
  8950. mtrace();
  8951. int result = PASS;
  8952. char message[4096]={0};
  8953. json_object *SignedUpdateFirmware = json_object_new_object();
  8954. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8955. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8956. sprintf(message,"[%d,\"%s\",%s]"
  8957. ,MESSAGE_TYPE_CALLRESULT
  8958. ,uuid
  8959. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8960. json_object_put(SignedUpdateFirmware);
  8961. LWS_Send(message);
  8962. return result;
  8963. }
  8964. int sendUnknownConfirmation(char *uuid)
  8965. {
  8966. mtrace();
  8967. int result = PASS;
  8968. char message[256]={0};
  8969. DEBUG_INFO("sendUnknownConfirmation...\n");
  8970. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8971. LWS_Send(message);
  8972. return result;
  8973. }
  8974. //==========================================
  8975. // Handle server request routine Start
  8976. //==========================================
  8977. int handleCancelReservationRequest(char *uuid, char *payload)
  8978. {
  8979. mtrace();
  8980. int result = FAIL;
  8981. int gunNO = 0;
  8982. int reservationIdInt = -1;
  8983. char comfirmstr[20];
  8984. DEBUG_INFO("handleCancelReservationRequest...\n");
  8985. json_object *CancelReservation;
  8986. CancelReservation = json_tokener_parse(payload);
  8987. if(!is_error(CancelReservation))
  8988. {
  8989. // Required data
  8990. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8991. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8992. }
  8993. json_object_put(CancelReservation);
  8994. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8995. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8996. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8997. if(reservationIdInt != -1)
  8998. {
  8999. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9000. //check Transaction active
  9001. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  9002. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9003. {
  9004. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  9005. {
  9006. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  9007. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  9008. if(gunType[2] == GUN_TYPE_CHAdeMO)
  9009. {
  9010. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  9011. }
  9012. else
  9013. {
  9014. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  9015. }
  9016. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  9017. goto end;
  9018. }
  9019. }
  9020. for (int index = 0; index < CCS_QUANTITY; index++)
  9021. {
  9022. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  9023. {
  9024. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  9025. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  9026. if(gunType[2] == GUN_TYPE_CCS)
  9027. {
  9028. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  9029. }
  9030. else
  9031. {
  9032. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  9033. }
  9034. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  9035. goto end;
  9036. }
  9037. }
  9038. for (int index = 0; index < GB_QUANTITY; index++)
  9039. {
  9040. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  9041. {
  9042. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  9043. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  9044. if(gunType[2] == GUN_TYPE_GBT)
  9045. {
  9046. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  9047. }
  9048. else
  9049. {
  9050. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  9051. }
  9052. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  9053. goto end;
  9054. }
  9055. }
  9056. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9057. {
  9058. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  9059. {
  9060. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  9061. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  9062. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  9063. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  9064. goto end;
  9065. }
  9066. }
  9067. for (int index = 0; index < AC_QUANTITY; index++)
  9068. {
  9069. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  9070. {
  9071. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  9072. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  9073. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9074. {
  9075. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  9076. }
  9077. else
  9078. {
  9079. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  9080. }
  9081. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  9082. goto end;
  9083. }
  9084. }
  9085. }
  9086. //The reservationId does NOT match the reservationId
  9087. sendCancelReservationConfirmation(uuid, comfirmstr);
  9088. end:
  9089. // Fill in ocpp packet uuid
  9090. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  9091. return result;
  9092. }
  9093. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  9094. {
  9095. mtrace();
  9096. int result = FAIL;
  9097. int gunIndex = -1;
  9098. char typeStr[16]={0};
  9099. char comfirmstr[20];
  9100. int specificId = FALSE;
  9101. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  9102. json_object *ChangeAvailability;
  9103. ChangeAvailability = json_tokener_parse(payload);
  9104. if(!is_error(ChangeAvailability))
  9105. {
  9106. // Required data
  9107. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  9108. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  9109. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  9110. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  9111. }
  9112. json_object_put(ChangeAvailability);
  9113. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  9114. {
  9115. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  9116. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  9117. }
  9118. else if(gunIndex == 0)
  9119. {
  9120. for(int i=0; i < gunTotalNumber; i++)
  9121. {
  9122. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  9123. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  9124. }
  9125. }
  9126. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  9127. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9128. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  9129. {
  9130. specificId = TRUE;
  9131. }
  9132. if(specificId == FALSE)
  9133. goto end;
  9134. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  9135. {
  9136. //----------------------gunIndex is 0 ------------------------------------------------//
  9137. if(gunIndex == 0)
  9138. {
  9139. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9140. {
  9141. for(int i=0; i < gunTotalNumber; i++)
  9142. {
  9143. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9144. {
  9145. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  9146. {
  9147. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  9148. {
  9149. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9150. goto end;
  9151. }
  9152. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9153. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9154. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9155. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9156. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9157. {
  9158. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9159. goto end;
  9160. }
  9161. }
  9162. }//END FOR CHAdeMO_QUANTITY
  9163. for (int index = 0; index < CCS_QUANTITY; index++)
  9164. {
  9165. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  9166. {
  9167. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  9168. {
  9169. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9170. goto end;
  9171. }
  9172. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9173. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9174. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9175. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9176. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9177. {
  9178. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9179. goto end;
  9180. }
  9181. }
  9182. }//END FOR CCS_QUANTITY
  9183. for (int index = 0; index < GB_QUANTITY; index++)
  9184. {
  9185. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  9186. {
  9187. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  9188. {
  9189. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9190. goto end;
  9191. }
  9192. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9193. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9194. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9195. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9196. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9197. {
  9198. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9199. goto end;
  9200. }
  9201. }
  9202. }// END FOR GB_QUANTITY
  9203. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9204. {
  9205. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  9206. {
  9207. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  9208. {
  9209. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9210. goto end;
  9211. }
  9212. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  9213. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  9214. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9215. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  9216. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9217. {
  9218. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9219. goto end;
  9220. }
  9221. }
  9222. }// END FOR GENERAL_GUN_QUANTITY
  9223. for (int index = 0; index < AC_QUANTITY; index++)
  9224. {
  9225. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  9226. {
  9227. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  9228. {
  9229. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9230. goto end;
  9231. }
  9232. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9233. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9234. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9235. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9236. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9237. {
  9238. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9239. goto end;
  9240. }
  9241. }
  9242. }//END FOR AC_QUANTITY
  9243. }// END FOR gunTotalNumber
  9244. }
  9245. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  9246. {
  9247. for(int i=0; i < gunTotalNumber; i++)
  9248. {
  9249. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  9250. {
  9251. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9252. goto end;
  9253. }
  9254. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9255. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  9256. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  9257. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  9258. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9259. {
  9260. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9261. goto end;
  9262. }
  9263. }
  9264. }
  9265. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9266. goto end;
  9267. }
  9268. //----------------------gunIndex is not 0 ------------------------------------------------//
  9269. //check Transaction active
  9270. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9271. {
  9272. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  9273. {
  9274. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  9275. {
  9276. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9277. goto end;
  9278. }
  9279. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9280. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9281. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9282. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9283. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9284. {
  9285. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9286. goto end;
  9287. }
  9288. else
  9289. {
  9290. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  9291. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9292. goto end;
  9293. }
  9294. }
  9295. }//END FOR CHAdeMO_QUANTITY
  9296. for (int index = 0; index < CCS_QUANTITY; index++)
  9297. {
  9298. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  9299. {
  9300. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  9301. {
  9302. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9303. goto end;
  9304. }
  9305. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9306. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9307. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9308. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9309. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9310. {
  9311. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9312. goto end;
  9313. }
  9314. else
  9315. {
  9316. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  9317. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9318. goto end;
  9319. }
  9320. }
  9321. }//END FOR CCS_QUANTITY
  9322. for (int index = 0; index < GB_QUANTITY; index++)
  9323. {
  9324. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  9325. {
  9326. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  9327. {
  9328. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9329. goto end;
  9330. }
  9331. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9332. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9333. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9334. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9335. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9336. {
  9337. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9338. goto end;
  9339. }
  9340. else
  9341. {
  9342. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  9343. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9344. goto end;
  9345. }
  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))
  9351. {
  9352. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  9353. {
  9354. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9355. goto end;
  9356. }
  9357. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  9358. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  9359. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9360. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  9361. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9362. {
  9363. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9364. goto end;
  9365. }
  9366. else
  9367. {
  9368. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  9369. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9370. goto end;
  9371. }
  9372. }
  9373. }// END FOR GENERAL_GUN_QUANTITY
  9374. for (int index = 0; index < AC_QUANTITY; index++)
  9375. {
  9376. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  9377. {
  9378. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  9379. {
  9380. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9381. goto end;
  9382. }
  9383. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9384. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9385. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9386. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9387. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9388. {
  9389. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9390. goto end;
  9391. }
  9392. else
  9393. {
  9394. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  9395. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9396. goto end;
  9397. }
  9398. }
  9399. }//END FOR AC_QUANTITY
  9400. }//END FOR AvailabilityTypeStr[Inoperative]
  9401. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  9402. {
  9403. //----------------------gunIndex is 0 ------------------------------------------------//
  9404. if(gunIndex == 0)
  9405. {
  9406. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9407. {
  9408. for(int i=0; i < gunTotalNumber; i++)
  9409. {
  9410. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9411. {
  9412. 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
  9413. {
  9414. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9415. goto end;
  9416. }
  9417. }//END FOR CHAdeMO_QUANTITY
  9418. for (int index = 0; index < CCS_QUANTITY; index++)
  9419. {
  9420. 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
  9421. {
  9422. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9423. goto end;
  9424. }
  9425. }//END FOR CCS_QUANTITY
  9426. for (int index = 0; index < GB_QUANTITY; index++)
  9427. {
  9428. 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
  9429. {
  9430. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9431. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9432. goto end;
  9433. }
  9434. }// END FOR GB_QUANTITY
  9435. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9436. {
  9437. 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
  9438. {
  9439. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9440. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9441. goto end;
  9442. }
  9443. }// END FOR GENERAL_GUN_QUANTITY
  9444. for (int index = 0; index < AC_QUANTITY; index++)
  9445. {
  9446. 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
  9447. {
  9448. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9449. goto end;
  9450. }
  9451. }//END FOR CHAdeMO_QUANTITY
  9452. }// END FOR gunTotalNumber
  9453. }
  9454. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  9455. {
  9456. for(int i=0; i < gunTotalNumber; i++)
  9457. {
  9458. for (int index = 0; index < AC_QUANTITY; index++)
  9459. {
  9460. 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
  9461. {
  9462. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9463. goto end;
  9464. }
  9465. }//END FOR CHAdeMO_QUANTITY
  9466. } // END FOR gunTotalNumber
  9467. }
  9468. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9469. goto end;
  9470. }
  9471. //----------------------gunIndex is not 0 ------------------------------------------------//
  9472. //check Transaction active
  9473. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9474. {
  9475. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9476. {
  9477. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9478. goto end;
  9479. }
  9480. }//END FOR CHAdeMO_QUANTITY
  9481. for (int index = 0; index < CCS_QUANTITY; index++)
  9482. {
  9483. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9484. {
  9485. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9486. goto end;
  9487. }
  9488. }//END FOR CCS_QUANTITY
  9489. for (int index = 0; index < GB_QUANTITY; index++)
  9490. {
  9491. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9492. {
  9493. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9494. goto end;
  9495. }
  9496. }// END FOR GB_QUANTITY
  9497. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9498. {
  9499. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9500. {
  9501. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9502. goto end;
  9503. }
  9504. }// END FOR GENERAL_GUN_QUANTITY
  9505. for (int index = 0; index < AC_QUANTITY; index++)
  9506. {
  9507. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9508. {
  9509. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9510. goto end;
  9511. }
  9512. }//END FOR AC_QUANTITY
  9513. }//END FOR AvailabilityTypeStr[Operative]
  9514. end:
  9515. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9516. {
  9517. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  9518. }
  9519. else
  9520. {
  9521. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  9522. }
  9523. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9524. {
  9525. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9526. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9527. }
  9528. else if(gunIndex == 0)
  9529. {
  9530. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9531. {
  9532. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  9533. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  9534. }
  9535. }
  9536. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  9537. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9538. return result;
  9539. }
  9540. int handleChangeConfigurationRequest(char *uuid, char *payload)
  9541. {
  9542. mtrace();
  9543. int valueInvalid = NO;
  9544. int result = FAIL;
  9545. char keystr[40]={0};
  9546. char valuestr[501]={0}; //value should be limited in 500 bytes
  9547. char comfirmstr[20]={0};
  9548. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  9549. json_object *ChangeConfiguration;
  9550. ChangeConfiguration = json_tokener_parse(payload);
  9551. if(!is_error(ChangeConfiguration))
  9552. {
  9553. // Required data
  9554. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  9555. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  9556. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  9557. {
  9558. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  9559. }
  9560. else
  9561. {
  9562. valueInvalid = YES;
  9563. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  9564. }
  9565. }
  9566. json_object_put(ChangeConfiguration);
  9567. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  9568. {
  9569. DEBUG_ERROR("Payload is null or value is invalid.\n");
  9570. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9571. }
  9572. else
  9573. {
  9574. int status = setKeyValue(keystr, valuestr);
  9575. switch(status)
  9576. {
  9577. case ConfigurationStatus_Accepted:
  9578. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  9579. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  9580. StoreConfigurationTable();
  9581. break;
  9582. case RebootRequired:
  9583. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  9584. StoreConfigurationTable();
  9585. break;
  9586. case NotSupported:
  9587. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  9588. break;
  9589. case ConfigurationStatus_Rejected:
  9590. default:
  9591. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9592. break;
  9593. }
  9594. }
  9595. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  9596. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  9597. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9598. {
  9599. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9600. SetOcppConnStatus(FALSE);
  9601. }
  9602. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9603. {
  9604. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9605. }
  9606. return result;
  9607. }
  9608. int handleClearCacheRequest(char *uuid, char *payload)
  9609. {
  9610. mtrace();
  9611. int result = FAIL;
  9612. char comfirmstr[20];
  9613. char rmFileCmd[100]={0};
  9614. struct stat stats;
  9615. DEBUG_INFO("handleClearCacheRequest...\n");
  9616. stat("/Storage/OCPP", &stats);
  9617. // Check for directory existence
  9618. if (S_ISDIR(stats.st_mode) == 1)
  9619. {}
  9620. else
  9621. {
  9622. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  9623. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  9624. system(rmFileCmd);
  9625. }
  9626. if(OCPP_cleanLocalCache())
  9627. {
  9628. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  9629. }
  9630. else
  9631. {
  9632. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  9633. }
  9634. sendClearCacheConfirmation(uuid, comfirmstr);
  9635. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9636. return result;
  9637. }
  9638. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9639. {
  9640. mtrace();
  9641. int result = FAIL;
  9642. int resultRename;
  9643. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9644. char chargingProfilePurposeStr[26]={0};
  9645. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9646. char tempchargingProfilePurposeStr[26]={0};
  9647. char str[100]={0};
  9648. char fname[200]={0};
  9649. char comfirmstr[20]={0};
  9650. char word[1600]={0};
  9651. int clearflag = FALSE;
  9652. int chargingProfileIdIsNULL = FALSE;
  9653. int connectorIsNULL = FALSE;
  9654. int chargingProfilePurposeIsNULL = FALSE;
  9655. int stackLevelIsNULL = FALSE;
  9656. //int GotoEnd = FALSE;
  9657. FILE *fptr1, *fptr2;
  9658. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9659. int n_chargingProfile=0;
  9660. int isEmptyFile = FALSE;
  9661. char sLineWord[1600]={0};
  9662. char chargingProfiles[10][100]={0};
  9663. int ChargeProfileCount = 0;
  9664. int ch;
  9665. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9666. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9667. json_object *ClearChargingProfile;
  9668. ClearChargingProfile = json_tokener_parse(payload);
  9669. if(!is_error(ClearChargingProfile))
  9670. {
  9671. // Optional data
  9672. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9673. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9674. else
  9675. chargingProfileIdIsNULL = TRUE;
  9676. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9677. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9678. else
  9679. connectorIsNULL = TRUE;
  9680. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9681. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9682. else
  9683. chargingProfilePurposeIsNULL = TRUE;
  9684. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9685. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9686. else
  9687. stackLevelIsNULL = TRUE;
  9688. }
  9689. json_object_put(ClearChargingProfile);
  9690. if(connectorIsNULL == FALSE)
  9691. {
  9692. switch(connectorIdInt)
  9693. {
  9694. case 0:
  9695. if(chargingProfilePurposeIsNULL == TRUE)
  9696. {
  9697. int l = 0;
  9698. strcpy(fname, ChargePointMaxProfile_JSON);
  9699. if((access(fname,F_OK))!=-1)
  9700. {
  9701. strcpy(chargingProfiles[l], fname);
  9702. l = l + 1;
  9703. }
  9704. strcpy(fname, TxDefaultProfile_0_JSON);
  9705. if((access(fname,F_OK))!=-1)
  9706. {
  9707. strcpy(chargingProfiles[l], fname);
  9708. l = l + 1;
  9709. }
  9710. ChargeProfileCount = l;
  9711. }
  9712. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  9713. {
  9714. strcpy(fname, ChargePointMaxProfile_JSON);
  9715. if((access(fname,F_OK))!=-1)
  9716. {
  9717. strcpy(chargingProfiles[0], fname);
  9718. ChargeProfileCount = 1;
  9719. }
  9720. }
  9721. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9722. {
  9723. strcpy(fname, TxDefaultProfile_0_JSON);
  9724. if((access(fname,F_OK))!=-1)
  9725. {
  9726. strcpy(chargingProfiles[0], fname);
  9727. ChargeProfileCount = 1;
  9728. }
  9729. }
  9730. break;
  9731. default:
  9732. if(chargingProfilePurposeIsNULL == TRUE)
  9733. {
  9734. int m = 0;
  9735. memset(fname, 0, ARRAY_SIZE(fname));
  9736. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9737. if((access(fname,F_OK))!=-1)
  9738. {
  9739. strcpy(chargingProfiles[m], fname);
  9740. m = m + 1;
  9741. }
  9742. memset(fname, 0, ARRAY_SIZE(fname));
  9743. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9744. if((access(fname,F_OK))!=-1)
  9745. {
  9746. strcpy(chargingProfiles[m], fname);
  9747. m = m + 1;
  9748. }
  9749. ChargeProfileCount = m;
  9750. }
  9751. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9752. {
  9753. //strcpy(fname, TxDefaultProfile_1_JSON);
  9754. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9755. if((access(fname,F_OK))!=-1)
  9756. {
  9757. strcpy(chargingProfiles[0], fname);
  9758. ChargeProfileCount = 1;
  9759. }
  9760. }
  9761. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9762. {
  9763. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9764. if((access(fname,F_OK))!=-1)
  9765. {
  9766. strcpy(chargingProfiles[0], fname);
  9767. ChargeProfileCount = 1;
  9768. }
  9769. //strcpy(fname, TxProfile_1_JSON);
  9770. }
  9771. //strcpy(fname, ChargePointMaxProfile_JSON );
  9772. break;
  9773. }
  9774. }
  9775. else // Check all Charging Profiles
  9776. {
  9777. int i = 0;
  9778. char fnametemp[200]={0};
  9779. ChargeProfileCount = 0;
  9780. //Check ChargePointMaxProfile.json exit
  9781. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9782. {
  9783. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9784. i = i + 1;
  9785. }
  9786. //Check TxDefaultProfile_0.json exit
  9787. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9788. {
  9789. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9790. i = i + 1;
  9791. }
  9792. //Check TxDefaultProfile_%d.json
  9793. for(int j=1; j <= gunTotalNumber; j++)
  9794. {
  9795. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9796. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9797. if((access(fnametemp,F_OK))!=-1)
  9798. {
  9799. strcpy(chargingProfiles[i], fnametemp);
  9800. i = i + 1;
  9801. }
  9802. }
  9803. //Check TxProfile_%d.json
  9804. for(int j=1; j <= gunTotalNumber; j++)
  9805. {
  9806. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9807. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9808. if((access(fnametemp,F_OK))!=-1)
  9809. {
  9810. strcpy(chargingProfiles[i], fnametemp);
  9811. i = i + 1;
  9812. }
  9813. }
  9814. ChargeProfileCount = i;
  9815. }// End connectorIsNULL is TRUE
  9816. if(ChargeProfileCount == 0)
  9817. {
  9818. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9819. goto end;
  9820. }
  9821. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9822. {
  9823. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9824. goto end;
  9825. }
  9826. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9827. {
  9828. memset(str, 0, ARRAY_SIZE(str));
  9829. // clear temp file
  9830. sprintf(str,"rm -f %s",temp);
  9831. system(str);
  9832. for(int k=0; k < ChargeProfileCount; k++)
  9833. {
  9834. memset(str, 0, ARRAY_SIZE(str));
  9835. //clear file in C
  9836. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9837. system(str);
  9838. }
  9839. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9840. goto end;
  9841. }
  9842. else if(connectorIsNULL == TRUE)
  9843. {
  9844. for(int k=0; k < ChargeProfileCount; k++)
  9845. {
  9846. fptr1 = fopen(chargingProfiles[k], "r");
  9847. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9848. //Check Charging Profile Count
  9849. while(fscanf(fptr1, "%s", word) != EOF)
  9850. {
  9851. //DEBUG_INFO("word=%s\n",word);
  9852. if(strstr(word, "chargingProfileId")!= NULL)
  9853. {
  9854. //DEBUG_INFO("test chargingProfileId \n");
  9855. n_chargingProfile = n_chargingProfile + 1;
  9856. //DEBUG_INFO("chargingProfileId Found\n");
  9857. }
  9858. }
  9859. rewind(fptr1);
  9860. //search Charging Profile Element
  9861. //int i= 0;
  9862. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9863. {
  9864. json_object *tmpProfilee;
  9865. tmpProfilee = json_tokener_parse(sLineWord);
  9866. if(!is_error(tmpProfilee))
  9867. {
  9868. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9869. {
  9870. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9871. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9872. }
  9873. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9874. {
  9875. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9876. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9877. }
  9878. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9879. {
  9880. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9881. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9882. }
  9883. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9884. {
  9885. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9886. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9887. }
  9888. }
  9889. json_object_put(tmpProfilee);
  9890. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9891. {
  9892. //------- not write to fptr2-------//
  9893. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9894. //clearflag = TRUE;
  9895. }
  9896. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9897. {
  9898. //------- not write to fptr2-------//
  9899. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9900. }
  9901. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9902. {
  9903. //------- not write to fptr2-------//
  9904. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9905. }
  9906. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9907. {
  9908. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9909. }
  9910. else
  9911. {
  9912. fprintf(fptr2, sLineWord);//writing data into file
  9913. }
  9914. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9915. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9916. if(clearflag == TRUE)
  9917. {
  9918. fclose(fptr1);
  9919. fclose(fptr2);
  9920. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9921. system(str);
  9922. // clear temp file
  9923. sprintf(str,"rm -f %s",temp);
  9924. system(str);
  9925. }
  9926. else
  9927. {
  9928. fclose(fptr1);
  9929. fclose(fptr2);
  9930. memset(str, 0, ARRAY_SIZE(str));
  9931. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9932. system(str);
  9933. resultRename = rename(temp, chargingProfiles[k]);
  9934. if(resultRename == 0)
  9935. {
  9936. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9937. }
  9938. else
  9939. {
  9940. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9941. }
  9942. if(comfirmstr[0]== 0)
  9943. {
  9944. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9945. }
  9946. //Check chargingProfile is empty file
  9947. /*------ Read the file ----------------*/
  9948. fptr1=fopen(chargingProfiles[k],"r");
  9949. ch=fgetc(fptr1);
  9950. rewind(fptr1);
  9951. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9952. if(ch!=EOF)
  9953. {
  9954. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9955. {
  9956. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9957. if(sLineWord[0]=='\0')
  9958. {
  9959. isEmptyFile = TRUE;
  9960. break;
  9961. }
  9962. else
  9963. {
  9964. isEmptyFile = FALSE;
  9965. break;
  9966. }
  9967. }
  9968. }
  9969. else
  9970. isEmptyFile = TRUE;
  9971. fclose(fptr1);
  9972. if(isEmptyFile == TRUE)
  9973. {
  9974. memset(str, 0, ARRAY_SIZE(str));
  9975. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9976. system(str);
  9977. }
  9978. }
  9979. }// End of while(int k=0; k < ChargePointCount; k++)
  9980. }
  9981. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9982. {
  9983. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9984. for(int k=0; k < ChargeProfileCount; k++)
  9985. {
  9986. fptr1 = fopen(chargingProfiles[k], "r");
  9987. fptr2 = fopen(temp, "w+");
  9988. //Check Charging Profile Count
  9989. while(fscanf(fptr1, "%s", word) != EOF)
  9990. {
  9991. //DEBUG_INFO("word=%s\n",word);
  9992. if(strstr(word, "chargingProfileId")!= NULL)
  9993. {
  9994. n_chargingProfile = n_chargingProfile + 1;
  9995. }
  9996. }
  9997. rewind(fptr1);
  9998. //search Charging Profile Element
  9999. //int i= 0;
  10000. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  10001. {
  10002. json_object *tmpProfilee;
  10003. tmpProfilee = json_tokener_parse(sLineWord);
  10004. if(!is_error(tmpProfilee))
  10005. {
  10006. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  10007. {
  10008. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  10009. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  10010. }
  10011. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  10012. {
  10013. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  10014. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  10015. }
  10016. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  10017. {
  10018. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  10019. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  10020. }
  10021. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10022. {
  10023. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  10024. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  10025. }
  10026. }
  10027. json_object_put(tmpProfilee);
  10028. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  10029. {
  10030. //------- not write to fptr2-------//
  10031. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  10032. //clearflag = TRUE;
  10033. }
  10034. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  10035. {
  10036. //------- not write to fptr2-------//
  10037. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  10038. }
  10039. else if(stackLevelIsNULL == TRUE)
  10040. {
  10041. //Clear Whole File
  10042. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  10043. clearflag = TRUE;
  10044. break;
  10045. }
  10046. else
  10047. {
  10048. fprintf(fptr2, sLineWord);//writing data into file
  10049. }
  10050. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  10051. }
  10052. if(clearflag == TRUE)
  10053. {
  10054. fclose(fptr1);
  10055. fclose(fptr2);
  10056. sprintf(str,"rm -f %s",chargingProfiles[k]);
  10057. system(str);
  10058. // clear temp file
  10059. sprintf(str,"rm -f %s",temp);
  10060. system(str);
  10061. }
  10062. else
  10063. {
  10064. fclose(fptr1);
  10065. fclose(fptr2);
  10066. sprintf(str,"rm -f %s",chargingProfiles[k]);
  10067. system(str);
  10068. resultRename = rename(temp, chargingProfiles[k]);
  10069. if(resultRename == 0)
  10070. {
  10071. DEBUG_INFO("File ChargingProfile renamed successfully");
  10072. }
  10073. else
  10074. {
  10075. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  10076. }
  10077. if(comfirmstr[0]== 0)
  10078. {
  10079. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  10080. }
  10081. //Check chargingProfile is empty file
  10082. /*------ Read the file ----------------*/
  10083. fptr1=fopen(chargingProfiles[k],"r");
  10084. ch=fgetc(fptr1);
  10085. rewind(fptr1);
  10086. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  10087. if(ch!=EOF)
  10088. {
  10089. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  10090. {
  10091. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  10092. if(sLineWord[0]=='\0')
  10093. {
  10094. isEmptyFile = TRUE;
  10095. break;
  10096. }
  10097. else
  10098. {
  10099. isEmptyFile = FALSE;
  10100. break;
  10101. }
  10102. }
  10103. }
  10104. else
  10105. isEmptyFile = TRUE;
  10106. fclose(fptr1);
  10107. if(isEmptyFile == TRUE)
  10108. {
  10109. memset(str, 0, ARRAY_SIZE(str));
  10110. sprintf(str,"rm -f %s",chargingProfiles[k]);
  10111. system(str);
  10112. }
  10113. /*------- End of reading ---------------*/
  10114. }
  10115. } // while(int k=0; k < ChargeProfileCount; k++)
  10116. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  10117. end:
  10118. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  10119. {
  10120. if(connectorIdInt == 0)
  10121. {
  10122. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10123. {
  10124. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  10125. }
  10126. }
  10127. else
  10128. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  10129. }
  10130. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  10131. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10132. return result;
  10133. }
  10134. void createFirmwareVersionByDataTransfer(void)
  10135. {
  10136. json_object *FirmwareDataTransfer = json_object_new_object();
  10137. // AC & DC model
  10138. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  10139. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  10140. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  10141. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  10142. // DC model
  10143. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  10144. {
  10145. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  10146. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  10147. (gunType[3] != GUN_TYPE_UNKNOWN))
  10148. {
  10149. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  10150. }
  10151. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  10152. {
  10153. // DS DM DW
  10154. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  10155. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  10156. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  10157. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  10158. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  10159. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  10160. }
  10161. else
  10162. {
  10163. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  10164. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  10165. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  10166. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  10167. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  10168. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  10169. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  10170. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  10171. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  10172. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  10173. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  10174. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  10175. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  10176. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  10177. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  10178. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  10179. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  10180. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  10181. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  10182. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  10183. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  10184. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  10185. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  10186. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  10187. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  10188. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  10189. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  10190. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  10191. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  10192. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  10193. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  10194. }
  10195. }
  10196. // 4G model
  10197. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  10198. {
  10199. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  10200. }
  10201. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  10202. json_object_put(FirmwareDataTransfer);
  10203. }
  10204. int handleDataTransferRequest(char *uuid, char *payload)
  10205. {
  10206. mtrace();
  10207. json_object *response = json_object_new_object();
  10208. int result = FAIL;
  10209. char tempvendorId[255]={0};
  10210. char tempmessageId[50]={0};
  10211. char tempdata[10240]={0};
  10212. char message[20480]={0};
  10213. DEBUG_INFO("handleDataTransferRequest...\n");
  10214. if((uuid != NULL) && (payload != NULL))
  10215. {
  10216. json_object *DataTransfer;
  10217. DataTransfer = json_tokener_parse(payload);
  10218. if(!is_error(DataTransfer))
  10219. {
  10220. // Required data
  10221. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  10222. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  10223. // Optional data
  10224. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  10225. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  10226. if(json_object_object_get(DataTransfer, "data") != NULL)
  10227. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  10228. result = PASS;
  10229. }
  10230. json_object_put(DataTransfer);
  10231. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  10232. {
  10233. // Send all moudle firmware version on EVSE
  10234. createFirmwareVersionByDataTransfer();
  10235. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10236. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10237. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10238. json_object_put(response);
  10239. }
  10240. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  10241. {
  10242. system("/usr/bin/run_tmate_restart.sh &");
  10243. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10244. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10245. json_object_put(response);
  10246. }
  10247. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  10248. {
  10249. json_object *data;
  10250. data = json_tokener_parse(tempdata);
  10251. if(!is_error(data))
  10252. {
  10253. 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))
  10254. {
  10255. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10256. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  10257. if(json_object_object_get(data, "SOC") != NULL)
  10258. {
  10259. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  10260. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  10261. }
  10262. if(json_object_object_get(data, "Energy") != NULL)
  10263. {
  10264. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  10265. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  10266. }
  10267. if(json_object_object_get(data, "Duration") != NULL)
  10268. {
  10269. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  10270. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  10271. }
  10272. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10273. }
  10274. else
  10275. {
  10276. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10277. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  10278. }
  10279. }
  10280. else
  10281. {
  10282. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10283. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10284. }
  10285. json_object_put(data);
  10286. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10287. json_object_put(response);
  10288. }
  10289. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  10290. {
  10291. json_object *data;
  10292. data = json_tokener_parse(tempdata);
  10293. if(!is_error(data))
  10294. {
  10295. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  10296. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  10297. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  10298. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  10299. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  10300. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  10301. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  10302. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  10303. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  10304. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  10305. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10306. }
  10307. else
  10308. {
  10309. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10310. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10311. }
  10312. json_object_put(data);
  10313. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10314. json_object_put(response);
  10315. }
  10316. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  10317. {
  10318. json_object *data;
  10319. data = json_tokener_parse(tempdata);
  10320. if(!is_error(data))
  10321. {
  10322. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  10323. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10324. if(json_object_object_get(data, "idToken") != NULL)
  10325. {
  10326. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  10327. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  10328. }
  10329. else
  10330. {
  10331. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10332. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  10333. }
  10334. if(json_object_object_get(data, "price") != NULL) //v1.0
  10335. {
  10336. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  10337. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  10338. }
  10339. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  10340. {
  10341. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10342. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10343. }
  10344. else
  10345. {
  10346. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10347. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  10348. }
  10349. }
  10350. else
  10351. {
  10352. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10353. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10354. }
  10355. json_object_put(data);
  10356. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10357. json_object_put(response);
  10358. }
  10359. else if(strstr(tempmessageId, "RunningCost") != NULL)
  10360. {
  10361. json_object *data;
  10362. data = json_tokener_parse(tempdata);
  10363. if(!is_error(data))
  10364. {
  10365. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10366. if(json_object_object_get(data, "txId") != NULL)
  10367. {
  10368. // California pricing V1.0
  10369. DEBUG_INFO("California pricing V1.0\n");
  10370. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  10371. sprintf((char*)dmsVersion, "1.0");
  10372. for(int idx = 0;idx<gunTotalNumber;idx++)
  10373. {
  10374. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10375. {
  10376. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  10377. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  10378. if(json_object_object_get(data, "description") != NULL)
  10379. {
  10380. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  10381. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  10382. }
  10383. else
  10384. {
  10385. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10386. json_object_object_add(response, "data", json_object_new_string("description not found."));
  10387. }
  10388. }
  10389. }
  10390. }
  10391. else if(json_object_object_get(data, "transactionId") != NULL)
  10392. {
  10393. // California pricing V2.0
  10394. DEBUG_INFO("California pricing V2.0\n");
  10395. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  10396. sprintf((char*)dmsVersion, "2.0");
  10397. for(int idx=0;idx<gunTotalNumber;idx++)
  10398. {
  10399. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  10400. {
  10401. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10402. if(json_object_object_get(data, "timestamp") != NULL)
  10403. {
  10404. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  10405. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  10406. }
  10407. else
  10408. {
  10409. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10410. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  10411. }
  10412. if(json_object_object_get(data, "meterValue") != NULL)
  10413. {
  10414. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  10415. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  10416. }
  10417. else
  10418. {
  10419. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10420. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  10421. }
  10422. if(json_object_object_get(data, "cost") != NULL)
  10423. {
  10424. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  10425. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10426. }
  10427. else
  10428. {
  10429. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10430. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10431. }
  10432. if(json_object_object_get(data, "state") != NULL)
  10433. {
  10434. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  10435. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  10436. }
  10437. else
  10438. {
  10439. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10440. json_object_object_add(response, "data", json_object_new_string("state not found."));
  10441. }
  10442. if(json_object_object_get(data, "chargingPrice") != NULL)
  10443. {
  10444. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  10445. {
  10446. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  10447. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  10448. }
  10449. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  10450. {
  10451. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  10452. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  10453. }
  10454. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  10455. {
  10456. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  10457. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  10458. }
  10459. }
  10460. else
  10461. {
  10462. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10463. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  10464. }
  10465. if(json_object_object_get(data, "idlePrice") != NULL)
  10466. {
  10467. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  10468. {
  10469. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  10470. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  10471. }
  10472. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  10473. {
  10474. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  10475. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  10476. }
  10477. }
  10478. if(json_object_object_get(data, "nextPeriod") != NULL)
  10479. {
  10480. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  10481. {
  10482. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  10483. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  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("atTime not found."));
  10489. }
  10490. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  10491. {
  10492. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  10493. {
  10494. 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")));
  10495. 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"));
  10496. }
  10497. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  10498. {
  10499. 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")));
  10500. 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"));
  10501. }
  10502. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  10503. {
  10504. 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")));
  10505. 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"));
  10506. }
  10507. }
  10508. else
  10509. {
  10510. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10511. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  10512. }
  10513. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  10514. {
  10515. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  10516. {
  10517. 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")));
  10518. 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"));
  10519. }
  10520. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  10521. {
  10522. 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")));
  10523. 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"));
  10524. }
  10525. }
  10526. }
  10527. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  10528. {
  10529. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  10530. {
  10531. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10532. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10533. }
  10534. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  10535. {
  10536. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  10537. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  10538. }
  10539. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  10540. {
  10541. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  10542. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  10543. }
  10544. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  10545. {
  10546. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10547. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10548. }
  10549. }
  10550. }
  10551. }
  10552. }
  10553. else
  10554. {
  10555. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10556. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10557. }
  10558. }
  10559. else
  10560. {
  10561. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10562. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10563. }
  10564. json_object_put(data);
  10565. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10566. json_object_put(response);
  10567. }
  10568. else if(strstr(tempmessageId, "FinalCost") != NULL)
  10569. {
  10570. json_object *data;
  10571. data = json_tokener_parse(tempdata);
  10572. if(!is_error(data))
  10573. {
  10574. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10575. if(json_object_object_get(data, "txId") != NULL)
  10576. {
  10577. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  10578. for(int idx = 0;idx<gunTotalNumber;idx++)
  10579. {
  10580. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10581. {
  10582. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10583. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  10584. if(json_object_object_get(data, "description") != NULL)
  10585. {
  10586. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  10587. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  10588. }
  10589. else
  10590. {
  10591. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10592. json_object_object_add(response, "data", json_object_new_string("description not found."));
  10593. }
  10594. }
  10595. }
  10596. }
  10597. else if(json_object_object_get(data, "transactionId") != NULL)
  10598. {
  10599. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  10600. for(int idx = 0;idx<gunTotalNumber;idx++)
  10601. {
  10602. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  10603. {
  10604. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10605. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10606. if(json_object_object_get(data, "cost") != NULL)
  10607. {
  10608. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  10609. ShmOCPP16Data->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10610. }
  10611. else
  10612. {
  10613. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10614. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10615. }
  10616. if(json_object_object_get(data, "priceText") != NULL)
  10617. {
  10618. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10619. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10620. }
  10621. else
  10622. {
  10623. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10624. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  10625. }
  10626. if(json_object_object_get(data, "qrCodeText") != NULL)
  10627. {
  10628. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10629. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10630. }
  10631. }
  10632. }
  10633. }
  10634. else
  10635. {
  10636. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10637. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10638. }
  10639. }
  10640. else
  10641. {
  10642. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10643. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10644. }
  10645. json_object_put(data);
  10646. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10647. json_object_put(response);
  10648. }
  10649. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  10650. {
  10651. json_object *data;
  10652. data = json_tokener_parse(tempdata);
  10653. if(!is_error(data))
  10654. {
  10655. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10656. if(json_object_object_get(data, "Content_Type") != NULL)
  10657. {
  10658. 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))
  10659. {
  10660. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10661. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10662. {
  10663. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10664. }
  10665. }
  10666. else
  10667. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10668. }
  10669. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10670. }
  10671. else
  10672. {
  10673. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10674. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10675. }
  10676. json_object_put(data);
  10677. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10678. json_object_put(response);
  10679. }
  10680. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  10681. {
  10682. json_object *data;
  10683. data = json_tokener_parse(tempdata);
  10684. if(!is_error(data))
  10685. {
  10686. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10687. if(json_object_object_get(data, "ConnectorId") != NULL)
  10688. {
  10689. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  10690. }
  10691. if(json_object_object_get(data, "SerialNo") != NULL)
  10692. {
  10693. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  10694. }
  10695. if(json_object_object_get(data, "Page_Index") != NULL)
  10696. {
  10697. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10698. }
  10699. if(json_object_object_get(data, "Duration") != NULL)
  10700. {
  10701. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10702. }
  10703. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  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("Configuration content something wrong."));
  10709. }
  10710. json_object_put(data);
  10711. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10712. json_object_put(response);
  10713. }
  10714. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  10715. {
  10716. json_object *data;
  10717. data = json_tokener_parse(tempdata);
  10718. if(!is_error(data))
  10719. {
  10720. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10721. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10722. {
  10723. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10724. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10725. else
  10726. {
  10727. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10728. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10729. }
  10730. }
  10731. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10732. {
  10733. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10734. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10735. else
  10736. {
  10737. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10738. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10739. }
  10740. }
  10741. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  10742. {
  10743. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  10744. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  10745. else
  10746. {
  10747. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10748. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10749. }
  10750. }
  10751. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  10752. {
  10753. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  10754. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  10755. else
  10756. {
  10757. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10758. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10759. }
  10760. }
  10761. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10762. {
  10763. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10764. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10765. else
  10766. {
  10767. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10768. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10769. }
  10770. }
  10771. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10772. {
  10773. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10774. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10775. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10776. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10777. else
  10778. {
  10779. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10780. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10781. }
  10782. }
  10783. if(json_object_object_get(data, "isAuthentication") != NULL)
  10784. {
  10785. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10786. {
  10787. case 0:
  10788. case 1:
  10789. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10790. break;
  10791. default:
  10792. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10793. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10794. break;
  10795. }
  10796. }
  10797. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10798. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10799. }
  10800. else
  10801. {
  10802. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10803. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10804. }
  10805. json_object_put(data);
  10806. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10807. json_object_put(response);
  10808. }
  10809. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10810. {
  10811. json_object *data;
  10812. data = json_tokener_parse(tempdata);
  10813. if(!is_error(data))
  10814. {
  10815. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10816. {
  10817. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10818. {
  10819. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10820. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10821. }
  10822. else
  10823. {
  10824. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10825. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10826. }
  10827. }
  10828. else
  10829. {
  10830. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10831. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10832. }
  10833. }
  10834. else
  10835. {
  10836. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10837. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10838. }
  10839. json_object_put(data);
  10840. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10841. json_object_put(response);
  10842. }
  10843. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10844. {
  10845. json_object *data;
  10846. data = json_tokener_parse(tempdata);
  10847. if(!is_error(data))
  10848. {
  10849. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10850. if(json_object_object_get(data, "stationName") != NULL)
  10851. {
  10852. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10853. }
  10854. else
  10855. {
  10856. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10857. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10858. }
  10859. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10860. {
  10861. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10862. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10863. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10864. }
  10865. }
  10866. else
  10867. {
  10868. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10869. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10870. }
  10871. json_object_put(data);
  10872. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10873. json_object_put(response);
  10874. }
  10875. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10876. {
  10877. json_object *data;
  10878. data = json_tokener_parse(tempdata);
  10879. if(!is_error(data))
  10880. {
  10881. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10882. if(json_object_object_get(data, "weatherId") != NULL)
  10883. {
  10884. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10885. }
  10886. else
  10887. {
  10888. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10889. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10890. }
  10891. if(json_object_object_get(data, "Temperature") != NULL)
  10892. {
  10893. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10894. }
  10895. else
  10896. {
  10897. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10898. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10899. }
  10900. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10901. {
  10902. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10903. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10904. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10905. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10906. );
  10907. }
  10908. }
  10909. else
  10910. {
  10911. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10912. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10913. }
  10914. json_object_put(data);
  10915. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10916. json_object_put(response);
  10917. }
  10918. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10919. {
  10920. json_object *data;
  10921. data = json_tokener_parse(tempdata);
  10922. if(!is_error(data))
  10923. {
  10924. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10925. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10926. {
  10927. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10928. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10929. }
  10930. else
  10931. {
  10932. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10933. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10934. }
  10935. }
  10936. else
  10937. {
  10938. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10939. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10940. }
  10941. json_object_put(data);
  10942. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10943. json_object_put(response);
  10944. }
  10945. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10946. {
  10947. json_object *data;
  10948. data = json_tokener_parse(tempdata);
  10949. if(!is_error(data))
  10950. {
  10951. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10952. {
  10953. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10954. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10955. if(gun_index < gunTotalNumber)
  10956. {
  10957. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10958. {
  10959. json_object *responsedata = json_object_new_object();
  10960. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10961. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10962. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10963. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10964. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10965. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10966. }
  10967. else
  10968. {
  10969. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10970. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10971. }
  10972. }
  10973. else
  10974. {
  10975. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10976. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10977. }
  10978. }
  10979. else
  10980. {
  10981. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10982. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10983. }
  10984. }
  10985. else
  10986. {
  10987. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10988. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10989. }
  10990. json_object_put(data);
  10991. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10992. json_object_put(response);
  10993. }
  10994. else if(strstr(tempmessageId, "ID_OccupancyFeeDisplay") != NULL)
  10995. {
  10996. json_object *data;
  10997. data = json_tokener_parse(tempdata);
  10998. if(!is_error(data))
  10999. {
  11000. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  11001. int gun_index = 0;
  11002. if(json_object_object_get(data, "ConnectorId") != NULL)
  11003. {
  11004. gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  11005. if(json_object_object_get(data, "occupancySN") != NULL)
  11006. {
  11007. sprintf((char *)ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].occupancySN, "%s", json_object_get_string(json_object_object_get(data,"occupancySN")));
  11008. }
  11009. else
  11010. {
  11011. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  11012. json_object_object_add(response, "data", json_object_new_string("occupancySN data can not get."));
  11013. }
  11014. if(json_object_object_get(data, "actionId") != NULL)
  11015. {
  11016. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].actionId = json_object_get_int(json_object_object_get(data,"actionId"));
  11017. }
  11018. else
  11019. {
  11020. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  11021. json_object_object_add(response, "data", json_object_new_string("actionId data can not get."));
  11022. }
  11023. }
  11024. else
  11025. {
  11026. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  11027. json_object_object_add(response, "data", json_object_new_string("ConnectorId data can not get."));
  11028. }
  11029. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  11030. {
  11031. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].OccupancyFeeDisplayReq = 1;
  11032. }
  11033. }
  11034. else
  11035. {
  11036. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  11037. json_object_object_add(response, "data", json_object_new_string("OccupancyFeeDisplay content got something wrong."));
  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, "ID_SetOccupancyPrice") != NULL)
  11044. {
  11045. json_object *data;
  11046. data = json_tokener_parse(tempdata);
  11047. if(!is_error(data))
  11048. {
  11049. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  11050. if(json_object_object_get(data, "price") != NULL)
  11051. {
  11052. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.price = json_object_get_double(json_object_object_get(data,"price"));
  11053. }
  11054. else
  11055. {
  11056. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  11057. json_object_object_add(response, "data", json_object_new_string("price data can not get."));
  11058. }
  11059. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  11060. {
  11061. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.SetOccupancyPriceReq = 1;
  11062. }
  11063. }
  11064. else
  11065. {
  11066. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  11067. json_object_object_add(response, "data", json_object_new_string("SetOccupancyPrice content got something wrong."));
  11068. }
  11069. json_object_put(data);
  11070. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  11071. json_object_put(response);
  11072. }
  11073. // Support ISO-15118 related message
  11074. else if(strstr(tempmessageId, "TriggerMessage") != NULL)
  11075. {
  11076. char cmdBuf[1024]={0};
  11077. 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);
  11078. system(cmdBuf);
  11079. ShmOCPP16Data->v2g_extend.SignCertificateReq = 1;
  11080. json_object *responsedata = json_object_new_object();
  11081. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  11082. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11083. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  11084. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  11085. json_object_put(response);
  11086. }
  11087. else if(strstr(tempmessageId, "CertificateSigned") != NULL)
  11088. {
  11089. json_object *data;
  11090. data = json_tokener_parse(tempdata);
  11091. if(!is_error(data))
  11092. {
  11093. FILE *fp = fopen(CERTIFICATE_V2G, "w");
  11094. fprintf(fp, "%s", json_object_get_string(json_object_object_get(data, "certificateChain")));
  11095. fclose(fp);
  11096. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11097. json_object *responsedata = json_object_new_object();
  11098. if(certVerify(PRIVATE_KEY_V2G, CERTIFICATE_V2G) == PASS)
  11099. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  11100. else
  11101. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  11102. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11103. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  11104. }
  11105. else
  11106. {
  11107. json_object *responsedata = json_object_new_object();
  11108. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  11109. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11110. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  11111. }
  11112. json_object_put(data);
  11113. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  11114. json_object_put(response);
  11115. }
  11116. else if(strstr(tempmessageId, "DeleteCertificate") != NULL)
  11117. {
  11118. json_object *data;
  11119. data = json_tokener_parse(tempdata);
  11120. DEBUG_INFO("DeleteCertificate processing...\n");
  11121. if(!is_error(data))
  11122. {
  11123. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm") != NULL)
  11124. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm")));
  11125. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash") != NULL)
  11126. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash")));
  11127. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash") != NULL)
  11128. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash")));
  11129. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber") != NULL)
  11130. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber")));
  11131. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm);
  11132. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash);
  11133. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash);
  11134. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber);
  11135. char temp[256] = {0};
  11136. char compareData[256] = {0};
  11137. int isMatch = TRUE;
  11138. // Check certV2G
  11139. if(access(CERTIFICATE_V2G,F_OK) != -1)
  11140. {
  11141. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_SerialNumber, compareData);
  11142. if(strcmp(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber) != 0)
  11143. isMatch = FALSE;
  11144. if(isMatch == TRUE)
  11145. {
  11146. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerNameHash, compareData);
  11147. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  11148. isMatch = FALSE;
  11149. }
  11150. if(isMatch == TRUE)
  11151. {
  11152. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerKeyHash, compareData);
  11153. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  11154. isMatch = FALSE;
  11155. }
  11156. if(isMatch == TRUE)
  11157. {
  11158. sprintf(temp, "rm -f %s", CERTIFICATE_V2G);
  11159. system(temp);
  11160. json_object *responsedata = json_object_new_object();
  11161. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  11162. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11163. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  11164. }
  11165. else
  11166. {
  11167. json_object *responsedata = json_object_new_object();
  11168. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  11169. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11170. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  11171. }
  11172. }
  11173. else
  11174. {
  11175. json_object *responsedata = json_object_new_object();
  11176. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  11177. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11178. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  11179. }
  11180. }
  11181. else
  11182. {
  11183. json_object *responsedata = json_object_new_object();
  11184. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  11185. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11186. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  11187. }
  11188. json_object_put(data);
  11189. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  11190. json_object_put(response);
  11191. }
  11192. else if(strstr(tempmessageId, "GetInstalledCertificateIds") != NULL)
  11193. {
  11194. json_object *data;
  11195. data = json_tokener_parse(tempdata);
  11196. if(!is_error(data))
  11197. {
  11198. /*
  11199. * TODO:
  11200. * 1. Query certificate to response
  11201. */
  11202. json_object *responsedata = json_object_new_object();
  11203. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  11204. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11205. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  11206. }
  11207. else
  11208. {
  11209. json_object *responsedata = json_object_new_object();
  11210. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  11211. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11212. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  11213. }
  11214. json_object_put(data);
  11215. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  11216. json_object_put(response);
  11217. }
  11218. else if(strstr(tempmessageId, "InstallCertificate") != NULL)
  11219. {
  11220. json_object *data;
  11221. data = json_tokener_parse(tempdata);
  11222. if(!is_error(data))
  11223. {
  11224. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  11225. if(json_object_object_get(data, "certificateType") != NULL)
  11226. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(data, "certificateType")));
  11227. if(json_object_object_get(data, "certificate") != NULL)
  11228. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(data, "certificate")));
  11229. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType);
  11230. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  11231. char temp[1024];
  11232. FILE *fp = fopen(tempCert, "w");
  11233. fprintf(fp, "%s", ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  11234. fclose(fp);
  11235. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  11236. char strExpDate[30];
  11237. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  11238. fp = popen(temp, "r");
  11239. if(fp)
  11240. {
  11241. while(fgets(temp, sizeof(temp), fp) != NULL)
  11242. {
  11243. if(strstr(temp, "notAfter=") != NULL)
  11244. {
  11245. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  11246. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  11247. break;
  11248. }
  11249. }
  11250. }
  11251. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  11252. struct tm tmExpDate;
  11253. struct timeb tbExpDate;
  11254. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  11255. tbExpDate.time = mktime(&tmExpDate);
  11256. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  11257. {
  11258. DEBUG_INFO("The enddate is already expired...\n");
  11259. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Rejected");
  11260. }
  11261. else
  11262. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted");
  11263. if(strcmp((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted") == 0)
  11264. {
  11265. if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "V2GRootCertificate") != NULL)
  11266. {
  11267. if(access(ROOTCA_V2G,F_OK) != -1)
  11268. {
  11269. DEBUG_INFO("Existed V2GRootCertificate is found. Replacing...\n");
  11270. rename(ROOTCA_V2G, "/Storage/OCPP/rootCaV2g_fallback.pem");
  11271. rename(tempCert, ROOTCA_V2G);
  11272. }
  11273. else
  11274. {
  11275. DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
  11276. rename(tempCert, ROOTCA_V2G);
  11277. }
  11278. json_object *responsedata = json_object_new_object();
  11279. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  11280. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11281. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  11282. }
  11283. else if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "MORootCertificate") != NULL)
  11284. {
  11285. if(access(ROOTCA_MO,F_OK) != -1)
  11286. {
  11287. DEBUG_INFO("Existed MORootCertificate is found. Replacing...\n");
  11288. rename(ROOTCA_MO, "/Storage/OCPP/rootCaMo_fallback.pem");
  11289. rename(tempCert, ROOTCA_MO);
  11290. }
  11291. else
  11292. {
  11293. DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
  11294. rename(tempCert, ROOTCA_MO);
  11295. }
  11296. json_object *responsedata = json_object_new_object();
  11297. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  11298. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11299. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  11300. }
  11301. else
  11302. {
  11303. json_object *responsedata = json_object_new_object();
  11304. json_object_object_add(responsedata, "status", json_object_new_string("Failed"));
  11305. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11306. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  11307. }
  11308. }
  11309. else
  11310. {
  11311. json_object *responsedata = json_object_new_object();
  11312. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  11313. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11314. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  11315. }
  11316. }
  11317. else
  11318. {
  11319. json_object *responsedata = json_object_new_object();
  11320. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  11321. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  11322. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  11323. }
  11324. json_object_put(data);
  11325. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  11326. json_object_put(response);
  11327. }
  11328. else
  11329. {
  11330. // Can not find valid message id
  11331. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  11332. }
  11333. }
  11334. else
  11335. {
  11336. // Payload is null
  11337. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  11338. }
  11339. LWS_Send(message);
  11340. return result;
  11341. }
  11342. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  11343. {
  11344. mtrace();
  11345. int result = FAIL;
  11346. int connectorIdInt, durationInt;
  11347. char chargingRateUnitStr[4]={0};
  11348. char comfirmstr[20];
  11349. int confirmPeriods = 0;
  11350. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  11351. json_object *GetCompositeSchedule;
  11352. GetCompositeSchedule = json_tokener_parse(payload);
  11353. if(!is_error(GetCompositeSchedule))
  11354. {
  11355. // Required data
  11356. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  11357. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  11358. else
  11359. connectorIdInt = -1;
  11360. if(json_object_object_get(GetCompositeSchedule, "duration"))
  11361. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  11362. else
  11363. durationInt = 86400;
  11364. // Optional data
  11365. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  11366. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  11367. }
  11368. json_object_put(GetCompositeSchedule);
  11369. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  11370. if((connectorIdInt == 0) ||
  11371. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  11372. {
  11373. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  11374. struct StructChargingProfile tmpProfile[1];
  11375. if(strstr(chargingRateUnitStr, "W") != NULL)
  11376. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  11377. else
  11378. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  11379. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  11380. {
  11381. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  11382. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  11383. }
  11384. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  11385. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  11386. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  11387. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  11388. {
  11389. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  11390. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  11391. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  11392. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  11393. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  11394. {
  11395. confirmPeriods = idx;
  11396. break;
  11397. }
  11398. }
  11399. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  11400. {
  11401. confirmPeriods += 1;
  11402. }
  11403. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  11404. }
  11405. else
  11406. {
  11407. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  11408. }
  11409. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  11410. return result;
  11411. }
  11412. int handleGetConfigurationRequest(char *uuid, char *payload)
  11413. {
  11414. mtrace();
  11415. int result = FAIL;
  11416. int MaxKeySupported = 0;
  11417. int n_keys = 0;
  11418. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  11419. DEBUG_INFO("handleGetConfigurationRequest...\n");
  11420. json_object *GetConfiguration;
  11421. GetConfiguration = json_tokener_parse(payload);
  11422. if(!is_error(GetConfiguration))
  11423. {
  11424. // Optional data
  11425. if(json_object_object_get(GetConfiguration, "key") != NULL)
  11426. {
  11427. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  11428. {
  11429. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  11430. n_keys = idx + 1;
  11431. }
  11432. }
  11433. }
  11434. json_object_put(GetConfiguration);
  11435. UnknownKeynum = 0;
  11436. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  11437. MaxKeySupported = GetConfigurationMaxKeysNUM;
  11438. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  11439. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  11440. if(n_keys != 0)
  11441. {
  11442. for(int i=0;i<n_keys;i++)
  11443. {
  11444. getKeyValue(requestKey[i]);
  11445. }
  11446. }
  11447. else
  11448. {
  11449. DEBUG_INFO("There is no key in Message, get all configuration\n");
  11450. getKeyValue("");
  11451. }
  11452. processUnkownKey();
  11453. sendGetConfigurationConfirmation(uuid);
  11454. return result;
  11455. }
  11456. static char fnamePlusPath[100]={0};
  11457. static char fnamePWithNoPath[60]={0};
  11458. void checkUploadLog(void)
  11459. {
  11460. FILE *fp;
  11461. /* Open the command for reading. */
  11462. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  11463. if (fp == NULL) {
  11464. DEBUG_WARN("Failed to run command\n" );
  11465. exit(1);
  11466. }
  11467. int ftppathlen = 0;
  11468. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  11469. int i = 0;
  11470. /* Read the output a line at a time - output it. */
  11471. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  11472. if(i==0)
  11473. {
  11474. ftppathlen = strlen(fnamePlusPath);
  11475. DEBUG_INFO("%s\n", fnamePlusPath);
  11476. fnamePlusPath[ftppathlen]='\0';
  11477. break;
  11478. }
  11479. i= i+1;
  11480. }
  11481. /* close */
  11482. pclose(fp);
  11483. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  11484. {
  11485. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  11486. {
  11487. fnamePlusPath[k]='\0';
  11488. }
  11489. }
  11490. i=1;
  11491. //char fname[60]={0};
  11492. while(i < ftppathlen)
  11493. {
  11494. int len=ftppathlen-i;
  11495. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  11496. {
  11497. DEBUG_INFO("compare '/' all right\n");
  11498. break;
  11499. }
  11500. i=i+1;
  11501. }
  11502. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  11503. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  11504. fnamePWithNoPath[i+1] = '\0';
  11505. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  11506. {
  11507. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  11508. {
  11509. fnamePWithNoPath[j]='\0';
  11510. }
  11511. }
  11512. FILE* fp1 = fopen(fnamePlusPath, "r");
  11513. if (fp1)
  11514. {
  11515. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  11516. // file exists
  11517. fclose(fp1);
  11518. }
  11519. else
  11520. {
  11521. // file doesn't exist
  11522. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  11523. }
  11524. }
  11525. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  11526. {
  11527. mtrace();
  11528. int result = FAIL;
  11529. time_t CurrentTime;
  11530. struct tm *tm;
  11531. pthread_t th_Status;
  11532. CurrentTime = time(NULL);
  11533. tm = localtime(&CurrentTime);
  11534. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  11535. 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);
  11536. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11537. if(!interLock.isGetDiagnosticGoing)
  11538. {
  11539. interLock.isGetDiagnosticGoing = 1;
  11540. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, payload);
  11541. sleep(1);
  11542. }
  11543. else
  11544. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  11545. return result;
  11546. }
  11547. void* GetDiagnosticsProcess(void* data)
  11548. {
  11549. pthread_detach(pthread_self());
  11550. mtrace();
  11551. int retriesInt=0, retryIntervalInt=0;
  11552. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  11553. 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};
  11554. int port=0;
  11555. int isSuccess = FALSE;
  11556. char cmdBuf[2048];
  11557. struct tm *tmNow;
  11558. time_t CurrentTime;
  11559. struct tm tmStart;
  11560. struct tm tmStop;
  11561. CurrentTime = time(NULL);
  11562. tmNow=localtime(&CurrentTime);
  11563. uint16_t targetYear, targetMonth;
  11564. json_object *GetDiagnostics;
  11565. DEBUG_INFO("GetDiagnosticsProcess...\n");
  11566. GetDiagnostics = json_tokener_parse(data);
  11567. if(!is_error(GetDiagnostics))
  11568. {
  11569. // Required data
  11570. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  11571. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  11572. // Optional data
  11573. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  11574. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  11575. else
  11576. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  11577. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  11578. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  11579. else
  11580. retryIntervalInt = 30;
  11581. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  11582. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  11583. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  11584. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  11585. }
  11586. json_object_put(GetDiagnostics);
  11587. // Pack log to compress file
  11588. 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) &&
  11589. (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))
  11590. {
  11591. // Pack system log
  11592. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11593. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  11594. targetYear = tmStart.tm_year;
  11595. targetMonth = tmStart.tm_mon;
  11596. do
  11597. {
  11598. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11599. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  11600. if(targetMonth+1>=13)
  11601. {
  11602. targetYear += 1;
  11603. targetMonth = 1;
  11604. }
  11605. else
  11606. {
  11607. targetMonth += 1;
  11608. }
  11609. }while((targetYear < (tmNow->tm_year+1900)) ||
  11610. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11611. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  11612. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  11613. system(cmdBuf);
  11614. // Pack charging & event log
  11615. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11616. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  11617. targetYear = tmStart.tm_year;
  11618. targetMonth = tmStart.tm_mon;
  11619. do
  11620. {
  11621. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11622. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  11623. if(targetMonth+1>=13)
  11624. {
  11625. targetYear += 1;
  11626. targetMonth = 1;
  11627. }
  11628. else
  11629. {
  11630. targetMonth += 1;
  11631. }
  11632. }while((targetYear < (tmNow->tm_year+1900)) ||
  11633. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11634. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  11635. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  11636. system(cmdBuf);
  11637. // Combine log file
  11638. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  11639. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  11640. }
  11641. else
  11642. {
  11643. system("exec /root/logPackTools 'log' 6");
  11644. }
  11645. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11646. system(cmdBuf);
  11647. checkUploadLog();
  11648. //****************location*******************/
  11649. if(strcmp(locationstr,"")==0)
  11650. {
  11651. DEBUG_INFO("location is <Empty>!\n");
  11652. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11653. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11654. goto end;
  11655. }
  11656. memset(protocol, 0, ARRAY_SIZE(protocol));
  11657. memset(user, 0, ARRAY_SIZE(user) );
  11658. memset(password, 0, ARRAY_SIZE(password));
  11659. memset(host, 0, ARRAY_SIZE(host));
  11660. memset(path, 0, ARRAY_SIZE(path));
  11661. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11662. memset(host1, 0, ARRAY_SIZE(host1));
  11663. memset(path1, 0, ARRAY_SIZE(path1));
  11664. /*location: ftp://user:password@host:port/path*/
  11665. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  11666. if((access(fnamePlusPath,F_OK))!=-1)
  11667. {
  11668. DEBUG_INFO("fnamePlusPath exist.\n");
  11669. }
  11670. else
  11671. {
  11672. DEBUG_INFO("fnamePlusPath not exist!\n");
  11673. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11674. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11675. goto end;
  11676. }
  11677. if(strchr(locationstr,'@')==NULL)
  11678. {
  11679. sscanf(locationstr,
  11680. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11681. protocol, host, &port, path);
  11682. strcpy(user,"anonymous");
  11683. strcpy(password,"");
  11684. }
  11685. else
  11686. {
  11687. //DEBUG_INFO("pch=%s\n", pch);
  11688. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11689. protocol, user, password, host, &port, path);
  11690. }
  11691. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  11692. {
  11693. DEBUG_INFO("protocol is not ftp/http ! \n");
  11694. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11695. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11696. goto end;
  11697. }
  11698. if(strncmp(locationstr,"http", 4) == 0)
  11699. {
  11700. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11701. sprintf(ftppath,"/%s", path);
  11702. do
  11703. {
  11704. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11705. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11706. sleep(3);
  11707. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  11708. if(!isSuccess)
  11709. {
  11710. DEBUG_INFO("Diagnostics fail.\n");
  11711. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11712. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11713. sleep(retryIntervalInt);
  11714. }
  11715. else
  11716. {
  11717. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11718. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11719. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11720. }
  11721. retriesInt--;
  11722. }while((isSuccess == 0)&&(retriesInt >= 0));
  11723. }
  11724. else
  11725. {
  11726. sscanf(host,"%[^/]%s",host1, path1);
  11727. if(strlen(path) > 0)
  11728. sprintf(ftppath,"/%s", path);
  11729. else
  11730. sprintf(ftppath,"/%s", path1);
  11731. int ftppathlen=strlen(ftppath);
  11732. int i=1;
  11733. char filenametemp[50];
  11734. while(i < ftppathlen)
  11735. {
  11736. int len=ftppathlen-i;
  11737. if(ftppath[len]== 47) // '/' ascll code: 47
  11738. {
  11739. DEBUG_INFO("find '/' all right\n");
  11740. break;
  11741. }
  11742. i=i+1;
  11743. }
  11744. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11745. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11746. filenametemp[i+1] = 0;
  11747. if(port == 0)
  11748. port = 21;
  11749. do
  11750. {
  11751. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11752. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11753. sleep(3);
  11754. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  11755. if(!isSuccess)
  11756. {
  11757. DEBUG_INFO("Diagnostics fail.\n");
  11758. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11759. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11760. sleep(retryIntervalInt);
  11761. }
  11762. else
  11763. {
  11764. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11765. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11766. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11767. }
  11768. retriesInt--;
  11769. }while((!isSuccess)&&(retriesInt >= 0));
  11770. }
  11771. end:
  11772. system("rm -f /mnt/*");
  11773. sleep(5);
  11774. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11775. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11776. interLock.isGetDiagnosticGoing = 0;
  11777. pthread_exit(NULL);
  11778. }
  11779. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  11780. {
  11781. mtrace();
  11782. int result = FAIL;
  11783. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  11784. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  11785. {
  11786. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  11787. locallistVersion = -1;
  11788. }
  11789. else
  11790. {
  11791. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  11792. locallistVersion = 0;
  11793. OCPP_getListVerion();
  11794. }
  11795. //from db.OCPP_getListVerion
  11796. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  11797. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  11798. sendGetLocalListVersionConfirmation(uuid,"");
  11799. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  11800. return result;
  11801. }
  11802. int handleRemoteStartRequest(char *uuid, char *payload)
  11803. {
  11804. mtrace();
  11805. int result = PASS;
  11806. int connectorIdInt=-1;
  11807. int tempIndex = 0;
  11808. char comfirmstr[20]={0};
  11809. char cmdBuf[512];
  11810. json_object *RemoteStartTransaction;
  11811. FILE *fp;
  11812. DEBUG_INFO("handleRemoteStartRequest ...\n");
  11813. if(server_pending == TRUE)
  11814. {
  11815. result = FAIL;
  11816. }
  11817. RemoteStartTransaction = json_tokener_parse(payload);
  11818. if(!is_error(RemoteStartTransaction))
  11819. {
  11820. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  11821. {
  11822. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  11823. }
  11824. else
  11825. {
  11826. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11827. {
  11828. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  11829. {
  11830. connectorIdInt = (gun_index+1);
  11831. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  11832. break;
  11833. }
  11834. }
  11835. }
  11836. if(connectorIdInt == 0)
  11837. {
  11838. DEBUG_WARN("Connector id shall not equal 0.\n");
  11839. result = FAIL;
  11840. }
  11841. else if(json_object_object_get(RemoteStartTransaction, "idTag") == NULL)
  11842. {
  11843. DEBUG_WARN("idTag should not be NULL.\n");
  11844. result = FAIL;
  11845. }
  11846. else if(connectorIdInt == -1)
  11847. {
  11848. DEBUG_INFO("Connector id does not specific.\n");
  11849. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11850. {
  11851. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11852. // Required data
  11853. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11854. // Optional data
  11855. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11856. {
  11857. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11858. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11859. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11860. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11861. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11862. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11863. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11864. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11865. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11866. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11867. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11868. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11869. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11870. {
  11871. 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")));
  11872. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11873. 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"));
  11874. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11875. 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"));
  11876. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11877. 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")));
  11878. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11879. {
  11880. 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++)
  11881. {
  11882. 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"));
  11883. 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"));
  11884. 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)
  11885. 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"));
  11886. }
  11887. }
  11888. }
  11889. }
  11890. else
  11891. {
  11892. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11893. }
  11894. }
  11895. }
  11896. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11897. {
  11898. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11899. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11900. // Required data
  11901. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11902. // Optional data
  11903. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11904. {
  11905. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11906. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11907. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11908. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11909. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11910. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11911. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11912. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11913. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11914. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11915. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11916. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11917. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11918. {
  11919. 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")));
  11920. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11921. 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"));
  11922. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11923. 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"));
  11924. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11925. 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")));
  11926. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11927. {
  11928. 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++)
  11929. {
  11930. 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"));
  11931. 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"));
  11932. 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)
  11933. 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"));
  11934. }
  11935. }
  11936. }
  11937. }
  11938. else
  11939. {
  11940. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11941. }
  11942. }
  11943. else
  11944. {
  11945. DEBUG_WARN("Connector id is over maximun value.\n");
  11946. result = FAIL;
  11947. }
  11948. }
  11949. if(result == PASS)
  11950. {
  11951. if(connectorIdInt > 0)
  11952. {
  11953. //check Transaction active
  11954. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11955. {
  11956. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11957. {
  11958. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11959. }
  11960. else
  11961. {
  11962. tempIndex = connectorIdInt -1;
  11963. }
  11964. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11965. {
  11966. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11967. {
  11968. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11969. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11970. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11971. {
  11972. //Reserved
  11973. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11974. }
  11975. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11976. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11977. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11978. {
  11979. //Reserved
  11980. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11981. {
  11982. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11983. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11984. goto end;
  11985. }
  11986. }
  11987. else
  11988. {
  11989. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11990. {
  11991. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11992. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11993. goto end;
  11994. }
  11995. }//END FOR ELSE
  11996. }
  11997. }// END FOR CHAdeMO_QUANTITY
  11998. }
  11999. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  12000. {
  12001. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12002. {
  12003. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  12004. }
  12005. else
  12006. {
  12007. tempIndex = connectorIdInt -1;
  12008. }
  12009. for (int index = 0; index < CCS_QUANTITY; index++)
  12010. {
  12011. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12012. {
  12013. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  12014. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  12015. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  12016. {
  12017. //Reserved
  12018. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  12019. }
  12020. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  12021. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  12022. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  12023. {
  12024. //Reserved
  12025. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  12026. {
  12027. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  12028. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12029. goto end;
  12030. }
  12031. }
  12032. else
  12033. {
  12034. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  12035. {
  12036. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  12037. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12038. goto end;
  12039. }
  12040. }// END FOR ELSE
  12041. }
  12042. }// END FOR CCS_QUANTITY
  12043. }
  12044. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  12045. {
  12046. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12047. {
  12048. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  12049. }
  12050. else
  12051. {
  12052. tempIndex = connectorIdInt -1;
  12053. }
  12054. for (int index = 0; index < GB_QUANTITY; index++)
  12055. {
  12056. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  12057. {
  12058. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  12059. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  12060. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  12061. {
  12062. //Reserved
  12063. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  12064. }
  12065. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  12066. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  12067. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  12068. {
  12069. //Reserved
  12070. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  12071. {
  12072. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  12073. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12074. goto end;
  12075. }
  12076. }
  12077. else
  12078. {
  12079. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  12080. {
  12081. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  12082. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12083. goto end;
  12084. }
  12085. }// END FOR ELSE
  12086. }
  12087. } // END FOR GB_QUANTITY
  12088. }
  12089. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  12090. {
  12091. tempIndex = connectorIdInt -1;
  12092. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12093. {
  12094. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  12095. {
  12096. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  12097. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  12098. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  12099. {
  12100. //Reserved
  12101. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  12102. }
  12103. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  12104. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  12105. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  12106. {
  12107. //Reserved
  12108. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  12109. {
  12110. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  12111. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12112. goto end;
  12113. }
  12114. }
  12115. else
  12116. {
  12117. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  12118. {
  12119. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  12120. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12121. goto end;
  12122. }
  12123. }// END FOR ELSE
  12124. }
  12125. } // END FOR GB_QUANTITY
  12126. }
  12127. else
  12128. {
  12129. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12130. {
  12131. tempIndex = 2;
  12132. }
  12133. else
  12134. {
  12135. tempIndex = connectorIdInt -1;
  12136. }
  12137. for (int index = 0; index < AC_QUANTITY; index++)
  12138. {
  12139. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  12140. {
  12141. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  12142. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  12143. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  12144. {
  12145. //Reserved
  12146. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  12147. }
  12148. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  12149. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  12150. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  12151. {
  12152. //Reserved
  12153. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  12154. {
  12155. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  12156. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12157. goto end;
  12158. }
  12159. }
  12160. else
  12161. {
  12162. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  12163. {
  12164. DEBUG_WARN("AC connector not allow start cause busy.\n");
  12165. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12166. goto end;
  12167. }
  12168. }//END FOR ELSE
  12169. }
  12170. }// END FOR AC_QUANTITY
  12171. }
  12172. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  12173. {
  12174. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12175. {
  12176. // Save profile to file
  12177. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  12178. system(cmdBuf);
  12179. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  12180. fp = fopen(cmdBuf, "w");
  12181. 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));
  12182. fclose(fp);
  12183. }
  12184. else
  12185. {
  12186. DEBUG_WARN("Profile purpose not TxProfile.\n");
  12187. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12188. goto end;
  12189. }
  12190. }
  12191. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  12192. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  12193. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  12194. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  12195. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  12196. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  12197. }
  12198. else
  12199. {
  12200. uint8_t isHasIdleConnector = FALSE;
  12201. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  12202. {
  12203. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  12204. {
  12205. isHasIdleConnector = TRUE;
  12206. break;
  12207. }
  12208. }
  12209. if((isHasIdleConnector == TRUE) && !ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  12210. {
  12211. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12212. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  12213. {
  12214. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12215. {
  12216. // Save profile to file
  12217. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  12218. system(cmdBuf);
  12219. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  12220. fp = fopen(cmdBuf, "w");
  12221. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  12222. fclose(fp);
  12223. refreshStartTimer(&clientTime.RemoteStartWait);
  12224. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  12225. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  12226. }
  12227. else
  12228. {
  12229. DEBUG_WARN("Profile purpose not TxProfile.\n");
  12230. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12231. }
  12232. }
  12233. else
  12234. {
  12235. refreshStartTimer(&clientTime.RemoteStartWait);
  12236. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  12237. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  12238. }
  12239. }
  12240. else
  12241. {
  12242. DEBUG_INFO("There is not any connector is idle.\n");
  12243. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12244. }
  12245. }
  12246. }
  12247. else
  12248. {
  12249. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12250. }
  12251. end:
  12252. json_object_put(RemoteStartTransaction);
  12253. sendRemoteStartConfirmation(uuid, comfirmstr);
  12254. return result;
  12255. }
  12256. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  12257. {
  12258. mtrace();
  12259. int result = FAIL;
  12260. int match = FALSE;
  12261. int GunNO = 0;
  12262. int tempIndex = 0;
  12263. int transactionIdInt=0;
  12264. int transactionIdIsNULL= TRUE;
  12265. char comfirmstr[20];
  12266. json_object *RemoteStopTransaction;
  12267. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  12268. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  12269. if(server_pending == TRUE)
  12270. {
  12271. return 0;
  12272. }
  12273. RemoteStopTransaction = json_tokener_parse(payload);
  12274. if(!is_error(RemoteStopTransaction))
  12275. {
  12276. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  12277. {
  12278. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  12279. transactionIdIsNULL = FALSE;
  12280. }
  12281. }
  12282. json_object_put(RemoteStopTransaction);
  12283. if(transactionIdIsNULL == FALSE)
  12284. {
  12285. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  12286. {
  12287. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  12288. {
  12289. //check Transaction active
  12290. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  12291. {
  12292. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12293. {
  12294. tempIndex = ((gun_index==2) ? 1: 0);
  12295. }
  12296. else
  12297. {
  12298. tempIndex = gun_index;
  12299. }
  12300. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12301. {
  12302. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12303. {
  12304. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  12305. {
  12306. match = TRUE;
  12307. GunNO = gun_index;
  12308. }
  12309. }
  12310. }// END FOR CHAdeMO_QUANTITY
  12311. }
  12312. else if(gunType[gun_index] == GUN_TYPE_CCS)
  12313. {
  12314. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12315. {
  12316. tempIndex = ((gun_index==2) ? 1: 0);
  12317. }
  12318. else
  12319. {
  12320. tempIndex = gun_index;
  12321. }
  12322. for (int index = 0; index < CCS_QUANTITY; index++)
  12323. {
  12324. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12325. {
  12326. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  12327. {
  12328. match = TRUE;
  12329. GunNO = gun_index;
  12330. }
  12331. }
  12332. }// END FOR CCS_QUANTITY
  12333. }
  12334. else if(gunType[gun_index] == GUN_TYPE_GBT)
  12335. {
  12336. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12337. {
  12338. tempIndex = ((gun_index==2) ? 1: 0);
  12339. }
  12340. else
  12341. {
  12342. tempIndex = gun_index;
  12343. }
  12344. for (int index = 0; index < GB_QUANTITY; index++)
  12345. {
  12346. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12347. {
  12348. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  12349. {
  12350. match = TRUE;
  12351. GunNO = gun_index;
  12352. }
  12353. }
  12354. }// END FOR GB_QUANTITY
  12355. }
  12356. else if(gunType[gun_index] == GUN_TYPE_DO)
  12357. {
  12358. tempIndex = gun_index;
  12359. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12360. {
  12361. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12362. {
  12363. 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
  12364. {
  12365. match = TRUE;
  12366. GunNO = gun_index;
  12367. }
  12368. }
  12369. }// END FOR GB_QUANTITY
  12370. }
  12371. else
  12372. {
  12373. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12374. {
  12375. tempIndex = 2;
  12376. }
  12377. else
  12378. {
  12379. tempIndex = gun_index;
  12380. }
  12381. for (int index = 0; index < AC_QUANTITY; index++)
  12382. {
  12383. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12384. {
  12385. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  12386. {
  12387. match = TRUE;
  12388. GunNO = gun_index;
  12389. }
  12390. }
  12391. }// END FOR CHAdeMO_QUANTITY
  12392. } // END FOR AC ELSE
  12393. }// CHECK IF ResponseTransactionId == transactionIdInt
  12394. }//END FOR
  12395. if( match == TRUE)
  12396. {
  12397. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  12398. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  12399. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  12400. }
  12401. else
  12402. {
  12403. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12404. }
  12405. }
  12406. else
  12407. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12408. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  12409. return result;
  12410. }
  12411. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  12412. {
  12413. mtrace();
  12414. int result = FAIL;
  12415. int connectorIdInt=0, reservationIdInt=0;
  12416. int tempIndex = 0;
  12417. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  12418. char comfirmstr[20]={0};
  12419. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  12420. int c = 0;
  12421. char *loc;
  12422. //char *ptr;
  12423. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  12424. strcpy(sstrtemp, stringtrimspace(payload));
  12425. //***(1)connectorId ****/
  12426. c=0;
  12427. loc = strstr(sstrtemp, "connectorId");
  12428. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12429. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  12430. {
  12431. sstr[c] = loc[strlen("connectorId")+2+c];
  12432. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12433. c++;
  12434. }
  12435. sstr[c] = '\0';
  12436. connectorIdInt = atoi(sstr);
  12437. //***(2)expiryDate ****/
  12438. loc = strstr(sstrtemp, "expiryDate");
  12439. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12440. c = 0;
  12441. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  12442. {
  12443. sstr[c] = loc[3+strlen("expiryDate")+c];
  12444. c++;
  12445. }
  12446. sstr[c] = '\0';
  12447. strcpy(expiryDatestr, sstr);
  12448. //***(3)idTag ****/
  12449. loc = strstr(sstrtemp, "idTag");
  12450. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12451. c = 0;
  12452. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  12453. {
  12454. sstr[c] = loc[3+strlen("idTag")+c];
  12455. c++;
  12456. }
  12457. sstr[c] = '\0';
  12458. strcpy(idTagstr, sstr);
  12459. //***(4)parentIdTag ****/
  12460. loc = strstr(sstrtemp, "parentIdTag");
  12461. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12462. c = 0;
  12463. if(loc == NULL)
  12464. {
  12465. strcpy(parentIdTagstr, "");
  12466. }
  12467. else
  12468. {
  12469. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  12470. {
  12471. sstr[c] = loc[3+strlen("parentIdTag")+c];
  12472. c++;
  12473. }
  12474. sstr[c] = '\0';
  12475. strcpy(parentIdTagstr, sstr);
  12476. }
  12477. //***(5)reservationId ****/
  12478. c=0;
  12479. loc = strstr(sstrtemp, "reservationId");
  12480. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12481. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  12482. {
  12483. sstr[c] = loc[strlen("reservationId")+2+c];
  12484. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12485. c++;
  12486. }
  12487. sstr[c] = '\0';
  12488. reservationIdInt = atoi(sstr);
  12489. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12490. /*
  12491. enum SYSTEM_STATUS
  12492. {
  12493. SYS_MODE_BOOTING = 0,
  12494. SYS_MODE_IDLE = 1,
  12495. SYS_MODE_AUTHORIZING = 2,
  12496. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  12497. SYS_MODE_REASSIGN = 4,
  12498. SYS_MODE_PREPARING = 5,
  12499. SYS_MODE_PREPARE_FOR_EV = 6,
  12500. SYS_MODE_PREPARE_FOR_EVSE = 7,
  12501. SYS_MODE_CHARGING = 8,
  12502. SYS_MODE_TERMINATING = 9,
  12503. SYS_MODE_COMPLETE = 10,
  12504. SYS_MODE_ALARM = 11,
  12505. SYS_MODE_FAULT = 12,
  12506. SYS_MODE_RESERVATION = 13,
  12507. SYS_MODE_BOOKING = 14,
  12508. SYS_MODE_MAINTAIN = 15,
  12509. SYS_MODE_DEBUG = 16,
  12510. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  12511. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  12512. SYS_MODE_UPDATE = 19
  12513. };
  12514. */
  12515. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  12516. {
  12517. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12518. goto end;
  12519. }
  12520. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  12521. {
  12522. //check Transaction active
  12523. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  12524. {
  12525. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12526. {
  12527. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12528. }
  12529. else
  12530. {
  12531. tempIndex = connectorIdInt -1;
  12532. }
  12533. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12534. {
  12535. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12536. {
  12537. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12538. {
  12539. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12540. {
  12541. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12542. {
  12543. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  12544. {
  12545. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12546. }
  12547. else
  12548. {
  12549. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12550. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12551. }
  12552. }
  12553. 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'))
  12554. {
  12555. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12556. }
  12557. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12558. {
  12559. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12560. }
  12561. else
  12562. {
  12563. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12564. }
  12565. }
  12566. 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
  12567. {
  12568. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12569. }
  12570. }
  12571. else
  12572. {
  12573. //replace reservation
  12574. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12575. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12576. }
  12577. }
  12578. } // END FOR CHAdeMO_QUANTITY
  12579. }
  12580. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  12581. {
  12582. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12583. {
  12584. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12585. }
  12586. else
  12587. {
  12588. tempIndex = connectorIdInt -1;
  12589. }
  12590. for (int index = 0; index < CCS_QUANTITY; index++)
  12591. {
  12592. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12593. {
  12594. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12595. {
  12596. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12597. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12598. {
  12599. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12600. {
  12601. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  12602. {
  12603. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12604. }
  12605. else
  12606. {
  12607. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12608. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12609. }
  12610. }
  12611. 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'))
  12612. {
  12613. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12614. }
  12615. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  12616. {
  12617. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12618. }
  12619. else
  12620. {
  12621. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12622. }
  12623. }
  12624. 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
  12625. {
  12626. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12627. }
  12628. }
  12629. else
  12630. {
  12631. //replace reservation
  12632. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12633. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12634. }
  12635. }
  12636. } // END FOR CCS_QUANTITY
  12637. }
  12638. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  12639. {
  12640. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12641. {
  12642. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12643. }
  12644. else
  12645. {
  12646. tempIndex = connectorIdInt -1;
  12647. }
  12648. for (int index = 0; index < GB_QUANTITY; index++)
  12649. {
  12650. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12651. {
  12652. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12653. {
  12654. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12655. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12656. {
  12657. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12658. {
  12659. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  12660. {
  12661. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12662. }
  12663. else
  12664. {
  12665. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12666. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12667. }
  12668. }
  12669. 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'))
  12670. {
  12671. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12672. }
  12673. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12674. {
  12675. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12676. }
  12677. else
  12678. {
  12679. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12680. }
  12681. }
  12682. 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
  12683. {
  12684. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12685. }
  12686. }
  12687. else
  12688. {
  12689. //replace reservation
  12690. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12691. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12692. }
  12693. }
  12694. }// END FOR GB_QUANTITY
  12695. }
  12696. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  12697. {
  12698. tempIndex = connectorIdInt -1;
  12699. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12700. {
  12701. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12702. {
  12703. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  12704. {
  12705. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12706. 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
  12707. {
  12708. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12709. {
  12710. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  12711. {
  12712. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12713. }
  12714. else
  12715. {
  12716. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12717. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12718. }
  12719. }
  12720. 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'))
  12721. {
  12722. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12723. }
  12724. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12725. {
  12726. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12727. }
  12728. else
  12729. {
  12730. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12731. }
  12732. }
  12733. 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
  12734. {
  12735. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12736. }
  12737. }
  12738. else
  12739. {
  12740. //replace reservation
  12741. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12742. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12743. }
  12744. }
  12745. }// END FOR GB_QUANTITY
  12746. }
  12747. else
  12748. {
  12749. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12750. {
  12751. tempIndex = 2;
  12752. }
  12753. else
  12754. {
  12755. tempIndex = (connectorIdInt -1);
  12756. }
  12757. for (int index = 0; index < AC_QUANTITY; index++)
  12758. {
  12759. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12760. {
  12761. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12762. {
  12763. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12764. {
  12765. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12766. {
  12767. 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))
  12768. {
  12769. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12770. }
  12771. else
  12772. {
  12773. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12774. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12775. }
  12776. }
  12777. 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'))
  12778. {
  12779. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12780. }
  12781. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12782. {
  12783. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12784. }
  12785. else
  12786. {
  12787. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12788. }
  12789. }
  12790. 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
  12791. {
  12792. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12793. }
  12794. }
  12795. else
  12796. {
  12797. //replace reservation
  12798. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12799. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12800. }
  12801. }
  12802. } // END FOR AC_QUANTITY
  12803. }
  12804. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12805. }
  12806. else if(connectorIdInt == 0)
  12807. {
  12808. //check Transaction active
  12809. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12810. {
  12811. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12812. {
  12813. 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'))
  12814. {
  12815. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12816. goto end;
  12817. }
  12818. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12819. {
  12820. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12821. goto end;
  12822. }
  12823. 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
  12824. {
  12825. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12826. goto end;
  12827. }
  12828. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12829. {
  12830. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12831. goto end;
  12832. }
  12833. }
  12834. }// END FOR CHAdeMO_QUANTITY
  12835. for (int index = 0; index < CCS_QUANTITY; index++)
  12836. {
  12837. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12838. {
  12839. 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'))
  12840. {
  12841. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12842. goto end;
  12843. }
  12844. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12845. {
  12846. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12847. goto end;
  12848. }
  12849. 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
  12850. {
  12851. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12852. goto end;
  12853. }
  12854. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12855. {
  12856. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12857. goto end;
  12858. }
  12859. }
  12860. } // END FOR CCS_QUANTITY
  12861. for (int index = 0; index < GB_QUANTITY; index++)
  12862. {
  12863. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12864. {
  12865. 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'))
  12866. {
  12867. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12868. goto end;
  12869. }
  12870. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12871. {
  12872. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12873. goto end;
  12874. }
  12875. 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
  12876. {
  12877. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12878. goto end;
  12879. }
  12880. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12881. {
  12882. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12883. goto end;
  12884. }
  12885. }
  12886. } // END FOR GB_QUANTITY
  12887. for (int index = 0; index < AC_QUANTITY; index++)
  12888. {
  12889. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12890. {
  12891. 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'))
  12892. {
  12893. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12894. goto end;
  12895. }
  12896. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12897. {
  12898. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12899. goto end;
  12900. }
  12901. 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
  12902. {
  12903. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12904. goto end;
  12905. }
  12906. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12907. {
  12908. 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))
  12909. {
  12910. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12911. goto end;
  12912. }
  12913. }
  12914. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12915. {
  12916. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12917. goto end;
  12918. }
  12919. }
  12920. }// END FOR AC_QUANTITY
  12921. //The connectorId is 0
  12922. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12923. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12924. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12925. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12926. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12927. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12928. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12929. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12930. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12931. result = TRUE;
  12932. return result;
  12933. }
  12934. else
  12935. {
  12936. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12937. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12938. }
  12939. if(strcmp(comfirmstr,"Accepted") == 0)
  12940. {
  12941. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12942. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12943. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12944. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12945. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12946. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12947. result = TRUE;
  12948. return result;
  12949. }
  12950. end:
  12951. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12952. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12953. return result;
  12954. }
  12955. int handleResetRequest(char *uuid, char *payload)
  12956. {
  12957. mtrace();
  12958. int result = FAIL;
  12959. char sstr[10]={0},sstrtemp[30]={ 0 };
  12960. char typestr[10]={0};
  12961. char comfirmstr[20]={0};
  12962. int c = 0;
  12963. char *loc;
  12964. DEBUG_INFO("handleResetRequest...\n");
  12965. strcpy(sstrtemp, stringtrimspace(payload));
  12966. loc = strstr(sstrtemp, "type");
  12967. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12968. c = 0;
  12969. while (loc[3+strlen("type")+c] != '\"')
  12970. {
  12971. sstr[c] = loc[3+strlen("type")+c];
  12972. c++;
  12973. }
  12974. sstr[c] = '\0';
  12975. strcpy(typestr,sstr);
  12976. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12977. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12978. {
  12979. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12980. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12981. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12982. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12983. }
  12984. else
  12985. {
  12986. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12987. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12988. result = PASS;
  12989. }
  12990. sendResetConfirmation(uuid, comfirmstr);
  12991. return result;
  12992. }
  12993. int handleSendLocalListRequest(char *uuid, char *payload)
  12994. {
  12995. mtrace();
  12996. int result = FAIL;
  12997. char comfirmstr[20];
  12998. int checkState_Faulted = FALSE;
  12999. json_object *SendLocalList;
  13000. DEBUG_INFO("handleSendLocalListRequest...\n");
  13001. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  13002. {
  13003. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  13004. goto end;
  13005. }
  13006. //check Charge Point state
  13007. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13008. {
  13009. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  13010. {
  13011. checkState_Faulted = TRUE; //OCPP Status: Faulted
  13012. }
  13013. }
  13014. for (int index = 0; index < CCS_QUANTITY; index++)
  13015. {
  13016. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  13017. {
  13018. checkState_Faulted = TRUE; //OCPP Status
  13019. }
  13020. }
  13021. for (int index = 0; index < GB_QUANTITY; index++)
  13022. {
  13023. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  13024. {
  13025. checkState_Faulted = TRUE; //OCPP Status: Faulted
  13026. }
  13027. }
  13028. //check Charge Point state
  13029. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13030. {
  13031. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  13032. {
  13033. checkState_Faulted = TRUE; //OCPP Status: Faulted
  13034. }
  13035. }
  13036. //check Charge Point state
  13037. for (int index = 0; index < AC_QUANTITY; index++)
  13038. {
  13039. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  13040. {
  13041. checkState_Faulted = TRUE; //OCPP Status: Faulted
  13042. }
  13043. }
  13044. if(checkState_Faulted == TRUE)
  13045. {
  13046. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  13047. goto end;
  13048. }
  13049. // Parsing payload
  13050. SendLocalList = json_tokener_parse(payload);
  13051. if(!is_error(SendLocalList))
  13052. {
  13053. // Required data
  13054. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  13055. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  13056. // Optional data
  13057. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  13058. {
  13059. //Check UpdateType
  13060. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  13061. {
  13062. //Local list full update
  13063. DEBUG_INFO("Local list full update.\n");
  13064. locallistVersion = 0;
  13065. OCPP_getListVerion();
  13066. if((ShmOCPP16Data->SendLocalList.ListVersion > 0) && (ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion))
  13067. {
  13068. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  13069. goto end;
  13070. }
  13071. OCPP_cleanLocalList();
  13072. }
  13073. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  13074. {
  13075. //Local list different update
  13076. DEBUG_INFO("Local list different update.\n");
  13077. locallistVersion = 0;
  13078. OCPP_getListVerion();
  13079. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  13080. {
  13081. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  13082. goto end;
  13083. }
  13084. }
  13085. else
  13086. {
  13087. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  13088. goto end;
  13089. }
  13090. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  13091. {
  13092. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  13093. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  13094. goto end;
  13095. }
  13096. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  13097. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  13098. {
  13099. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag, "%s", stringtrimspace((char *)json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag"))));
  13100. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  13101. {
  13102. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status, "%s", stringtrimspace((char *)json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status"))));
  13103. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  13104. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate, "%s", stringtrimspace((char *)json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate"))));
  13105. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  13106. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag, "%s", stringtrimspace((char *)json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag"))));
  13107. }
  13108. // Add to db
  13109. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  13110. {
  13111. //Local list full update
  13112. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  13113. idx,
  13114. ShmOCPP16Data->SendLocalList.ListVersion,
  13115. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  13116. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  13117. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  13118. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  13119. // update list
  13120. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  13121. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  13122. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  13123. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  13124. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  13125. }
  13126. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  13127. {
  13128. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  13129. idx,
  13130. ShmOCPP16Data->SendLocalList.ListVersion,
  13131. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  13132. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  13133. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  13134. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  13135. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  13136. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  13137. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  13138. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  13139. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  13140. }
  13141. }
  13142. }
  13143. else
  13144. {
  13145. //Check UpdateType
  13146. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  13147. {
  13148. //Local list full update
  13149. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  13150. OCPP_cleanLocalList();
  13151. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  13152. goto end;
  13153. }
  13154. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  13155. {
  13156. //Local list different update
  13157. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  13158. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  13159. goto end;
  13160. }
  13161. }
  13162. result = PASS;
  13163. }
  13164. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  13165. end:
  13166. json_object_put(SendLocalList);
  13167. sendSendLocalListConfirmation(uuid, comfirmstr);
  13168. return result;
  13169. }
  13170. int handleSetChargingProfileRequest(char *uuid, char *payload)
  13171. {
  13172. mtrace();
  13173. int result = FAIL;
  13174. struct StructSetChargingProfile SetProfileReq = {0};
  13175. int tempchargingProfileIdInt;
  13176. int tempstackLevelInt;
  13177. int chargingSchedulePeriodCount = 0;
  13178. char comfirmstr[20]={0};
  13179. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  13180. char rmFileCmd[128]={0};
  13181. int profileQuantity = 0;
  13182. int replaceableProfileCnt = 0;
  13183. json_object *SetChargingProfile;
  13184. DEBUG_INFO("handleSetChargingProfileRequest\n");
  13185. SetChargingProfile = json_tokener_parse(payload);
  13186. if(!is_error(SetChargingProfile))
  13187. {
  13188. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  13189. {
  13190. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  13191. }
  13192. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  13193. {
  13194. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13195. {
  13196. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13197. }
  13198. else
  13199. {
  13200. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13201. DEBUG_WARN("Cannot find chargingProfileId field.");
  13202. goto end;
  13203. }
  13204. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13205. {
  13206. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  13207. }
  13208. else
  13209. {
  13210. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13211. DEBUG_WARN("Cannot find stackLevel field.");
  13212. goto end;
  13213. }
  13214. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  13215. {
  13216. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  13217. }
  13218. else
  13219. {
  13220. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13221. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  13222. goto end;
  13223. }
  13224. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  13225. {
  13226. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  13227. }
  13228. else
  13229. {
  13230. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13231. DEBUG_WARN("Cannot find chargingProfileKind field.");
  13232. goto end;
  13233. }
  13234. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  13235. {
  13236. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  13237. }
  13238. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  13239. {
  13240. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  13241. }
  13242. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  13243. {
  13244. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  13245. }
  13246. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  13247. {
  13248. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  13249. }
  13250. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  13251. {
  13252. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  13253. {
  13254. 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")));
  13255. }
  13256. else
  13257. {
  13258. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13259. DEBUG_WARN("Cannot find chargingRateUnit field.");
  13260. goto end;
  13261. }
  13262. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  13263. {
  13264. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  13265. }
  13266. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  13267. {
  13268. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  13269. }
  13270. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  13271. {
  13272. 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")));
  13273. }
  13274. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  13275. {
  13276. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  13277. if(chargingSchedulePeriodCount <= 10)
  13278. {
  13279. 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++)
  13280. {
  13281. 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)
  13282. {
  13283. 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"));
  13284. }
  13285. else
  13286. {
  13287. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13288. DEBUG_WARN("Cannot find startPeriod field.");
  13289. goto end;
  13290. }
  13291. 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)
  13292. {
  13293. 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"));
  13294. }
  13295. else
  13296. {
  13297. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13298. DEBUG_WARN("Cannot find limit field.");
  13299. goto end;
  13300. }
  13301. 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)
  13302. {
  13303. 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"));
  13304. }
  13305. }
  13306. }
  13307. }
  13308. else
  13309. {
  13310. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13311. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  13312. goto end;
  13313. }
  13314. }
  13315. else
  13316. {
  13317. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13318. DEBUG_WARN("Cannot find chargingSchedule field.");
  13319. goto end;
  13320. }
  13321. }
  13322. }
  13323. // Profile periods quantity check
  13324. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  13325. {
  13326. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13327. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13328. goto end;
  13329. }
  13330. // Check invalid limit
  13331. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  13332. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  13333. {
  13334. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  13335. {
  13336. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  13337. {
  13338. 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)))) ||
  13339. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  13340. {
  13341. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13342. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  13343. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  13344. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  13345. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  13346. goto end;
  13347. }
  13348. }
  13349. }
  13350. else
  13351. {
  13352. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  13353. {
  13354. 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) ||
  13355. (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)))
  13356. {
  13357. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13358. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  13359. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  13360. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  13361. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  13362. goto end;
  13363. }
  13364. }
  13365. }
  13366. }
  13367. // Profile purpose info check
  13368. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13369. {
  13370. FILE *fp;
  13371. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  13372. if(SetProfileReq.ConnectorId != 0)
  13373. {
  13374. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13375. DEBUG_WARN("Profile connector id is not 0.\n");
  13376. goto end;
  13377. }
  13378. fp = fopen(ChargePointMaxProfile_JSON, "r");
  13379. if (!fp)
  13380. {
  13381. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  13382. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  13383. }
  13384. else
  13385. {
  13386. char *line = NULL;
  13387. size_t len = 0;
  13388. while(getline(&line, &len, fp) != -1)
  13389. {
  13390. json_object *obj = NULL;
  13391. obj = json_tokener_parse(line);
  13392. if(is_error(obj))
  13393. {
  13394. DEBUG_ERROR("Parse txProfile from file error.\n");
  13395. }
  13396. else
  13397. {
  13398. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13399. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13400. {
  13401. profileQuantity += 1;
  13402. }
  13403. else
  13404. replaceableProfileCnt += 1;
  13405. }
  13406. }
  13407. }
  13408. fclose(fp);
  13409. }
  13410. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13411. {
  13412. FILE *fp;
  13413. char filename[128]={0};
  13414. int tmpProfileQuantity;
  13415. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  13416. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13417. {
  13418. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13419. DEBUG_WARN("Profile connector id is over max gun number.\n");
  13420. goto end;
  13421. }
  13422. if(SetProfileReq.ConnectorId == 0)
  13423. {
  13424. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  13425. {
  13426. tmpProfileQuantity = 0;
  13427. memset(filename, 0, ARRAY_SIZE(filename));
  13428. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13429. fp = fopen(filename, "r");
  13430. if (!fp)
  13431. {
  13432. DEBUG_INFO("%s does not create.\n", filename);
  13433. fp = fopen(filename, "w+");
  13434. }
  13435. else
  13436. {
  13437. char *line = NULL;
  13438. size_t len = 0;
  13439. while(getline(&line, &len, fp) != -1)
  13440. {
  13441. json_object *obj = NULL;
  13442. obj = json_tokener_parse(line);
  13443. if(is_error(obj))
  13444. {
  13445. DEBUG_ERROR("Parse txProfile from file error.\n");
  13446. }
  13447. else
  13448. {
  13449. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13450. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13451. {
  13452. tmpProfileQuantity += 1;
  13453. }
  13454. else
  13455. replaceableProfileCnt += 1;
  13456. }
  13457. }
  13458. }
  13459. fclose(fp);
  13460. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  13461. }
  13462. }
  13463. else
  13464. {
  13465. memset(filename, 0, ARRAY_SIZE(filename));
  13466. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13467. fp = fopen(filename, "r");
  13468. if (!fp)
  13469. {
  13470. DEBUG_INFO("%s does not create.\n", filename);
  13471. fp = fopen(filename, "w+");
  13472. }
  13473. else
  13474. {
  13475. char *line = NULL;
  13476. size_t len = 0;
  13477. while(getline(&line, &len, fp) != -1)
  13478. {
  13479. json_object *obj = NULL;
  13480. obj = json_tokener_parse(line);
  13481. if(is_error(obj))
  13482. {
  13483. DEBUG_ERROR("Parse txProfile from file error.\n");
  13484. }
  13485. else
  13486. {
  13487. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13488. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13489. {
  13490. profileQuantity += 1;
  13491. }
  13492. else
  13493. replaceableProfileCnt += 1;
  13494. }
  13495. }
  13496. }
  13497. fclose(fp);
  13498. }
  13499. }
  13500. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  13501. {
  13502. int isMatchTransactiodId= FALSE;
  13503. FILE *fp;
  13504. char filename[128]={0};
  13505. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  13506. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  13507. if(SetProfileReq.ConnectorId == 0)
  13508. {
  13509. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13510. DEBUG_WARN("Profile connector id is 0.\n");
  13511. goto end;
  13512. }
  13513. int tempIndex = 0;
  13514. //check Transaction active
  13515. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  13516. {
  13517. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13518. {
  13519. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13520. }
  13521. else
  13522. {
  13523. tempIndex = SetProfileReq.ConnectorId -1;
  13524. }
  13525. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13526. {
  13527. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13528. {
  13529. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13530. {
  13531. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13532. {
  13533. isMatchTransactiodId = TRUE;
  13534. break;
  13535. }
  13536. }
  13537. }
  13538. }
  13539. }
  13540. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  13541. {
  13542. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13543. {
  13544. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13545. }
  13546. else
  13547. {
  13548. tempIndex = SetProfileReq.ConnectorId -1;
  13549. }
  13550. for (int index = 0; index < CCS_QUANTITY; index++)
  13551. {
  13552. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13553. {
  13554. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  13555. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13556. {
  13557. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13558. {
  13559. isMatchTransactiodId = TRUE;
  13560. break;
  13561. }
  13562. }
  13563. }
  13564. }
  13565. }
  13566. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  13567. {
  13568. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13569. {
  13570. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13571. }
  13572. else
  13573. {
  13574. tempIndex = SetProfileReq.ConnectorId -1;
  13575. }
  13576. for (int index = 0; index < GB_QUANTITY; index++)
  13577. {
  13578. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13579. {
  13580. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13581. {
  13582. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13583. {
  13584. isMatchTransactiodId = TRUE;
  13585. break;
  13586. }
  13587. }
  13588. }
  13589. }
  13590. }
  13591. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  13592. {
  13593. tempIndex = SetProfileReq.ConnectorId -1;
  13594. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13595. {
  13596. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13597. {
  13598. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  13599. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13600. {
  13601. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13602. {
  13603. isMatchTransactiodId = TRUE;
  13604. break;
  13605. }
  13606. }
  13607. }
  13608. }
  13609. }
  13610. else
  13611. {
  13612. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13613. {
  13614. tempIndex = 2;
  13615. }
  13616. else
  13617. {
  13618. tempIndex = (SetProfileReq.ConnectorId -1);
  13619. }
  13620. for (int index = 0; index < AC_QUANTITY; index++)
  13621. {
  13622. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13623. {
  13624. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  13625. {
  13626. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13627. {
  13628. isMatchTransactiodId = TRUE;
  13629. break;
  13630. }
  13631. }
  13632. }
  13633. }
  13634. }
  13635. //check Transaction active
  13636. if(isMatchTransactiodId == FALSE)
  13637. {
  13638. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13639. DEBUG_WARN("Tx profile transaction id is not match.\n");
  13640. goto end;
  13641. }
  13642. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13643. {
  13644. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13645. DEBUG_WARN("Connector id is over max gun number.\n");
  13646. goto end;
  13647. }
  13648. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13649. fp = fopen(filename, "r");
  13650. if (!fp)
  13651. {
  13652. DEBUG_INFO("%s does not create.\n", filename);
  13653. fp = fopen(filename, "w+");
  13654. }
  13655. else
  13656. {
  13657. char *line = NULL;
  13658. size_t len = 0;
  13659. while(getline(&line, &len, fp) != -1)
  13660. {
  13661. json_object *obj = NULL;
  13662. obj = json_tokener_parse(line);
  13663. if(is_error(obj))
  13664. {
  13665. DEBUG_ERROR("Parse txProfile from file error.\n");
  13666. }
  13667. else
  13668. {
  13669. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13670. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13671. {
  13672. profileQuantity += 1;
  13673. }
  13674. else
  13675. replaceableProfileCnt += 1;
  13676. }
  13677. }
  13678. }
  13679. fclose(fp);
  13680. }
  13681. // Check ChargeProfileMaxStackLevel
  13682. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  13683. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  13684. {
  13685. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13686. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13687. goto end;
  13688. }
  13689. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13690. {
  13691. FILE *fp;
  13692. char dataLine[4096]={0};
  13693. char fnametemp[128]={0};
  13694. int tmpProfileQuantity;
  13695. //Check ChargePointMaxProfile.json exit
  13696. profileQuantity = 0;
  13697. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  13698. {
  13699. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  13700. //Check Charging Profile Count
  13701. tmpProfileQuantity = 0;
  13702. while(fscanf(fp, "%s", dataLine) != EOF)
  13703. {
  13704. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13705. {
  13706. profileQuantity += 1;
  13707. tmpProfileQuantity += 1;
  13708. }
  13709. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13710. }
  13711. fclose(fp);
  13712. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  13713. }
  13714. //Check TxDefaultProfile_%d.json
  13715. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13716. {
  13717. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13718. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13719. if((access(fnametemp,F_OK))!=-1)
  13720. {
  13721. fp = fopen(fnametemp, "r");
  13722. //Check Charging Profile Count
  13723. tmpProfileQuantity = 0;
  13724. while(fscanf(fp, "%s", dataLine) != EOF)
  13725. {
  13726. //DEBUG_INFO("word=%s\n",word);
  13727. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13728. {
  13729. profileQuantity += 1;
  13730. tmpProfileQuantity += 1;
  13731. }
  13732. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13733. }
  13734. fclose(fp);
  13735. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13736. }
  13737. }
  13738. //Check TxProfile_%d.json
  13739. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13740. {
  13741. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13742. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  13743. if((access(fnametemp,F_OK))!=-1)
  13744. {
  13745. fp = fopen(fnametemp, "r");
  13746. //Check Charging Profile Count
  13747. tmpProfileQuantity = 0;
  13748. while(fscanf(fp, "%s", dataLine) != EOF)
  13749. {
  13750. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13751. {
  13752. profileQuantity += 1;
  13753. tmpProfileQuantity += 1;
  13754. }
  13755. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13756. }
  13757. fclose(fp);
  13758. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13759. }
  13760. }
  13761. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  13762. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  13763. // To check total Profile quantity
  13764. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  13765. {
  13766. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13767. {
  13768. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13769. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13770. goto end;
  13771. }
  13772. }
  13773. else
  13774. {
  13775. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13776. {
  13777. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13778. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13779. goto end;
  13780. }
  13781. }
  13782. }
  13783. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13784. //**********************************Write to File********************************************************/
  13785. {
  13786. FILE *infile;
  13787. FILE *outfile;
  13788. char dataLine[4096]={0};
  13789. char filename[128]={0};
  13790. int chkChar=0;
  13791. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  13792. {
  13793. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13794. {
  13795. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  13796. }
  13797. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13798. {
  13799. if(SetProfileReq.ConnectorId==0)
  13800. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13801. else
  13802. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13803. }
  13804. else
  13805. {
  13806. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13807. }
  13808. infile = fopen (filename, "r");
  13809. outfile = fopen (tempfile, "w");
  13810. chkChar = fgetc(infile);
  13811. rewind(infile);
  13812. if(chkChar == EOF)
  13813. {
  13814. // Profile is empty
  13815. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13816. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13817. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13818. fclose(infile);
  13819. fclose(outfile);
  13820. sprintf(rmFileCmd,"rm -f %s",filename);
  13821. system(rmFileCmd);
  13822. rename(tempfile, filename);
  13823. }
  13824. else
  13825. {
  13826. // Profile is not empty
  13827. int ChargingProfileAdded = FALSE;
  13828. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  13829. {
  13830. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  13831. json_object *tmpChargingProfile;
  13832. tmpChargingProfile = json_tokener_parse(dataLine);
  13833. if(!is_error(SetChargingProfile))
  13834. {
  13835. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13836. {
  13837. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13838. {
  13839. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13840. }
  13841. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13842. {
  13843. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13844. }
  13845. }
  13846. }
  13847. json_object_put(tmpChargingProfile);
  13848. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  13849. {
  13850. if(ChargingProfileAdded == FALSE)
  13851. {
  13852. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13853. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13854. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13855. ChargingProfileAdded = TRUE;
  13856. }
  13857. }
  13858. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13859. {
  13860. if(ChargingProfileAdded == FALSE)
  13861. {
  13862. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13863. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13864. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13865. ChargingProfileAdded = TRUE;
  13866. }
  13867. }
  13868. else
  13869. {
  13870. fprintf(outfile,"%s\n",dataLine);
  13871. if(ChargingProfileAdded == FALSE)
  13872. {
  13873. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13874. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13875. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13876. ChargingProfileAdded = TRUE;
  13877. }
  13878. }
  13879. } // end of while loop
  13880. fclose(infile);
  13881. fclose(outfile);
  13882. sprintf(rmFileCmd,"rm -f %s",filename);
  13883. system(rmFileCmd);
  13884. rename(tempfile, filename);
  13885. }
  13886. }
  13887. sleep(1);
  13888. result = TRUE;
  13889. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13890. }
  13891. end:
  13892. json_object_put(SetChargingProfile);
  13893. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13894. {
  13895. if(SetProfileReq.ConnectorId == 0)
  13896. {
  13897. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13898. {
  13899. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13900. }
  13901. }
  13902. else
  13903. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13904. }
  13905. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13906. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13907. return result;
  13908. }
  13909. int handleTriggerMessageRequest(char *uuid, char *payload)
  13910. {
  13911. mtrace();
  13912. int result = FAIL;
  13913. int connectorIdIsNULL = FALSE;
  13914. int connectorIdInt =0;
  13915. char sstr[40]={0},sstrtemp[100]={ 0 };
  13916. char requestedMessagestr[40]={0};
  13917. char comfirmstr[20]={0};
  13918. int c = 0;
  13919. char *loc;
  13920. DEBUG_INFO("handleTriggerMessageRequest\n");
  13921. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13922. strcpy(sstrtemp, stringtrimspace(payload));
  13923. c = 0;
  13924. loc = strstr(sstrtemp, "requestedMessage");
  13925. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13926. {
  13927. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13928. c++;
  13929. }
  13930. sstr[c] = '\0';
  13931. strcpy(requestedMessagestr, sstr);
  13932. c = 0;
  13933. loc = strstr(sstrtemp, "connectorId");
  13934. if(loc == NULL)
  13935. {
  13936. connectorIdIsNULL = TRUE;
  13937. }
  13938. else
  13939. {
  13940. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13941. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13942. {
  13943. sstr[c] = loc[strlen("connectorId")+2+c];
  13944. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13945. c++;
  13946. }
  13947. sstr[c] = '\0';
  13948. connectorIdInt = atoi(sstr);
  13949. }
  13950. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13951. {
  13952. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13953. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13954. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13955. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13956. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13957. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13958. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13959. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13960. {
  13961. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13962. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13963. return TRUE;
  13964. }
  13965. else
  13966. {
  13967. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13968. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13969. }
  13970. }
  13971. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13972. {
  13973. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13974. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13975. return TRUE;
  13976. }
  13977. //==========================
  13978. // Trigger message
  13979. //==========================
  13980. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13981. {
  13982. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13983. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13984. {
  13985. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13986. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13987. }
  13988. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13989. }
  13990. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13991. {
  13992. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13993. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13994. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13995. }
  13996. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13997. {
  13998. //sendBootNotificationRequest();
  13999. server_sign = FALSE;
  14000. }
  14001. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  14002. {
  14003. refreshStartTimer(&clientTime.Heartbeat);
  14004. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  14005. }
  14006. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  14007. {
  14008. if(connectorIdIsNULL == FALSE)
  14009. {
  14010. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  14011. {
  14012. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  14013. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  14014. }
  14015. }
  14016. else
  14017. {
  14018. for(int idx=0;idx< gunTotalNumber;idx++)
  14019. {
  14020. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  14021. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  14022. }
  14023. }
  14024. }
  14025. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  14026. {
  14027. if(connectorIdIsNULL == FALSE)
  14028. {
  14029. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  14030. {
  14031. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  14032. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  14033. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  14034. }
  14035. }
  14036. else
  14037. {
  14038. for(int idx=0;idx< gunTotalNumber;idx++)
  14039. {
  14040. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  14041. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  14042. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  14043. }
  14044. }
  14045. }
  14046. return result;
  14047. }
  14048. int handleUnlockConnectorRequest(char *uuid, char *payload)
  14049. {
  14050. mtrace();
  14051. int result = FAIL;
  14052. int connectorIdInt =0;
  14053. char comfirmstr[20]={0};
  14054. int tempIndex = 0;
  14055. json_object *UnlockConnector;
  14056. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  14057. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  14058. UnlockConnector = json_tokener_parse(payload);
  14059. if(!is_error(UnlockConnector))
  14060. {
  14061. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  14062. {
  14063. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  14064. }
  14065. }
  14066. json_object_put(UnlockConnector);
  14067. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  14068. if(gunTotalNumber == 0)
  14069. {
  14070. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  14071. goto end;
  14072. }
  14073. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  14074. {
  14075. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  14076. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  14077. goto end;
  14078. }
  14079. else
  14080. {
  14081. //check Transaction active
  14082. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  14083. {
  14084. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14085. {
  14086. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  14087. }
  14088. else
  14089. {
  14090. tempIndex = connectorIdInt -1;
  14091. }
  14092. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14093. {
  14094. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  14095. {
  14096. //stop Transaction
  14097. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  14098. }
  14099. }
  14100. }
  14101. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  14102. {
  14103. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14104. {
  14105. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  14106. }
  14107. else
  14108. {
  14109. tempIndex = connectorIdInt -1;
  14110. }
  14111. for (int index = 0; index < CCS_QUANTITY; index++)
  14112. {
  14113. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  14114. {
  14115. //stop Transaction
  14116. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  14117. }
  14118. }
  14119. }
  14120. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  14121. {
  14122. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14123. {
  14124. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  14125. }
  14126. else
  14127. {
  14128. tempIndex = connectorIdInt -1;
  14129. }
  14130. for (int index = 0; index < GB_QUANTITY; index++)
  14131. {
  14132. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  14133. {
  14134. //stop Transaction
  14135. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  14136. }
  14137. }
  14138. }
  14139. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  14140. {
  14141. tempIndex = connectorIdInt -1;
  14142. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14143. {
  14144. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  14145. {
  14146. //stop Transaction
  14147. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  14148. }
  14149. }
  14150. }
  14151. else
  14152. {
  14153. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14154. {
  14155. tempIndex = 2;
  14156. }
  14157. else
  14158. {
  14159. tempIndex = connectorIdInt-1;
  14160. }
  14161. for (int index = 0; index < AC_QUANTITY; index++)
  14162. {
  14163. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  14164. {
  14165. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  14166. }
  14167. }
  14168. }
  14169. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  14170. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  14171. result = TRUE;
  14172. return result;
  14173. }
  14174. end:
  14175. //json_object_put(obj); --- remove temporally
  14176. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  14177. return result;
  14178. }
  14179. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  14180. {
  14181. mtrace();
  14182. int result = FAIL;
  14183. pthread_t t;
  14184. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  14185. sendUpdateFirmwareConfirmation(uuid);
  14186. if(!interLock.isUpdateFirmwareGoing)
  14187. {
  14188. interLock.isUpdateFirmwareGoing = 1;
  14189. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  14190. sleep(1);
  14191. }
  14192. else
  14193. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  14194. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  14195. return result;
  14196. }
  14197. void *UpdateFirmwareProcess(void *data)
  14198. {
  14199. pthread_detach(pthread_self());
  14200. mtrace();
  14201. int retriesInt =0, retryIntervalInt=0;
  14202. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  14203. int port=0;
  14204. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  14205. int isSuccess = 0;
  14206. char ftpbuf[1024];
  14207. char temp[1024];
  14208. char * pch;
  14209. json_object *UpdateFirmware;
  14210. UpdateFirmware = json_tokener_parse(data);
  14211. if(!is_error(UpdateFirmware))
  14212. {
  14213. // Required data
  14214. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  14215. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  14216. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  14217. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  14218. // Optional data
  14219. if(json_object_object_get(UpdateFirmware, "retries"))
  14220. {
  14221. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  14222. }
  14223. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  14224. {
  14225. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  14226. }
  14227. }
  14228. json_object_put(UpdateFirmware);
  14229. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14230. memset(path, 0, ARRAY_SIZE(path));
  14231. // Wait retrieveData
  14232. if(strlen(retrieveDatestr) > 10)
  14233. {
  14234. do
  14235. {
  14236. sleep(1);
  14237. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  14238. }
  14239. // Ready to download
  14240. system("rm -f /mnt/*");
  14241. if(strncmp(locationstr,"http", 4) == 0)
  14242. {
  14243. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14244. sprintf(ftppath,"/%s", path);
  14245. DEBUG_INFO("locationstr: %s\n", locationstr);
  14246. DEBUG_INFO("protocol: %s\n",protocol);
  14247. DEBUG_INFO("host: %s\n",host);
  14248. DEBUG_INFO("path: %s\n",path);
  14249. DEBUG_INFO("ftppath: %s\n",ftppath);
  14250. int ftppathlen=strlen(ftppath);
  14251. int i=1;
  14252. char filenametemp[50];
  14253. while(i < ftppathlen)
  14254. {
  14255. int len=ftppathlen-i;
  14256. if(ftppath[len]== 47) // '/' ascll code: 47
  14257. {
  14258. DEBUG_INFO("compare '/' all right\n");
  14259. break;
  14260. }
  14261. i=i+1;
  14262. }
  14263. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14264. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  14265. filenametemp[i+1] = 0;
  14266. do
  14267. {
  14268. sleep(1);
  14269. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  14270. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14271. sleep(1);
  14272. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  14273. if(!isSuccess)
  14274. {
  14275. sleep(1);
  14276. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  14277. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14278. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  14279. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  14280. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14281. }
  14282. else
  14283. {
  14284. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  14285. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14286. }
  14287. retriesInt--;
  14288. }while((isSuccess == 0)&&(retriesInt >= 0));
  14289. }
  14290. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  14291. {
  14292. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14293. memset(temp, 0, ARRAY_SIZE(temp));
  14294. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14295. strcpy(ftpbuf, locationstr);
  14296. int ftppathlen=strlen(ftpbuf);
  14297. int i=1;
  14298. char filenametemp[50];
  14299. while(i < ftppathlen)
  14300. {
  14301. int len=ftppathlen-i;
  14302. if(ftpbuf[len]== 47) // '/' ascii code: 47
  14303. {
  14304. DEBUG_INFO(" compare '/' all right\n");
  14305. break;
  14306. }
  14307. i=i+1;
  14308. }
  14309. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14310. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  14311. filenametemp[i+1] = 0;
  14312. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14313. pch=strchr(temp,'@');
  14314. if(pch==NULL)
  14315. {
  14316. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14317. protocol, host, &port, path);
  14318. strcpy(user,"anonymous");
  14319. strcpy(password,"");
  14320. }
  14321. else
  14322. {
  14323. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  14324. protocol, user, host, &port, path);
  14325. }
  14326. sscanf(host,"%[^/]%s",host1, path1);
  14327. sprintf(ftppath,"%s:/%s", host,path);
  14328. if(port == 0)
  14329. {
  14330. port = 21;
  14331. }
  14332. do
  14333. {
  14334. sleep(1);
  14335. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  14336. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14337. sleep(1);
  14338. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  14339. if(!isSuccess)
  14340. {
  14341. //BulldogUtil.sleepMs(interval*1000);
  14342. DEBUG_INFO("Update firmware request and download file fail.\n");
  14343. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  14344. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14345. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  14346. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  14347. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14348. }
  14349. else
  14350. {
  14351. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  14352. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14353. }
  14354. retriesInt--;
  14355. }while((!isSuccess)&&(retriesInt >= 0));
  14356. }
  14357. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  14358. {
  14359. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14360. memset(temp, 0, ARRAY_SIZE(temp));
  14361. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14362. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  14363. int ftppathlen=strlen(ftpbuf);
  14364. int i=1;
  14365. char filenametemp[50];
  14366. while(i < ftppathlen)
  14367. {
  14368. int len=ftppathlen-i;
  14369. if(ftpbuf[len]== 47) // '/' ascll code: 47
  14370. {
  14371. DEBUG_INFO(" compare '/' all right\n");
  14372. break;
  14373. }
  14374. i=i+1;
  14375. }
  14376. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14377. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  14378. filenametemp[i+1] = 0;
  14379. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14380. pch=strchr(temp,'@');
  14381. if(pch==NULL)
  14382. {
  14383. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14384. protocol, host, &port, path);
  14385. strcpy(user,"anonymous");
  14386. strcpy(password,"");
  14387. }
  14388. else
  14389. {
  14390. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14391. protocol, user, password, host, &port, path);
  14392. }
  14393. sscanf(host,"%[^/]%s",host1, path1);
  14394. sprintf(ftppath,"%s", path1);
  14395. //DEBUG_INFO("protocol =%s\n",protocol);
  14396. //DEBUG_INFO("user =%s\n",user);
  14397. //DEBUG_INFO("password =%s\n",password);
  14398. //DEBUG_INFO("host1 =%s\n",host1);
  14399. //DEBUG_INFO("port =%d\n",port);
  14400. //DEBUG_INFO("path1 =%s\n",path1);
  14401. //DEBUG_INFO("ftppath=%s\n",ftppath);
  14402. //ftpFile(host, user, password, port, ftppath, fname);
  14403. //download firmware pthred
  14404. if(port == 0)
  14405. {
  14406. port = 21;
  14407. }
  14408. do
  14409. {
  14410. sleep(1);
  14411. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  14412. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14413. sleep(1);
  14414. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  14415. if(!isSuccess)
  14416. {
  14417. //BulldogUtil.sleepMs(interval*1000);
  14418. DEBUG_INFO("Update firmware request and download file fail.\n");
  14419. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  14420. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14421. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  14422. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  14423. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14424. }
  14425. else
  14426. {
  14427. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  14428. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14429. }
  14430. retriesInt--;
  14431. }while((!isSuccess)&&(retriesInt >= 0));
  14432. }
  14433. else
  14434. {
  14435. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  14436. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14437. sleep(1);
  14438. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  14439. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14440. }
  14441. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)
  14442. {
  14443. sleep(3);
  14444. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  14445. }
  14446. interLock.isUpdateFirmwareGoing = 0;
  14447. pthread_exit(NULL);
  14448. }
  14449. int handleCertificateSignedRequest(char *uuid, char *payload)
  14450. {
  14451. mtrace();
  14452. int result = PASS;
  14453. json_object *CertificateSigned;
  14454. DEBUG_INFO("handleCertificateSignedRequest...\n");
  14455. CertificateSigned = json_tokener_parse(payload);
  14456. if(!is_error(CertificateSigned))
  14457. {
  14458. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  14459. }
  14460. json_object_put(CertificateSigned);
  14461. FILE *fp = fopen("/Storage/OCPP/tempCP.pem", "w");
  14462. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  14463. fclose(fp);
  14464. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14465. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  14466. if(certVerify(PRIVATE_KEY_CP, "/Storage/OCPP/tempCP.pem") == PASS)
  14467. {
  14468. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  14469. system("rm -f /Storage/OCPP/certCP_fallback.pem");
  14470. rename(CERTIFICATE_CP, "/Storage/OCPP/certCP_fallback.pem");
  14471. rename("/Storage/OCPP/tempCP.pem", CERTIFICATE_CP);
  14472. }
  14473. else
  14474. {
  14475. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Rejected");
  14476. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  14477. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14478. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14479. }
  14480. sendCertificateSignedConfirmation(uuid);
  14481. return result;
  14482. }
  14483. int handleDeleteCertificateRequest(char *uuid, char *payload)
  14484. {
  14485. mtrace();
  14486. int result = PASS;
  14487. json_object *DeleteCertificate;
  14488. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  14489. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  14490. DeleteCertificate = json_tokener_parse(payload);
  14491. if(!is_error(DeleteCertificate))
  14492. {
  14493. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  14494. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  14495. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  14496. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  14497. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14498. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  14499. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  14500. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  14501. char temp[256] = {0};
  14502. char compareData[256] = {0};
  14503. int isMatch = TRUE;
  14504. FILE *fp;
  14505. if(access(ROOTCA_CS,F_OK) != -1)
  14506. {
  14507. // Check CentralSystemRootCertificate
  14508. DEBUG_INFO("Checking CentralSystemRootCertificate...\n");
  14509. parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, compareData);
  14510. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14511. isMatch = FALSE;
  14512. if(isMatch == TRUE)
  14513. {
  14514. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, compareData);
  14515. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14516. isMatch = FALSE;
  14517. }
  14518. if(isMatch == TRUE)
  14519. {
  14520. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, compareData);
  14521. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14522. isMatch = FALSE;
  14523. }
  14524. if(isMatch == TRUE)
  14525. {
  14526. sprintf(temp, "rm -f /Storage/OCPP/%s", ROOTCA_CS);
  14527. system(temp);
  14528. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14529. goto End;
  14530. }
  14531. }
  14532. // Check ManufacturerRootCertificate
  14533. if(access(ROOTCA_MFG,F_OK) != -1)
  14534. {
  14535. isMatch = TRUE;
  14536. parseCertInfo(ROOTCA_MFG, CERT_PARSE_SerialNumber, compareData);
  14537. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14538. isMatch = FALSE;
  14539. if(isMatch == TRUE)
  14540. {
  14541. parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerNameHash, compareData);
  14542. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14543. isMatch = FALSE;
  14544. }
  14545. if(isMatch == TRUE)
  14546. {
  14547. parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerKeyHash, compareData);
  14548. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14549. isMatch = FALSE;
  14550. }
  14551. if(isMatch == TRUE)
  14552. {
  14553. sprintf(temp, "rm -f %s", ROOTCA_MFG);
  14554. system(temp);
  14555. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14556. goto End;
  14557. }
  14558. }
  14559. // Check certCP
  14560. if(access(CERTIFICATE_CP,F_OK) != -1)
  14561. {
  14562. isMatch = FALSE;
  14563. sprintf(temp ,"openssl x509 -noout -serial -in %s", CERTIFICATE_CP);
  14564. fp = popen(temp, "r");
  14565. if(fp)
  14566. {
  14567. while(fgets(temp, sizeof(temp), fp) != NULL)
  14568. {
  14569. if(strstr(temp, "serial=") != NULL)
  14570. {
  14571. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14572. sscanf(temp, "%*[^=]=%s", compareData);
  14573. break;
  14574. }
  14575. }
  14576. }
  14577. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14578. isMatch = FALSE;
  14579. if(isMatch == TRUE)
  14580. {
  14581. memset(compareData, 0, ARRAY_SIZE(compareData));
  14582. sprintf(temp ,"openssl x509 -noout -issuer -in %s | openssl dgst -%s", CERTIFICATE_CP, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14583. fp = popen(temp, "r");
  14584. if(fp)
  14585. {
  14586. while(fgets(temp, sizeof(temp), fp) != NULL)
  14587. {
  14588. strcat(compareData, temp);
  14589. }
  14590. }
  14591. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) == NULL)
  14592. isMatch = FALSE;
  14593. }
  14594. if(isMatch == TRUE)
  14595. {
  14596. memset(compareData, 0, ARRAY_SIZE(compareData));
  14597. sprintf(temp ,"openssl x509 -noout -pubkey -in %s | openssl dgst -%s", CERTIFICATE_CP, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14598. fp = popen(temp, "r");
  14599. if(fp)
  14600. {
  14601. while(fgets(temp, sizeof(temp), fp) != NULL)
  14602. {
  14603. strcat(compareData, temp);
  14604. }
  14605. }
  14606. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14607. isMatch = FALSE;
  14608. }
  14609. if(isMatch == TRUE)
  14610. {
  14611. sprintf(temp, "rm -f %s", CERTIFICATE_CP);
  14612. system(temp);
  14613. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14614. goto End;
  14615. }
  14616. }
  14617. }
  14618. End:
  14619. json_object_put(DeleteCertificate);
  14620. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  14621. sendDeleteCertificateConfirmation(uuid);
  14622. return result;
  14623. }
  14624. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  14625. {
  14626. mtrace();
  14627. int result = PASS;
  14628. json_object *ExtendedTriggerMessage;
  14629. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  14630. ExtendedTriggerMessage = json_tokener_parse(payload);
  14631. if(!is_error(ExtendedTriggerMessage))
  14632. {
  14633. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  14634. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  14635. {
  14636. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  14637. }
  14638. else
  14639. {
  14640. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  14641. }
  14642. }
  14643. json_object_put(ExtendedTriggerMessage);
  14644. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  14645. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  14646. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  14647. {
  14648. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  14649. }
  14650. else
  14651. {
  14652. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  14653. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  14654. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  14655. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  14656. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  14657. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  14658. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  14659. {
  14660. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  14661. }
  14662. else
  14663. {
  14664. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  14665. }
  14666. }
  14667. sendExtendedTriggerMessageConfirmation(uuid);
  14668. //==========================
  14669. // Trigger message
  14670. //==========================
  14671. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  14672. {
  14673. //sendBootNotificationRequest();
  14674. server_sign = FALSE;
  14675. }
  14676. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  14677. {
  14678. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14679. }
  14680. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  14681. {
  14682. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  14683. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  14684. {
  14685. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  14686. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  14687. }
  14688. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14689. }
  14690. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  14691. {
  14692. refreshStartTimer(&clientTime.Heartbeat);
  14693. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  14694. }
  14695. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  14696. {
  14697. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14698. {
  14699. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  14700. }
  14701. else
  14702. {
  14703. for(int idx=0;idx< gunTotalNumber;idx++)
  14704. {
  14705. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  14706. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  14707. }
  14708. }
  14709. }
  14710. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  14711. {
  14712. char cmdBuf[1024]={0};
  14713. 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);
  14714. system(cmdBuf);
  14715. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  14716. }
  14717. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  14718. {
  14719. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14720. {
  14721. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  14722. }
  14723. else
  14724. {
  14725. for(int idx=0;idx< gunTotalNumber;idx++)
  14726. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  14727. }
  14728. }
  14729. return result;
  14730. }
  14731. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  14732. {
  14733. mtrace();
  14734. int result = PASS;
  14735. json_object *GetInstalledCertificateIds;
  14736. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  14737. GetInstalledCertificateIds = json_tokener_parse(payload);
  14738. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  14739. if(!is_error(GetInstalledCertificateIds))
  14740. {
  14741. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  14742. DEBUG_INFO("Requested Certificate: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14743. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "Accepted");
  14744. // Check CentralSystemRootCertificate
  14745. if((strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "CentralSystemRootCertificate")!= NULL) && (access(ROOTCA_CS,F_OK) != -1))
  14746. {
  14747. char parseData[512] = {0};
  14748. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14749. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14750. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_SerialNumber, parseData) == PASS)
  14751. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14752. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14753. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14754. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14755. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14756. }
  14757. else
  14758. {
  14759. DEBUG_INFO(">>> No CentralSystemRootCertificate found.\n");
  14760. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14761. }
  14762. // Check ManufacturerRootCertificate
  14763. if((strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "ManufacturerRootCertificate") != NULL) && (access(ROOTCA_MFG,F_OK) != -1))
  14764. {
  14765. char parseData[512] = {0};
  14766. if(parseCertInfo(ROOTCA_MFG, 1, parseData) == PASS)
  14767. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14768. if(parseCertInfo(ROOTCA_MFG, 1, parseData) == PASS)
  14769. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14770. if(parseCertInfo(ROOTCA_MFG, 1, parseData) == PASS)
  14771. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14772. if(parseCertInfo(ROOTCA_MFG, 1, parseData) == PASS)
  14773. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14774. }
  14775. else
  14776. {
  14777. DEBUG_INFO(">>> No ManufacturerRootCertificate found.\n");
  14778. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14779. }
  14780. }
  14781. json_object_put(GetInstalledCertificateIds);
  14782. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  14783. sendGetInstalledCertificateIdsConfirmation(uuid);
  14784. return result;
  14785. }
  14786. void* GetLogProcess(void* data)
  14787. {
  14788. pthread_detach(pthread_self());
  14789. mtrace();
  14790. 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};
  14791. int port=0;
  14792. int isSuccess = FALSE;
  14793. char cmdBuf[2048];
  14794. struct tm *tmNow;
  14795. time_t CurrentTime;
  14796. struct tm tmStart;
  14797. struct tm tmStop;
  14798. CurrentTime = time(NULL);
  14799. tmNow=localtime(&CurrentTime);
  14800. uint16_t targetYear, targetMonth;
  14801. json_object *GetLog;
  14802. DEBUG_INFO("GetLogProcess...\n");
  14803. GetLog = json_tokener_parse(data);
  14804. if(!is_error(GetLog))
  14805. {
  14806. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  14807. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  14808. if(json_object_object_get(GetLog, "retries") != NULL)
  14809. {
  14810. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  14811. }
  14812. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  14813. {
  14814. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  14815. }
  14816. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  14817. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  14818. {
  14819. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  14820. }
  14821. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  14822. {
  14823. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  14824. }
  14825. }
  14826. json_object_put(GetLog);
  14827. // Pack log to compress file
  14828. 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) &&
  14829. (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))
  14830. {
  14831. // Pack system log
  14832. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14833. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14834. targetYear = tmStart.tm_year;
  14835. targetMonth = tmStart.tm_mon;
  14836. do
  14837. {
  14838. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14839. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  14840. if(targetMonth+1>=13)
  14841. {
  14842. targetYear += 1;
  14843. targetMonth = 1;
  14844. }
  14845. else
  14846. {
  14847. targetMonth += 1;
  14848. }
  14849. }while((targetYear < (tmNow->tm_year+1900)) ||
  14850. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14851. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  14852. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  14853. system(cmdBuf);
  14854. // Pack charging & event log
  14855. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14856. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  14857. targetYear = tmStart.tm_year;
  14858. targetMonth = tmStart.tm_mon;
  14859. do
  14860. {
  14861. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14862. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  14863. if(targetMonth+1>=13)
  14864. {
  14865. targetYear += 1;
  14866. targetMonth = 1;
  14867. }
  14868. else
  14869. {
  14870. targetMonth += 1;
  14871. }
  14872. }while((targetYear < (tmNow->tm_year+1900)) ||
  14873. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14874. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  14875. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  14876. system(cmdBuf);
  14877. // Combine log file
  14878. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  14879. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  14880. }
  14881. else
  14882. {
  14883. system("exec /root/logPackTools 'log' 6");
  14884. }
  14885. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetLog.Response_filename);
  14886. system(cmdBuf);
  14887. checkUploadLog();
  14888. //****************location*******************/
  14889. if(strcmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"")==0)
  14890. {
  14891. DEBUG_INFO("location is <Empty>!\n");
  14892. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14893. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14894. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14895. goto end;
  14896. }
  14897. memset(protocol, 0, ARRAY_SIZE(protocol));
  14898. memset(user, 0, ARRAY_SIZE(user) );
  14899. memset(password, 0, ARRAY_SIZE(password));
  14900. memset(host, 0, ARRAY_SIZE(host));
  14901. memset(path, 0, ARRAY_SIZE(path));
  14902. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14903. memset(host1, 0, ARRAY_SIZE(host1));
  14904. memset(path1, 0, ARRAY_SIZE(path1));
  14905. /*location: ftp://user:password@host:port/path*/
  14906. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  14907. if((access(fnamePlusPath,F_OK))!=-1)
  14908. {
  14909. DEBUG_INFO("fnamePlusPath exist.\n");
  14910. }
  14911. else
  14912. {
  14913. DEBUG_INFO("fnamePlusPath not exist!\n");
  14914. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14915. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14916. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14917. goto end;
  14918. }
  14919. if(strchr((char*)ShmOCPP16Data->GetLog.log.remoteLocation,'@')==NULL)
  14920. {
  14921. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,
  14922. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14923. protocol, host, &port, path);
  14924. strcpy(user,"anonymous");
  14925. strcpy(password,"");
  14926. }
  14927. else
  14928. {
  14929. //DEBUG_INFO("pch=%s\n", pch);
  14930. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14931. protocol, user, password, host, &port, path);
  14932. }
  14933. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  14934. {
  14935. DEBUG_INFO("protocol is not ftp/http ! \n");
  14936. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14937. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14938. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14939. goto end;
  14940. }
  14941. if(strncmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"http", 4) == 0)
  14942. {
  14943. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14944. sprintf(ftppath,"/%s", path);
  14945. do
  14946. {
  14947. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14948. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14949. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14950. sleep(3);
  14951. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, (char*)ShmOCPP16Data->GetLog.log.remoteLocation);
  14952. if(!isSuccess)
  14953. {
  14954. DEBUG_INFO("Diagnostics fail.\n");
  14955. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14956. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14957. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14958. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14959. }
  14960. else
  14961. {
  14962. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14963. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14964. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14965. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14966. }
  14967. ShmOCPP16Data->GetLog.retries--;
  14968. }while((isSuccess == 0)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14969. }
  14970. else
  14971. {
  14972. sscanf(host,"%[^/]%s",host1, path1);
  14973. if(strlen(path) > 0)
  14974. sprintf(ftppath,"/%s", path);
  14975. else
  14976. sprintf(ftppath,"/%s", path1);
  14977. int ftppathlen=strlen(ftppath);
  14978. int i=1;
  14979. char filenametemp[50];
  14980. while(i < ftppathlen)
  14981. {
  14982. int len=ftppathlen-i;
  14983. if(ftppath[len]== 47) // '/' ascll code: 47
  14984. {
  14985. DEBUG_INFO("find '/' all right\n");
  14986. break;
  14987. }
  14988. i=i+1;
  14989. }
  14990. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14991. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  14992. filenametemp[i+1] = 0;
  14993. if(port == 0)
  14994. port = 21;
  14995. do
  14996. {
  14997. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14998. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14999. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  15000. sleep(3);
  15001. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  15002. if(!isSuccess)
  15003. {
  15004. DEBUG_INFO("Diagnostics fail.\n");
  15005. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  15006. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  15007. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  15008. sleep(ShmOCPP16Data->GetLog.retryInterval);
  15009. }
  15010. else
  15011. {
  15012. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  15013. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  15014. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  15015. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  15016. }
  15017. ShmOCPP16Data->GetLog.retries--;
  15018. }while((!isSuccess)&&(ShmOCPP16Data->GetLog.retries >= 0));
  15019. }
  15020. end:
  15021. system("rm -f /mnt/*");
  15022. sleep(5);
  15023. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  15024. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Idle");
  15025. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  15026. interLock.isGetDiagnosticGoing = 0;
  15027. pthread_exit(NULL);
  15028. }
  15029. int handleGetLogRequest(char *uuid, char *payload)
  15030. {
  15031. mtrace();
  15032. int result = PASS;
  15033. time_t CurrentTime;
  15034. struct tm *tm;
  15035. DEBUG_INFO("handleGetLogRequest...\n");
  15036. pthread_t th_Status;
  15037. CurrentTime = time(NULL);
  15038. tm = localtime(&CurrentTime);
  15039. memset(ShmOCPP16Data->GetLog.Response_filename, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetLog.Response_filename));
  15040. 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);
  15041. if(!interLock.isGetDiagnosticGoing)
  15042. {
  15043. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Accepted");
  15044. interLock.isGetDiagnosticGoing = 1;
  15045. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  15046. sleep(1);
  15047. }
  15048. else
  15049. {
  15050. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  15051. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  15052. }
  15053. sendGetLogConfirmation(uuid);
  15054. return result;
  15055. }
  15056. int handleInstallCertificateRequest(char *uuid, char *payload)
  15057. {
  15058. mtrace();
  15059. int result = PASS;
  15060. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  15061. json_object *InstallCertificate;
  15062. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  15063. DEBUG_INFO("handleInstallCertificateRequest...\n");
  15064. InstallCertificate = json_tokener_parse(payload);
  15065. if(!is_error(InstallCertificate))
  15066. {
  15067. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  15068. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  15069. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  15070. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  15071. char temp[1024];
  15072. FILE *fp = fopen(tempCert, "w");
  15073. fprintf(fp, "%s", ShmOCPP16Data->InstallCertificate.certificate);
  15074. fclose(fp);
  15075. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  15076. char strExpDate[30];
  15077. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  15078. fp = popen(temp, "r");
  15079. if(fp)
  15080. {
  15081. while(fgets(temp, sizeof(temp), fp) != NULL)
  15082. {
  15083. if(strstr(temp, "notAfter=") != NULL)
  15084. {
  15085. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  15086. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  15087. break;
  15088. }
  15089. }
  15090. }
  15091. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  15092. struct tm tmExpDate;
  15093. struct timeb tbExpDate;
  15094. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  15095. tbExpDate.time = mktime(&tmExpDate);
  15096. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  15097. {
  15098. DEBUG_INFO("The enddate is already expired...\n");
  15099. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  15100. goto End;
  15101. }
  15102. // Verify certificate with rootCA
  15103. sprintf(temp ,"openssl verify -CAfile /root/cacert.pem /Storage/OCPP/tempInstallCertificate.pem");
  15104. fp = popen(temp, "r");
  15105. if(fp)
  15106. {
  15107. while(fgets(temp, sizeof(temp), fp) != NULL)
  15108. {
  15109. if((strstr(temp, "tempInstallCertificate.pem: OK") != NULL) || (strstr(temp, "self signed certificate") != NULL))
  15110. {
  15111. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  15112. break;
  15113. }
  15114. else
  15115. {
  15116. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  15117. }
  15118. }
  15119. }
  15120. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  15121. {
  15122. //=====================================================
  15123. // Verify if the certificate is valid or not. (OCSP?)
  15124. //=====================================================
  15125. /*
  15126. DEBUG_INFO("openssl CA verifying...FAIL --> Start OCSP process...\n");
  15127. // Get ocsp url
  15128. char ocspUrl[512];
  15129. sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", tempCert);
  15130. fp = popen(temp, "r");
  15131. if(fp)
  15132. {
  15133. while(fgets(temp, sizeof(temp), fp) != NULL)
  15134. {
  15135. if(strstr(temp, "://") != NULL)
  15136. {
  15137. strcpy(ocspUrl, temp);
  15138. break;
  15139. }
  15140. }
  15141. }
  15142. // Get certificate chain for issuer
  15143. * openssl s_client -connect [serverURL:port] -showcerts | sed -n '/-----BEGIN/,/-------END/p' > tempChain.pem
  15144. *
  15145. // Execute OCSP
  15146. sprintf(temp ,"openssl ocsp -issuer tempChain.pem -cert /Storage/OCPP/tempInstallCertificate.pem -text -url %s", ocspUrl);
  15147. fp = popen(temp, "r");
  15148. if(fp)
  15149. {
  15150. while(fgets(temp, sizeof(temp), fp) != NULL)
  15151. {
  15152. if(strstr(temp, "tempInstallCertificate.pem: good") != NULL)
  15153. {
  15154. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  15155. break;
  15156. }
  15157. }
  15158. }
  15159. system("rm -f /Storage/OCPP/tempChain.pem");
  15160. pclose(fp);
  15161. */
  15162. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  15163. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  15164. {
  15165. DEBUG_INFO("OCSP verifying...FAIL.\n");
  15166. goto End;
  15167. }
  15168. else
  15169. DEBUG_INFO("OCSP verifying...PASS.\n");
  15170. }
  15171. else
  15172. DEBUG_INFO("openssl CA verifying...PASS.\n");
  15173. }
  15174. End:
  15175. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") == 0)
  15176. {
  15177. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "CentralSystemRootCertificate") == 0)
  15178. {
  15179. if(access(ROOTCA_CS,F_OK) != -1)
  15180. {
  15181. DEBUG_INFO("Existed CentralSystemRootCertificate is found. Replacing...\n");
  15182. rename(ROOTCA_CS, "/Storage/OCPP/CentralSystemRootCertificate_fallback.pem");
  15183. rename(tempCert, ROOTCA_CS);
  15184. }
  15185. else
  15186. {
  15187. DEBUG_INFO("No existed CentralSystemRootCertificate. Creating...\n");
  15188. rename(tempCert, ROOTCA_CS);
  15189. }
  15190. }
  15191. else if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "ManufacturerRootCertificate") == 0)
  15192. {
  15193. if(access(ROOTCA_MFG,F_OK) != -1)
  15194. {
  15195. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  15196. rename(ROOTCA_MFG, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  15197. rename(tempCert, ROOTCA_MFG);
  15198. }
  15199. else
  15200. {
  15201. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  15202. rename(tempCert, ROOTCA_MFG);
  15203. }
  15204. }
  15205. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  15206. }
  15207. sendInstallCertificateConfirmation(uuid);
  15208. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  15209. {
  15210. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidCentralSystemCertificate");
  15211. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  15212. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  15213. }
  15214. json_object_put(InstallCertificate);
  15215. return result;
  15216. }
  15217. void *SignedUpdateFirmwareProcess(void *data)
  15218. {
  15219. pthread_detach(pthread_self());
  15220. mtrace();
  15221. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  15222. int port=0;
  15223. int isSuccess = 0;
  15224. char ftpbuf[1024];
  15225. char temp[1024];
  15226. char * pch;
  15227. char firmwareFileName[50];
  15228. DEBUG_INFO("SignedUpdateFirmwareProcess ...\n");
  15229. json_object *SignedUpdateFirmware;
  15230. SignedUpdateFirmware = json_tokener_parse(data);
  15231. if(!is_error(SignedUpdateFirmware))
  15232. {
  15233. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  15234. {
  15235. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  15236. }
  15237. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  15238. {
  15239. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  15240. }
  15241. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  15242. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  15243. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  15244. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  15245. {
  15246. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  15247. }
  15248. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  15249. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  15250. }
  15251. json_object_put(SignedUpdateFirmware);
  15252. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  15253. memset(path, 0, ARRAY_SIZE(path));
  15254. // Wait retrieveData
  15255. if(strlen((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location) > 10)
  15256. {
  15257. do
  15258. {
  15259. sleep(1);
  15260. }while(!isOvertNow((uint8_t*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime));
  15261. }
  15262. // Ready to download
  15263. system("rm -f /mnt/*");
  15264. if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"http", 4) == 0)
  15265. {
  15266. sscanf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  15267. sprintf(ftppath,"/%s", path);
  15268. DEBUG_INFO("locationstr: %s\n", (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15269. DEBUG_INFO("protocol: %s\n",protocol);
  15270. DEBUG_INFO("host: %s\n",host);
  15271. DEBUG_INFO("path: %s\n",path);
  15272. DEBUG_INFO("ftppath: %s\n",ftppath);
  15273. int ftppathlen=strlen(ftppath);
  15274. int i=1;
  15275. while(i < ftppathlen)
  15276. {
  15277. int len=ftppathlen-i;
  15278. if(ftppath[len]== 47) // '/' ascll code: 47
  15279. {
  15280. DEBUG_INFO("compare '/' all right\n");
  15281. break;
  15282. }
  15283. i=i+1;
  15284. }
  15285. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  15286. strncpy(firmwareFileName, ftppath+(ftppathlen-i+1), i+1);
  15287. firmwareFileName[i+1] = 0;
  15288. do
  15289. {
  15290. sleep(1);
  15291. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15292. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  15293. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15294. sleep(1);
  15295. isSuccess = httpDownLoadFile(host, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15296. if(!isSuccess)
  15297. {
  15298. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15299. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15300. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15301. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  15302. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15303. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15304. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15305. }
  15306. else
  15307. {
  15308. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15309. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  15310. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15311. }
  15312. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15313. }while((isSuccess == 0)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15314. }
  15315. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"sftp", 4) == 0) // sftp
  15316. {
  15317. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15318. memset(temp, 0, ARRAY_SIZE(temp));
  15319. //DEBUG_INFO("locationstr=%s\n",locationstr);
  15320. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15321. int ftppathlen=strlen(ftpbuf);
  15322. int i=1;
  15323. while(i < ftppathlen)
  15324. {
  15325. int len=ftppathlen-i;
  15326. if(ftpbuf[len]== 47) // '/' ascii code: 47
  15327. {
  15328. DEBUG_INFO(" compare '/' all right\n");
  15329. break;
  15330. }
  15331. i=i+1;
  15332. }
  15333. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  15334. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  15335. firmwareFileName[i+1] = 0;
  15336. strncpy(temp, ftpbuf, ftppathlen-i+1);
  15337. pch=strchr(temp,'@');
  15338. if(pch==NULL)
  15339. {
  15340. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15341. protocol, host, &port, path);
  15342. strcpy(user,"anonymous");
  15343. strcpy(password,"");
  15344. }
  15345. else
  15346. {
  15347. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  15348. protocol, user, host, &port, path);
  15349. }
  15350. sscanf(host,"%[^/]%s",host1, path1);
  15351. sprintf(ftppath,"%s:/%s", host,path);
  15352. if(port == 0)
  15353. {
  15354. port = 21;
  15355. }
  15356. do
  15357. {
  15358. sleep(1);
  15359. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15360. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  15361. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15362. sleep(1);
  15363. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15364. if(!isSuccess)
  15365. {
  15366. sleep(1);
  15367. DEBUG_INFO("Update firmware request and download file fail.\n");
  15368. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15369. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15370. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15371. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  15372. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15373. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15374. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15375. }
  15376. else
  15377. {
  15378. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15379. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  15380. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15381. }
  15382. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15383. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15384. }
  15385. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"ftp", 3) == 0) // ftp
  15386. {
  15387. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15388. memset(temp, 0, ARRAY_SIZE(temp));
  15389. //DEBUG_INFO("locationstr=%s\n",locationstr);
  15390. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15391. int ftppathlen=strlen(ftpbuf);
  15392. int i=1;
  15393. while(i < ftppathlen)
  15394. {
  15395. int len=ftppathlen-i;
  15396. if(ftpbuf[len]== 47) // '/' ascll code: 47
  15397. {
  15398. DEBUG_INFO(" compare '/' all right\n");
  15399. break;
  15400. }
  15401. i=i+1;
  15402. }
  15403. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  15404. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  15405. firmwareFileName[i+1] = 0;
  15406. strncpy(temp, ftpbuf, ftppathlen-i+1);
  15407. pch=strchr(temp,'@');
  15408. if(pch==NULL)
  15409. {
  15410. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15411. protocol, host, &port, path);
  15412. strcpy(user,"anonymous");
  15413. strcpy(password,"");
  15414. }
  15415. else
  15416. {
  15417. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  15418. protocol, user, password, host, &port, path);
  15419. }
  15420. sscanf(host,"%[^/]%s",host1, path1);
  15421. sprintf(ftppath,"%s", path1);
  15422. //DEBUG_INFO("protocol =%s\n",protocol);
  15423. //DEBUG_INFO("user =%s\n",user);
  15424. //DEBUG_INFO("password =%s\n",password);
  15425. //DEBUG_INFO("host1 =%s\n",host1);
  15426. //DEBUG_INFO("port =%d\n",port);
  15427. //DEBUG_INFO("path1 =%s\n",path1);
  15428. //DEBUG_INFO("ftppath=%s\n",ftppath);
  15429. //ftpFile(host, user, password, port, ftppath, fname);
  15430. //download firmware pthred
  15431. if(port == 0)
  15432. {
  15433. port = 21;
  15434. }
  15435. do
  15436. {
  15437. sleep(1);
  15438. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15439. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  15440. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15441. sleep(1);
  15442. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15443. if(!isSuccess)
  15444. {
  15445. //BulldogUtil.sleepMs(interval*1000);
  15446. DEBUG_INFO("Update firmware request and download file fail.\n");
  15447. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15448. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15449. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15450. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  15451. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15452. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15453. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15454. }
  15455. else
  15456. {
  15457. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15458. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  15459. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15460. }
  15461. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15462. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15463. }
  15464. else
  15465. {
  15466. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15467. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15468. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15469. sleep(1);
  15470. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15471. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15472. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15473. }
  15474. // Verify firmware image signature
  15475. struct stat st;
  15476. FILE *fp = fopen("/tmp/signingFirmwareUpdate.crt", "w");
  15477. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  15478. fclose(fp);
  15479. system("openssl x509 -pubkey -noout -in /tmp/signingFirmwareUpdate.crt > /tmp/signingFirmwareUpdate.key");
  15480. fp = fopen("/tmp/signingFirmwareUpdate.sign", "w");
  15481. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  15482. fclose(fp);
  15483. system("openssl base64 -d -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15484. stat("/tmp/signingFirmwareUpdate.sign.256", &st);
  15485. if(st.st_size == 0)
  15486. system("openssl base64 -d -A -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15487. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "Downloaded") != NULL)
  15488. {
  15489. sprintf(temp ,"openssl dgst -verify /tmp/signingFirmwareUpdate.key -signature /tmp/signingFirmwareUpdate.sign.256 /mnt/%s", firmwareFileName);
  15490. fp = popen(temp, "r");
  15491. if(fp)
  15492. {
  15493. while(fgets(temp, sizeof(temp), fp) != NULL)
  15494. {
  15495. if(strstr(temp, "Verified OK") != NULL)
  15496. {
  15497. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15498. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "SignatureVerified");
  15499. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15500. }
  15501. else
  15502. {
  15503. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15504. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InvalidSignature");
  15505. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15506. sleep(1);
  15507. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15508. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InstallationFailed");
  15509. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15510. sleep(1);
  15511. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15512. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15513. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15514. }
  15515. break;
  15516. }
  15517. }
  15518. pclose(fp);
  15519. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "SignatureVerified") != NULL)ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  15520. }
  15521. interLock.isUpdateFirmwareGoing = 0;
  15522. pthread_exit(NULL);
  15523. }
  15524. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  15525. {
  15526. mtrace();
  15527. int result = PASS;
  15528. pthread_t t;
  15529. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  15530. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Accepted");
  15531. sendSignedUpdateFirmwareConfirmation(uuid);
  15532. if(!interLock.isUpdateFirmwareGoing)
  15533. {
  15534. interLock.isUpdateFirmwareGoing = 1;
  15535. pthread_create(&t, NULL, SignedUpdateFirmwareProcess, payload);
  15536. sleep(1);
  15537. }
  15538. else
  15539. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  15540. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareConf = 1;
  15541. return result;
  15542. }
  15543. int handleUnknownRequest(char *uuid, char *payload)
  15544. {
  15545. mtrace();
  15546. int result = PASS;
  15547. DEBUG_INFO("handleUnknownRequest...\n");
  15548. sendUnknownConfirmation(uuid);
  15549. return result;
  15550. }
  15551. //==========================================
  15552. // Handle server response routine
  15553. //==========================================
  15554. void handleAuthorizeResponse(char *payload, int gun_index)
  15555. {
  15556. mtrace();
  15557. char expiryDatestr[36]={0};
  15558. char parentIdTagstr[21]={0};
  15559. char statusstr[20]={0};
  15560. int expiryDateISNULL=FALSE;
  15561. int parentIdTagISNULL=FALSE;
  15562. DEBUG_INFO("handleAuthorizeResponse...\n");
  15563. json_object *Authorize;
  15564. Authorize = json_tokener_parse(payload);
  15565. if(!is_error(Authorize))
  15566. {
  15567. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  15568. {
  15569. // Required data
  15570. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  15571. // Optional data
  15572. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  15573. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  15574. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  15575. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  15576. }
  15577. }
  15578. json_object_put(Authorize);
  15579. if(expiryDateISNULL == FALSE)
  15580. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  15581. if(parentIdTagISNULL == FALSE)
  15582. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  15583. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  15584. //Update idTag information to authorization cache if supproted
  15585. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  15586. {
  15587. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  15588. }
  15589. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  15590. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  15591. authorizeRetryTimes = 0;
  15592. }
  15593. void handleBootNotificationResponse(char *payload, int gun_index)
  15594. {
  15595. mtrace();
  15596. char statusStr[12]={0};
  15597. char currentTimeStr[30]={0};
  15598. int intervalInt = 0;
  15599. DEBUG_INFO("handleBootNotificationResponse...\n");
  15600. json_object *BootNotification;
  15601. BootNotification = json_tokener_parse(payload);
  15602. if(!is_error(BootNotification))
  15603. {
  15604. // Required data
  15605. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  15606. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  15607. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  15608. }
  15609. json_object_put(BootNotification);
  15610. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15611. BootNotificationInterval = intervalInt;
  15612. //write back to ShmOCPP16Data->BootNotification
  15613. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  15614. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15615. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  15616. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  15617. {
  15618. BootNotificationInterval = 0;
  15619. if((intervalInt == 0) || (intervalInt >= 10))
  15620. {
  15621. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  15622. HeartBeatWaitTime = intervalInt;
  15623. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  15624. }
  15625. server_sign = TRUE;
  15626. server_pending =FALSE;
  15627. }
  15628. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  15629. {
  15630. server_pending = TRUE;
  15631. }
  15632. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  15633. srand(time(NULL));
  15634. refreshStartTimer(&clientTime.Heartbeat);
  15635. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  15636. SetOcppConnStatus(TRUE);
  15637. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  15638. }
  15639. void handleDataTransferResponse(char *payload, int gun_index)
  15640. {
  15641. json_object *DataTransfer = json_tokener_parse(payload);
  15642. DEBUG_INFO("Corresponding gun-%d MessageId: %s\n", gun_index, ShmOCPP16Data->DataTransfer[gun_index].MessageId);
  15643. if(!is_error(DataTransfer))
  15644. {
  15645. // Required data
  15646. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  15647. // Optional data
  15648. if(json_object_object_get(DataTransfer, "data") != NULL)
  15649. {
  15650. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15651. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15652. if(!is_error(Data))
  15653. {
  15654. if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Authorize") != NULL)
  15655. {
  15656. if(json_object_object_get(Data, "certificateStatus") != NULL)
  15657. {
  15658. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "%s", json_object_get_string(json_object_object_get(Data, "certificateStatus")));
  15659. }
  15660. if(json_object_object_get(Data, "idTokenInfo") != NULL)
  15661. {
  15662. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "status") != NULL)
  15663. {
  15664. 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")));
  15665. }
  15666. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "cacheExpiryDateTime") != NULL)
  15667. {
  15668. 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")));
  15669. }
  15670. }
  15671. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  15672. }
  15673. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Get15118EVCertificate") != NULL)
  15674. {
  15675. if(json_object_object_get(Data, "status") != NULL)
  15676. {
  15677. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15678. }
  15679. if(json_object_object_get(Data, "exiResponse") != NULL)
  15680. {
  15681. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_exiResponse, "%s", json_object_get_string(json_object_object_get(Data, "exiResponse")));
  15682. }
  15683. ShmOCPP16Data->v2g_extend.Get15118EVCertificateConf = 1;
  15684. }
  15685. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "GetCertificateStatus") != NULL)
  15686. {
  15687. if(json_object_object_get(Data, "status") != NULL)
  15688. {
  15689. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15690. }
  15691. if(json_object_object_get(Data, "ocspResult") != NULL)
  15692. {
  15693. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_ocspResult, "%s", json_object_get_string(json_object_object_get(Data, "ocspResult")));
  15694. }
  15695. ShmOCPP16Data->v2g_extend.GetCertificateStatusConf = 1;
  15696. }
  15697. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "SignCertificate") != NULL)
  15698. {
  15699. sprintf((char*)ShmOCPP16Data->v2g_extend.SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15700. ShmOCPP16Data->v2g_extend.SignCertificateConf = 1;
  15701. }
  15702. else
  15703. {
  15704. if(json_object_object_get(Data, "msgId") != NULL)
  15705. {
  15706. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  15707. {
  15708. 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")));
  15709. }
  15710. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  15711. {
  15712. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15713. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  15714. }
  15715. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_GetOccupancyFee") != NULL)
  15716. {
  15717. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15718. {
  15719. if(json_object_object_get(Data, "occupancySN") != NULL)
  15720. 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")));
  15721. if(json_object_object_get(Data, "startTime") != NULL)
  15722. 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")));
  15723. if(json_object_object_get(Data, "duration") != NULL)
  15724. 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"));
  15725. if(json_object_object_get(Data, "occupancyFee") != NULL)
  15726. 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"));
  15727. }
  15728. ShmOCPP16Data->TcciCustomData.GetOccupancyFee[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].GetOccupancyFeeReq = 0;
  15729. }
  15730. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_OccupancyDeductResult") != NULL)
  15731. {
  15732. if(json_object_object_get(Data, "occupancySN") != NULL)
  15733. OCPP_update_occupancyDeduct_info((char*)json_object_get_string(json_object_object_get(Data, "occupancySN")));
  15734. }
  15735. }
  15736. }
  15737. }
  15738. json_object_put(Data);
  15739. }
  15740. }
  15741. json_object_put(DataTransfer);
  15742. }
  15743. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  15744. {
  15745. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  15746. //struct json_object *obj;
  15747. // obj = json_tokener_parse(payload);
  15748. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  15749. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  15750. //No fields are defined.
  15751. }
  15752. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15753. {
  15754. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  15755. //struct json_object *obj;
  15756. // obj = json_tokener_parse(payload);
  15757. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  15758. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  15759. //No fields are defined.
  15760. }
  15761. void handleHeartbeatResponse(char *payload, int gun_index)
  15762. {
  15763. mtrace();
  15764. DEBUG_INFO("handleHeartbeatResponse...\n");
  15765. json_object *Heartbeat;
  15766. Heartbeat = json_tokener_parse(payload);
  15767. if(!is_error(Heartbeat))
  15768. {
  15769. // Required data
  15770. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  15771. }
  15772. json_object_put(Heartbeat);
  15773. if(FirstHeartBeat == 0)
  15774. {
  15775. FirstHeartBeat = 1;
  15776. DEBUG_INFO("FirstHeartBeat \n");
  15777. }
  15778. HeartBeatWithNOResponse = 0;
  15779. refreshStartTimer(&clientTime.Heartbeat);
  15780. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  15781. }
  15782. void handleMeterValuesResponse(char *payload, int gun_index)
  15783. {
  15784. mtrace();
  15785. DEBUG_INFO("handleMeterValuesResponse...\n");
  15786. isQueueSendable = 1;
  15787. }
  15788. void handleStartTransactionResponse(char *payload, int gun_index)
  15789. {
  15790. mtrace();
  15791. //int transactionIdInt = 0;
  15792. FILE *outfile;
  15793. char data[100]={0};
  15794. DEBUG_INFO("handleStartTransactionResponse...\n");
  15795. json_object *StartTransaction;
  15796. StartTransaction = json_tokener_parse(payload);
  15797. if(!is_error(StartTransaction))
  15798. {
  15799. // Required data
  15800. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  15801. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  15802. // Optional data
  15803. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  15804. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  15805. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15806. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  15807. }
  15808. json_object_put(StartTransaction);
  15809. OCPP_updatePeriodEnergy(gun_index);
  15810. //-----------Start : write to the Queue TransactionId file -----------------//
  15811. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  15812. {}
  15813. else
  15814. {
  15815. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  15816. if(log == NULL)
  15817. {
  15818. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  15819. return ;
  15820. }
  15821. else
  15822. {
  15823. fclose(log);
  15824. }
  15825. }
  15826. // open file for writing
  15827. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  15828. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  15829. {
  15830. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  15831. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  15832. fputs(data, outfile);
  15833. fclose (outfile);
  15834. }
  15835. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15836. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15837. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  15838. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  15839. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15840. isQueueSendable = 1;
  15841. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  15842. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  15843. }
  15844. void handleStatusNotificationResponse(char *payload, int gun_index)
  15845. {
  15846. mtrace();
  15847. DEBUG_INFO("handleStatusNotificationResponse...\n");
  15848. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15849. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15850. if(gun_index != 99)
  15851. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  15852. }
  15853. void handleStopTransactionnResponse(char *payload, int gun_index)
  15854. {
  15855. mtrace();
  15856. DEBUG_INFO("handleStopTransactionnResponse...\n");
  15857. json_object *StopTransaction;
  15858. StopTransaction = json_tokener_parse(payload);
  15859. if(!is_error(StopTransaction))
  15860. {
  15861. // Optional data
  15862. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  15863. {
  15864. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  15865. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  15866. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  15867. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15868. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  15869. }
  15870. }
  15871. json_object_put(StopTransaction);
  15872. isQueueSendable = 1;
  15873. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  15874. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  15875. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15876. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15877. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  15878. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  15879. }
  15880. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  15881. {
  15882. mtrace();
  15883. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  15884. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  15885. }
  15886. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  15887. {
  15888. mtrace();
  15889. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  15890. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  15891. }
  15892. void handleSignCertificateResponse(char *payload, int gun_index)
  15893. {
  15894. mtrace();
  15895. DEBUG_INFO("handleSignCertificateResponse...\n");
  15896. json_object *SignCertificate;
  15897. SignCertificate = json_tokener_parse(payload);
  15898. if(!is_error(SignCertificate))
  15899. {
  15900. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  15901. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  15902. }
  15903. json_object_put(SignCertificate);
  15904. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  15905. }
  15906. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15907. {
  15908. mtrace();
  15909. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  15910. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  15911. }
  15912. //==========================================
  15913. // Handle Error routine
  15914. //==========================================
  15915. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  15916. {
  15917. mtrace();
  15918. #ifdef SystemLogMessage
  15919. DEBUG_INFO("errorCode: %s\n", errorCode);
  15920. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  15921. DEBUG_INFO("errorDetails: %s\n", payload);
  15922. #endif
  15923. }
  15924. //===============================================
  15925. // Common routine
  15926. //===============================================
  15927. int initialConfigurationTable(void)
  15928. {
  15929. //clock_t start_t, end_t, total_t;
  15930. FILE *fp;
  15931. FILE *outfile;
  15932. char str[512]={0};
  15933. char sstr[256]={0};
  15934. int c = 0;
  15935. char *loc;
  15936. int confVersion = 21;
  15937. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  15938. //start_t = clock();
  15939. //printf("Starting of the program, start_t = %ld\n", start_t);
  15940. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  15941. // Check configuration file size is correct
  15942. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  15943. {
  15944. struct stat st;
  15945. stat("/Storage/OCPP/OCPPConfiguration", &st);
  15946. if(st.st_size < 3100)
  15947. {
  15948. system("rm -f /Storage/OCPP/OCPPConfiguration");
  15949. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  15950. }
  15951. }
  15952. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  15953. {
  15954. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15955. if(outfile == NULL)
  15956. {
  15957. DEBUG_INFO("Error opening file\n");
  15958. return FALSE;
  15959. }
  15960. /*Core Profile*/
  15961. //AllowOfflineTxForUnknownId
  15962. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  15965. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15966. //AuthorizationCacheEnabled
  15967. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15970. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15971. //AuthorizeRemoteTxRequests
  15972. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  15973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15974. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  15975. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15976. //BlinkRepeat
  15977. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15980. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15981. //ClockAlignedDataInterval
  15982. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15985. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15986. //ConnectionTimeOut
  15987. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15989. if(ShmSysConfigAndInfo->SysConfig.ModelName[3]=='J')
  15990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "55" );
  15991. else
  15992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15993. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15994. //GetConfigurationMaxKeys
  15995. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15997. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  15998. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15999. // HeartbeatInterval
  16000. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  16001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  16002. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  16003. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  16004. // LightIntensity
  16005. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  16006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  16007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  16008. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  16009. // LocalAuthorizeOffline
  16010. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  16011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  16012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  16013. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16014. // LocalPreAuthorize
  16015. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  16016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  16017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  16018. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  16019. // MaxEnergyOnInvalidId
  16020. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  16021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  16022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  16023. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  16024. // MeterValuesAlignedData
  16025. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  16026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  16027. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16028. 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" );
  16029. else
  16030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  16031. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  16032. // MeterValuesAlignedDataMaxLength
  16033. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  16034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  16035. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  16037. else
  16038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  16039. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  16040. // MeterValuesSampledData
  16041. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  16042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  16043. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16044. 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" );
  16045. else
  16046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  16047. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  16048. // MeterValuesSampledDataMaxLength
  16049. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  16050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  16051. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  16053. else
  16054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  16055. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  16056. // MeterValueSampleInterval
  16057. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  16058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  16059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  16060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  16061. // MinimumStatusDuration
  16062. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  16063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  16064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  16065. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  16066. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16067. // NumberOfConnectors
  16068. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  16069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  16070. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16071. {
  16072. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  16073. }
  16074. else
  16075. {
  16076. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  16077. }
  16078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  16079. // ResetRetries
  16080. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  16081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  16082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  16083. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  16084. // ConnectorPhaseRotation
  16085. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  16086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  16087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  16088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  16089. // ConnectorPhaseRotationMaxLength
  16090. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  16091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  16092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  16093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  16094. // StopTransactionOnEVSideDisconnect
  16095. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  16096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  16097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  16098. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  16099. // StopTransactionOnInvalidId
  16100. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  16101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  16102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  16103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  16104. // StopTxnAlignedData
  16105. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  16106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  16107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  16108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  16109. // StopTxnAlignedDataMaxLength
  16110. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  16111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  16112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  16113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  16114. // StopTxnSampledData
  16115. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  16116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  16117. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  16119. else
  16120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  16121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  16122. // StopTxnSampledDataMaxLength
  16123. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  16124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  16125. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16126. {
  16127. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  16128. }
  16129. else
  16130. {
  16131. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  16132. }
  16133. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  16134. // SupportedFeatureProfiles
  16135. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  16136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  16137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  16138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  16139. // SupportedFeatureProfilesMaxLength
  16140. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  16141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  16142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  16143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  16144. // TransactionMessageAttempts
  16145. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  16146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  16147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  16148. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16150. // TransactionMessageRetryInterval
  16151. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  16152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  16153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  16154. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16155. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16156. // UnlockConnectorOnEVSideDisconnect
  16157. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  16158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  16159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  16160. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  16161. // WebSocketPingInterval
  16162. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  16163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  16164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  16165. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16166. // QueueOffLineMeterValues
  16167. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  16168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  16169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  16170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  16171. // AuthorizationKey
  16172. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  16173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  16174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  16175. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16176. // SecurityProfile
  16177. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  16178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  16179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  16180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16181. // DefaultPrice
  16182. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  16183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  16184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  16185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16186. // CustomDisplayCostAndPrice
  16187. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  16188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  16189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  16190. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  16191. // CustomIdleFeeAfterStop
  16192. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  16193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  16194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  16195. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  16196. // TimeOffset
  16197. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  16198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  16199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  16200. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  16201. // NextTimeOffsetTransitionDateTime
  16202. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  16203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  16204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  16205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  16206. // TimeOffsetNextTransition
  16207. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  16208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  16209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  16210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  16211. // SystemUptimeSec
  16212. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  16213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  16214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  16215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  16216. // FreeVend
  16217. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  16218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  16219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  16220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  16221. // FreeVendIdtag
  16222. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  16223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  16224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  16225. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16226. // OcppServer
  16227. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  16228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  16229. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  16230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16231. // MaintainServer
  16232. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  16233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  16234. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  16235. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16236. // StatusNotificationPeriodically
  16237. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  16238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  16239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  16240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  16241. // StatusNotificationInterval
  16242. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  16243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  16244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  16245. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  16246. // PreAuthAmount
  16247. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  16248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  16249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  16250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  16251. // isEnableLocalPowerSharing
  16252. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  16253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  16254. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  16255. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  16256. // PowerSharingServerIP
  16257. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  16258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  16259. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  16260. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  16261. // EVCCID_PREFIX
  16262. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  16263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  16264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  16265. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  16266. // OffLineMaxChargingPower
  16267. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  16268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  16269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  16270. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  16271. // Configuration Version
  16272. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  16273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  16274. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  16275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  16276. // Charging profile refresh interval
  16277. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  16278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  16279. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  16280. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  16281. // CpoName
  16282. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  16283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  16284. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "Zerova");
  16285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  16286. // Ocpp Software certificated version
  16287. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  16288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  16289. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  16290. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  16291. //* Local Auth List Management Profile*/
  16292. #if 0
  16293. //For OCTT Test Case
  16294. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  16295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  16296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  16297. #endif
  16298. #if 1
  16299. //LocalAuthListEnabled
  16300. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  16301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  16302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  16303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16304. #endif
  16305. //LocalAuthListMaxLength
  16306. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  16307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  16308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  16309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  16310. //SendLocalListMaxLength
  16311. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  16312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  16313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  16314. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  16315. //ReserveConnectorZeroSupported
  16316. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  16317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  16318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  16319. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16320. //* Smart Charging Profile */
  16321. //ChargeProfileMaxStackLevel
  16322. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  16323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  16324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  16325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16326. // ChargingScheduleAllowedChargingRateUnit
  16327. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  16328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  16329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  16330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16331. // ChargingScheduleMaxPeriods
  16332. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  16333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  16334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  16335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16336. // ConnectorSwitch3to1PhaseSupported
  16337. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  16338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  16339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  16340. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16341. // MaxChargingProfilesInstalled
  16342. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  16343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  16344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  16345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16346. fclose(outfile);
  16347. }
  16348. else
  16349. {
  16350. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  16351. char keystr[60]={0};
  16352. char readonlystr[10]={0};
  16353. char valuestr[256]={0};
  16354. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  16355. if(fp == NULL) {
  16356. DEBUG_INFO("Error opening file");
  16357. return FALSE;
  16358. }
  16359. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  16360. {
  16361. //DEBUG_INFO("Get Configuration \n");
  16362. if(strlen(str) > 0)
  16363. {
  16364. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16365. //*************************key*********************************/
  16366. if(strstr(str, "key") != NULL)
  16367. {
  16368. loc = strstr(str, "key");
  16369. c = 0;
  16370. memset(sstr ,0, ARRAY_SIZE(sstr) );
  16371. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  16372. {
  16373. sstr[c] = loc[strlen("key")+3+c];
  16374. c++;
  16375. }
  16376. sstr[c] = '\0';
  16377. strcpy(keystr,sstr);
  16378. }
  16379. //*************************readonly*********************************/
  16380. if(strstr(str, "readonly") != NULL)
  16381. {
  16382. loc = strstr(str, "readonly");
  16383. c = 0;
  16384. memset(sstr ,0, ARRAY_SIZE(sstr) );
  16385. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  16386. {
  16387. sstr[c] = loc[strlen("readonly")+2+c];
  16388. c++;
  16389. }
  16390. sstr[c] = '\0';
  16391. strcpy(readonlystr,sstr);
  16392. }
  16393. //*************************value*********************************/
  16394. if(strstr(str, "value") != NULL)
  16395. {
  16396. loc = strstr(str, "value");
  16397. c = 0;
  16398. memset(sstr ,0, ARRAY_SIZE(sstr) );
  16399. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  16400. {
  16401. sstr[c] = loc[strlen("value")+3+c];
  16402. c++;
  16403. }
  16404. sstr[c] = '\0';
  16405. strcpy(valuestr,sstr);
  16406. }
  16407. // DEBUG_INFO("keystr=%s\n",keystr);
  16408. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  16409. // DEBUG_INFO("valuestr=%s\n",valuestr);
  16410. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  16411. {
  16412. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16413. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16414. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  16415. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  16416. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  16417. }
  16418. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  16419. {
  16420. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16421. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16422. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  16423. }
  16424. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  16425. {
  16426. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16427. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  16428. }
  16429. if(strcmp(keystr, "BlinkRepeat") == 0)
  16430. {
  16431. //Charger.BlinkRepeat = Integer.parseInt(value);
  16432. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16433. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  16434. }
  16435. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  16436. {
  16437. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16438. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  16439. }
  16440. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  16441. {
  16442. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16443. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  16444. }
  16445. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  16446. {
  16447. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16448. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  16449. }
  16450. if(strcmp(keystr, "HeartbeatInterval") == 0)
  16451. {
  16452. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16453. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  16454. HeartBeatWaitTime = atoi(valuestr);
  16455. }
  16456. if(strcmp(keystr, "LightIntensity") == 0)
  16457. {
  16458. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  16460. }
  16461. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  16462. {
  16463. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  16465. }
  16466. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  16467. {
  16468. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  16470. }
  16471. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  16472. {
  16473. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  16475. }
  16476. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  16477. {
  16478. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16479. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  16480. }
  16481. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  16482. {
  16483. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16484. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  16485. }
  16486. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  16487. {
  16488. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  16490. }
  16491. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  16492. {
  16493. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16494. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  16495. }
  16496. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  16497. {
  16498. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16499. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  16500. }
  16501. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  16502. {
  16503. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  16505. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  16506. }
  16507. if(strcmp(keystr, "NumberOfConnectors") == 0)
  16508. {
  16509. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16510. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  16511. }
  16512. if(strcmp(keystr, "ResetRetries") == 0)
  16513. {
  16514. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16515. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  16516. }
  16517. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  16518. {
  16519. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  16521. }
  16522. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  16523. {
  16524. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  16526. }
  16527. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  16528. {
  16529. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  16531. }
  16532. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  16533. {
  16534. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16535. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  16536. }
  16537. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  16538. {
  16539. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  16541. }
  16542. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  16543. {
  16544. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16545. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16546. }
  16547. if(strcmp(keystr, "StopTxnSampledData") == 0)
  16548. {
  16549. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16550. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  16551. }
  16552. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  16553. {
  16554. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16555. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16556. }
  16557. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  16558. {
  16559. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16560. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  16561. }
  16562. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  16563. {
  16564. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16565. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  16566. }
  16567. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  16568. {
  16569. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16570. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  16571. TransactionMessageAttemptsValue = atoi(valuestr);
  16572. }
  16573. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  16574. {
  16575. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16576. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  16577. TransactionMessageRetryIntervalValue = atoi(valuestr);
  16578. }
  16579. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  16580. {
  16581. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16582. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  16583. }
  16584. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  16585. {
  16586. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  16588. }
  16589. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  16590. {
  16591. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16592. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  16593. }
  16594. if(strcmp(keystr, "AuthorizationKey") == 0)
  16595. {
  16596. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16597. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  16598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  16599. }
  16600. if(strcmp(keystr, "SecurityProfile") == 0)
  16601. {
  16602. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16603. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  16604. }
  16605. if(strcmp(keystr, "DefaultPrice") == 0)
  16606. {
  16607. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16608. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  16609. }
  16610. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  16611. {
  16612. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  16614. }
  16615. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  16616. {
  16617. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  16619. }
  16620. if(strcmp(keystr, "TimeOffset") == 0)
  16621. {
  16622. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  16624. }
  16625. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  16626. {
  16627. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16628. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  16629. }
  16630. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  16631. {
  16632. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16633. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  16634. }
  16635. if(strcmp(keystr, "SystemUptimeSec") == 0)
  16636. {
  16637. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16638. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  16639. }
  16640. if(strcmp(keystr, "FreeVend") == 0)
  16641. {
  16642. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16643. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  16644. }
  16645. if(strcmp(keystr, "FreeVendIdtag") == 0)
  16646. {
  16647. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16648. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  16649. }
  16650. if(strcmp(keystr, "OcppServer") == 0)
  16651. {
  16652. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16653. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  16654. }
  16655. if(strcmp(keystr, "MaintainServer") == 0)
  16656. {
  16657. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16658. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  16659. }
  16660. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  16661. {
  16662. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  16664. }
  16665. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  16666. {
  16667. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16668. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  16669. }
  16670. if(strcmp(keystr, "PreAuthAmount") == 0)
  16671. {
  16672. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16673. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  16674. }
  16675. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  16676. {
  16677. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  16679. }
  16680. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  16681. {
  16682. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16683. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  16684. }
  16685. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  16686. {
  16687. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  16689. }
  16690. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  16691. {
  16692. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16693. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  16694. }
  16695. if(strcmp(keystr, "ConfigurationVersion") == 0)
  16696. {
  16697. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16698. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  16699. }
  16700. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  16701. {
  16702. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  16704. }
  16705. if(strcmp(keystr, "CpoName") == 0)
  16706. {
  16707. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", valuestr);
  16709. }
  16710. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  16711. {
  16712. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  16714. }
  16715. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  16716. {
  16717. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16718. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  16719. }
  16720. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  16721. {
  16722. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  16724. }
  16725. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  16726. {
  16727. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16728. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  16729. }
  16730. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  16731. {
  16732. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16733. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  16734. }
  16735. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  16736. {
  16737. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16738. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  16739. }
  16740. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16741. {
  16742. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16743. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  16744. }
  16745. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  16746. {
  16747. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  16749. }
  16750. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  16751. {
  16752. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16753. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  16754. }
  16755. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  16756. {
  16757. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16758. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  16759. }
  16760. }
  16761. }
  16762. fclose(fp);
  16763. }
  16764. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  16765. {
  16766. return PASS;
  16767. }
  16768. else
  16769. {
  16770. return FAIL;
  16771. }
  16772. }
  16773. void StoreConfigurationTable(void)
  16774. {
  16775. FILE *outfile;
  16776. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  16777. if(outfile == NULL)
  16778. {
  16779. DEBUG_INFO("Error opening file");
  16780. return ;
  16781. }
  16782. /*Core Profile*/
  16783. //AllowOfflineTxForUnknownId
  16784. /*
  16785. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  16786. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  16787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  16788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  16789. */
  16790. //DEBUG_INFO("data=%s\n",data);
  16791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  16792. //AuthorizationCacheEnabled
  16793. /*
  16794. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  16795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  16796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  16797. */
  16798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  16799. //AuthorizeRemoteTxRequests
  16800. /*
  16801. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  16802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  16803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  16804. */
  16805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  16806. //BlinkRepeat
  16807. /*
  16808. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  16809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  16810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  16811. */
  16812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  16813. //ClockAlignedDataInterval
  16814. /*
  16815. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  16816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  16817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  16818. */
  16819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  16820. //ConnectionTimeOut
  16821. /*
  16822. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  16823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  16824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  16825. */
  16826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  16827. //GetConfigurationMaxKeys
  16828. /*
  16829. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  16830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  16831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  16832. */
  16833. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  16834. // HeartbeatInterval
  16835. /*
  16836. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  16837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  16838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  16839. */
  16840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  16841. // LightIntensity
  16842. /*
  16843. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  16844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  16845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  16846. */
  16847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  16848. // LocalAuthorizeOffline
  16849. /*
  16850. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  16851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  16852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  16853. */
  16854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16855. // LocalPreAuthorize
  16856. /*
  16857. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  16858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  16859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  16860. */
  16861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  16862. // MaxEnergyOnInvalidId
  16863. /*
  16864. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  16865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  16866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  16867. */
  16868. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  16869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  16870. // MeterValuesAlignedData
  16871. /*
  16872. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  16873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  16874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16875. */
  16876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  16877. // MeterValuesAlignedDataMaxLength
  16878. /*
  16879. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  16880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  16881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  16882. */
  16883. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  16884. // MeterValuesSampledData
  16885. /*
  16886. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  16887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  16888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16889. */
  16890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  16891. // MeterValuesSampledDataMaxLength
  16892. /*
  16893. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  16894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  16895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  16896. */
  16897. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  16898. // MeterValueSampleInterval
  16899. /*
  16900. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  16901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  16902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  16903. */
  16904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  16905. // MinimumStatusDuration
  16906. /*
  16907. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  16908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  16909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  16910. */
  16911. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16912. // NumberOfConnectors
  16913. /*
  16914. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  16915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  16916. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16917. {
  16918. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  16919. }
  16920. else
  16921. {
  16922. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  16923. }
  16924. */
  16925. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  16926. // ResetRetries
  16927. /*
  16928. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  16929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  16930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  16931. */
  16932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  16933. // ConnectorPhaseRotation
  16934. /*
  16935. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  16936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  16937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  16938. */
  16939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  16940. // ConnectorPhaseRotationMaxLength
  16941. /*
  16942. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  16943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  16944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  16945. */
  16946. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  16947. // StopTransactionOnEVSideDisconnect
  16948. /*
  16949. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  16950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  16951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  16952. */
  16953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  16954. // StopTransactionOnInvalidId
  16955. /*
  16956. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  16957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  16958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  16959. */
  16960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  16961. // StopTxnAlignedData
  16962. /*
  16963. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  16964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  16965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  16966. */
  16967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  16968. // StopTxnAlignedDataMaxLength
  16969. /*
  16970. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  16971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  16972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  16973. */
  16974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  16975. // StopTxnSampledData
  16976. /*
  16977. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  16978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  16979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  16980. */
  16981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  16982. // StopTxnSampledDataMaxLength
  16983. /*
  16984. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  16985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  16986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  16987. */
  16988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  16989. // SupportedFeatureProfiles
  16990. /*
  16991. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  16992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  16993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  16994. */
  16995. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  16996. // SupportedFeatureProfilesMaxLength
  16997. /*
  16998. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  16999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  17000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  17001. */
  17002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  17003. // TransactionMessageAttempts
  17004. /*
  17005. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  17006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  17007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  17008. */
  17009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  17010. // TransactionMessageRetryInterval
  17011. /*
  17012. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  17013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  17014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  17015. */
  17016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17017. // UnlockConnectorOnEVSideDisconnect
  17018. /*
  17019. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  17020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  17021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  17022. */
  17023. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  17024. // WebSocketPingInterval
  17025. /*
  17026. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  17027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  17028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  17029. */
  17030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17031. // QueueOffLineMeterValues
  17032. /*
  17033. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  17034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  17035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  17036. */
  17037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  17038. // AuthorizationKey
  17039. /*
  17040. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  17041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  17042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  17043. */
  17044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17045. // SecurityProfile
  17046. /*
  17047. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  17048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  17049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  17050. */
  17051. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17052. // DefaultPrice
  17053. /*
  17054. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  17055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  17056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  17057. */
  17058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  17059. // CustomDisplayCostAndPrice
  17060. /*
  17061. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  17062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  17063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  17064. */
  17065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  17066. // CustomIdleFeeAfterStop
  17067. /*
  17068. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  17069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  17070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  17071. */
  17072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  17073. // TimeOffset
  17074. /*
  17075. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  17076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  17077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  17078. */
  17079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  17080. // NextTimeOffsetTransitionDateTime
  17081. /*
  17082. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  17083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  17084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  17085. */
  17086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  17087. // TimeOffsetNextTransition
  17088. /*
  17089. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  17090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  17091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  17092. */
  17093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  17094. // SystemUptimeSec
  17095. /*
  17096. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  17097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  17098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  17099. */
  17100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  17101. // FreeVend
  17102. /*
  17103. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  17104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  17105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  17106. */
  17107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  17108. // FreeVendIdtag
  17109. /*
  17110. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  17111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  17112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  17113. */
  17114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  17115. // OcppServer
  17116. /*
  17117. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  17118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  17119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  17120. */
  17121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  17122. // MaintainServer
  17123. /*
  17124. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  17125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  17126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  17127. */
  17128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  17129. // StatusNotificationPeriodically
  17130. /*
  17131. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  17132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  17133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  17134. */
  17135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  17136. // StatusNotificationInterval
  17137. /*
  17138. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  17139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  17140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  17141. */
  17142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  17143. // PreAuthAmount
  17144. /*
  17145. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  17146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  17147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  17148. */
  17149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  17150. // isEnableLocalPowerSharing
  17151. /*
  17152. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  17153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  17154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  17155. */
  17156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  17157. // PowerSharingServerIP
  17158. /*
  17159. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  17160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  17161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  17162. */
  17163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  17164. // EVCCID_PREFIX
  17165. /*
  17166. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  17167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  17168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  17169. */
  17170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  17171. // OffLineMaxChargingPower
  17172. /*
  17173. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  17174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  17175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  17176. */
  17177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  17178. // ConfigurationVersion
  17179. /*
  17180. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  17181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  17182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  17183. */
  17184. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  17185. // CharingProfileRefreshInterval
  17186. /*
  17187. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  17188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  17189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  17190. */
  17191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  17192. // CpoName
  17193. /*
  17194. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  17195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  17196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "" );
  17197. */
  17198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  17199. // OcppSoftwareVersion
  17200. /*
  17201. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  17202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  17203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  17204. */
  17205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  17206. //* Local Auth List Management Profile*/
  17207. //LocalAuthListEnabled
  17208. /*
  17209. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  17210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  17211. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  17212. */
  17213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  17214. //LocalAuthListMaxLength
  17215. /*
  17216. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  17217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  17218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  17219. */
  17220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  17221. //SendLocalListMaxLength
  17222. /*
  17223. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  17224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  17225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  17226. */
  17227. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  17228. //ReserveConnectorZeroSupported
  17229. /*
  17230. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  17231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  17232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  17233. */
  17234. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  17235. //* Smart Charging Profile */
  17236. //ChargeProfileMaxStackLevel
  17237. /*
  17238. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  17239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  17240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  17241. */
  17242. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  17243. // ChargingScheduleAllowedChargingRateUnit
  17244. /*
  17245. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  17246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  17247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  17248. */
  17249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  17250. // ChargingScheduleMaxPeriods
  17251. /*
  17252. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  17253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  17254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  17255. */
  17256. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  17257. // ConnectorSwitch3to1PhaseSupported
  17258. /*
  17259. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  17260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  17261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  17262. */
  17263. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  17264. // MaxChargingProfilesInstalled
  17265. /*
  17266. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  17267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  17268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  17269. */
  17270. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  17271. fclose(outfile);
  17272. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17273. }
  17274. void getKeyValue(char *keyReq)
  17275. {
  17276. int isEmpty = FALSE;
  17277. int isKnowKey = FALSE;
  17278. DEBUG_INFO("keyReq = %s\n", keyReq);
  17279. if((keyReq == NULL) || (strlen(keyReq) == 0))
  17280. isEmpty = TRUE;
  17281. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  17282. {
  17283. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  17284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  17285. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  17286. {
  17287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  17288. }
  17289. else
  17290. {
  17291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  17292. }
  17293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  17294. isKnowKey = TRUE;
  17295. }
  17296. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  17297. {
  17298. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  17299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  17300. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  17301. {
  17302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  17303. }
  17304. else
  17305. {
  17306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  17307. }
  17308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  17309. isKnowKey = TRUE;
  17310. }
  17311. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  17312. {
  17313. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  17314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  17315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  17316. {
  17317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  17318. }
  17319. else
  17320. {
  17321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  17322. }
  17323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  17324. isKnowKey = TRUE;
  17325. }
  17326. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  17327. {
  17328. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  17329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  17330. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  17331. {
  17332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  17333. }
  17334. else
  17335. {
  17336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  17337. }
  17338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  17339. isKnowKey = TRUE;
  17340. }
  17341. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  17342. {
  17343. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  17344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  17345. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  17346. {
  17347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  17348. }
  17349. else
  17350. {
  17351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  17352. }
  17353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  17354. isKnowKey = TRUE;
  17355. }
  17356. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  17357. {
  17358. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  17359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  17360. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  17361. {
  17362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  17363. }
  17364. else
  17365. {
  17366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  17367. }
  17368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  17369. isKnowKey = TRUE;
  17370. }
  17371. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  17372. {
  17373. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  17374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  17375. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  17376. {
  17377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  17378. }
  17379. else
  17380. {
  17381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  17382. }
  17383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  17384. isKnowKey = TRUE;
  17385. }
  17386. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  17387. {
  17388. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  17389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  17390. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  17391. {
  17392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  17393. }
  17394. else
  17395. {
  17396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  17397. }
  17398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  17399. isKnowKey = TRUE;
  17400. }
  17401. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  17402. {
  17403. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  17404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  17405. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  17406. {
  17407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  17408. }
  17409. else
  17410. {
  17411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  17412. }
  17413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  17414. isKnowKey = TRUE;
  17415. }
  17416. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  17417. {
  17418. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  17419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  17420. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  17421. {
  17422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  17423. }
  17424. else
  17425. {
  17426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  17427. }
  17428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  17429. isKnowKey = TRUE;
  17430. }
  17431. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  17432. {
  17433. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  17434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  17435. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  17436. {
  17437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  17438. }
  17439. else
  17440. {
  17441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  17442. }
  17443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  17444. isKnowKey = TRUE;
  17445. }
  17446. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  17447. {
  17448. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  17449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  17450. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  17451. {
  17452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17453. }
  17454. else
  17455. {
  17456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17457. }
  17458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  17459. isKnowKey = TRUE;
  17460. }
  17461. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  17462. {
  17463. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  17464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  17465. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  17466. {
  17467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17468. }
  17469. else
  17470. {
  17471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17472. }
  17473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  17474. isKnowKey = TRUE;
  17475. }
  17476. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  17477. {
  17478. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  17479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  17480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  17481. {
  17482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17483. }
  17484. else
  17485. {
  17486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17487. }
  17488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  17489. isKnowKey = TRUE;
  17490. }
  17491. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  17492. {
  17493. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  17494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  17495. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  17496. {
  17497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  17498. }
  17499. else
  17500. {
  17501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  17502. }
  17503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  17504. isKnowKey = TRUE;
  17505. }
  17506. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  17507. {
  17508. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  17509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  17510. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  17511. {
  17512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17513. }
  17514. else
  17515. {
  17516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17517. }
  17518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  17519. isKnowKey = TRUE;
  17520. }
  17521. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  17522. {
  17523. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  17524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  17525. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  17526. {
  17527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  17528. }
  17529. else
  17530. {
  17531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  17532. }
  17533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  17534. isKnowKey = TRUE;
  17535. }
  17536. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  17537. {
  17538. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  17539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  17540. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  17541. {
  17542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  17543. }
  17544. else
  17545. {
  17546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  17547. }
  17548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  17549. isKnowKey = TRUE;
  17550. }
  17551. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  17552. {
  17553. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  17554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  17555. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  17556. {
  17557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  17558. }
  17559. else
  17560. {
  17561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  17562. }
  17563. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  17564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  17565. isKnowKey = TRUE;
  17566. }
  17567. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  17568. {
  17569. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  17570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  17571. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  17572. {
  17573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  17574. }
  17575. else
  17576. {
  17577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  17578. }
  17579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  17580. isKnowKey = TRUE;
  17581. }
  17582. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  17583. {
  17584. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  17585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  17586. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17587. {
  17588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  17589. }
  17590. else
  17591. {
  17592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  17593. }
  17594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  17595. isKnowKey = TRUE;
  17596. }
  17597. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  17598. {
  17599. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  17600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  17601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  17602. {
  17603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17604. }
  17605. else
  17606. {
  17607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17608. }
  17609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  17610. isKnowKey = TRUE;
  17611. }
  17612. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  17613. {
  17614. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  17615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  17616. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17617. {
  17618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17619. }
  17620. else
  17621. {
  17622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17623. }
  17624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  17625. isKnowKey = TRUE;
  17626. }
  17627. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  17628. {
  17629. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  17630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  17631. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17632. {
  17633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17634. }
  17635. else
  17636. {
  17637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17638. }
  17639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  17640. isKnowKey = TRUE;
  17641. }
  17642. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  17643. {
  17644. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  17645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  17646. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17647. {
  17648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17649. }
  17650. else
  17651. {
  17652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17653. }
  17654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  17655. isKnowKey = TRUE;
  17656. }
  17657. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  17658. {
  17659. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  17660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  17661. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17662. {
  17663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17664. }
  17665. else
  17666. {
  17667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17668. }
  17669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  17670. isKnowKey = TRUE;
  17671. }
  17672. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  17673. {
  17674. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  17675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  17676. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17677. {
  17678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  17679. }
  17680. else
  17681. {
  17682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  17683. }
  17684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  17685. isKnowKey = TRUE;
  17686. }
  17687. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  17688. {
  17689. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  17690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  17691. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17692. {
  17693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17694. }
  17695. else
  17696. {
  17697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17698. }
  17699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  17700. isKnowKey = TRUE;
  17701. }
  17702. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  17703. {
  17704. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  17705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  17706. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17707. {
  17708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  17709. }
  17710. else
  17711. {
  17712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  17713. }
  17714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  17715. isKnowKey = TRUE;
  17716. }
  17717. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  17718. {
  17719. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  17720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  17721. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17722. {
  17723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17724. }
  17725. else
  17726. {
  17727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17728. }
  17729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  17730. isKnowKey = TRUE;
  17731. }
  17732. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  17733. {
  17734. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  17735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  17736. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17737. {
  17738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  17739. }
  17740. else
  17741. {
  17742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  17743. }
  17744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  17745. isKnowKey = TRUE;
  17746. }
  17747. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  17748. {
  17749. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  17750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  17751. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17752. {
  17753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  17754. }
  17755. else
  17756. {
  17757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  17758. }
  17759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  17760. isKnowKey = TRUE;
  17761. }
  17762. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  17763. {
  17764. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  17765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  17766. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17767. {
  17768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17769. }
  17770. else
  17771. {
  17772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17773. }
  17774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  17775. isKnowKey = TRUE;
  17776. }
  17777. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  17778. {
  17779. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  17780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  17781. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17782. {
  17783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  17784. }
  17785. else
  17786. {
  17787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  17788. }
  17789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  17790. isKnowKey = TRUE;
  17791. }
  17792. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  17793. {
  17794. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  17795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  17796. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17797. {
  17798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  17799. }
  17800. else
  17801. {
  17802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  17803. }
  17804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  17805. isKnowKey = TRUE;
  17806. }
  17807. /*
  17808. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  17809. {
  17810. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  17811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  17812. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  17813. {
  17814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  17815. }
  17816. else
  17817. {
  17818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  17819. }
  17820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  17821. isKnowKey = TRUE;
  17822. }*/
  17823. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  17824. {
  17825. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  17826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  17827. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17828. {
  17829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  17830. }
  17831. else
  17832. {
  17833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  17834. }
  17835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  17836. isKnowKey = TRUE;
  17837. }
  17838. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  17839. {
  17840. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  17841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  17842. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  17843. {
  17844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  17845. }
  17846. else
  17847. {
  17848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  17849. }
  17850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  17851. isKnowKey = TRUE;
  17852. }
  17853. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  17854. {
  17855. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  17856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  17857. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17858. {
  17859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  17860. }
  17861. else
  17862. {
  17863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  17864. }
  17865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  17866. isKnowKey = TRUE;
  17867. }
  17868. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  17869. {
  17870. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  17871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  17872. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17873. {
  17874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  17875. }
  17876. else
  17877. {
  17878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  17879. }
  17880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  17881. isKnowKey = TRUE;
  17882. }
  17883. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  17884. {
  17885. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  17886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  17887. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17888. {
  17889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  17890. }
  17891. else
  17892. {
  17893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  17894. }
  17895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  17896. isKnowKey = TRUE;
  17897. }
  17898. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  17899. {
  17900. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  17901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  17902. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17903. {
  17904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  17905. }
  17906. else
  17907. {
  17908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  17909. }
  17910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  17911. isKnowKey = TRUE;
  17912. }
  17913. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  17914. {
  17915. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  17916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  17917. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17918. {
  17919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  17920. }
  17921. else
  17922. {
  17923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  17924. }
  17925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  17926. isKnowKey = TRUE;
  17927. }
  17928. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  17929. {
  17930. struct sysinfo s_info;
  17931. int error = sysinfo(&s_info);
  17932. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  17933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  17934. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  17935. {
  17936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  17937. }
  17938. else
  17939. {
  17940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  17941. }
  17942. if(error != 0)
  17943. {
  17944. DEBUG_WARN("System uptime get error: %d\n", error);
  17945. }
  17946. else
  17947. {
  17948. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  17949. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  17950. }
  17951. isKnowKey = TRUE;
  17952. }
  17953. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  17954. {
  17955. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  17956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  17957. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17958. {
  17959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  17960. }
  17961. else
  17962. {
  17963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  17964. }
  17965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  17966. isKnowKey = TRUE;
  17967. }
  17968. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  17969. {
  17970. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  17971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  17972. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17973. {
  17974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  17975. }
  17976. else
  17977. {
  17978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  17979. }
  17980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  17981. isKnowKey = TRUE;
  17982. }
  17983. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  17984. {
  17985. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  17986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  17987. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17988. {
  17989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  17990. }
  17991. else
  17992. {
  17993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  17994. }
  17995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  17996. isKnowKey = TRUE;
  17997. }
  17998. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  17999. {
  18000. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  18001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  18002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  18003. {
  18004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  18005. }
  18006. else
  18007. {
  18008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  18009. }
  18010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  18011. isKnowKey = TRUE;
  18012. }
  18013. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  18014. {
  18015. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  18016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  18017. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  18018. {
  18019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  18020. }
  18021. else
  18022. {
  18023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  18024. }
  18025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  18026. isKnowKey = TRUE;
  18027. }
  18028. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  18029. {
  18030. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  18031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  18032. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  18033. {
  18034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  18035. }
  18036. else
  18037. {
  18038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  18039. }
  18040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  18041. isKnowKey = TRUE;
  18042. }
  18043. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  18044. {
  18045. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  18046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  18047. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  18048. {
  18049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  18050. }
  18051. else
  18052. {
  18053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  18054. }
  18055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  18056. isKnowKey = TRUE;
  18057. }
  18058. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  18059. {
  18060. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  18061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  18062. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  18063. {
  18064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  18065. }
  18066. else
  18067. {
  18068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  18069. }
  18070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  18071. isKnowKey = TRUE;
  18072. }
  18073. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  18074. {
  18075. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  18076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  18077. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  18078. {
  18079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  18080. }
  18081. else
  18082. {
  18083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  18084. }
  18085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  18086. isKnowKey = TRUE;
  18087. }
  18088. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  18089. {
  18090. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  18091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  18092. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  18093. {
  18094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  18095. }
  18096. else
  18097. {
  18098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  18099. }
  18100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  18101. isKnowKey = TRUE;
  18102. }
  18103. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  18104. {
  18105. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  18106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  18107. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  18108. {
  18109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  18110. }
  18111. else
  18112. {
  18113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  18114. }
  18115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  18116. isKnowKey = TRUE;
  18117. }
  18118. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  18119. {
  18120. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  18121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  18122. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  18123. {
  18124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  18125. }
  18126. else
  18127. {
  18128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  18129. }
  18130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  18131. isKnowKey = TRUE;
  18132. }
  18133. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  18134. {
  18135. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  18136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  18137. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  18138. {
  18139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  18140. }
  18141. else
  18142. {
  18143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  18144. }
  18145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  18146. isKnowKey = TRUE;
  18147. }
  18148. if(isEmpty || strcmp(keyReq, "CpoName") == 0 )
  18149. {
  18150. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CpoName].Item, "CpoName");
  18151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Key, "CpoName");
  18152. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  18153. {
  18154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "0"/*"FALSE"*/);
  18155. }
  18156. else
  18157. {
  18158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "1"/*"TRUE"*/);
  18159. }
  18160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData );
  18161. isKnowKey = TRUE;
  18162. }
  18163. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  18164. {
  18165. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  18166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  18167. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  18168. {
  18169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  18170. }
  18171. else
  18172. {
  18173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  18174. }
  18175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  18176. isKnowKey = TRUE;
  18177. }
  18178. #if 1
  18179. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  18180. {
  18181. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  18182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  18183. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  18184. {
  18185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  18186. }
  18187. else
  18188. {
  18189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  18190. }
  18191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  18192. isKnowKey = TRUE;
  18193. }
  18194. #endif
  18195. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  18196. {
  18197. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  18198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  18199. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  18200. {
  18201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  18202. }
  18203. else
  18204. {
  18205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  18206. }
  18207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  18208. isKnowKey = TRUE;
  18209. }
  18210. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  18211. {
  18212. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  18213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  18214. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  18215. {
  18216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  18217. }
  18218. else
  18219. {
  18220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  18221. }
  18222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  18223. isKnowKey = TRUE;
  18224. }
  18225. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  18226. {
  18227. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  18228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  18229. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  18230. {
  18231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  18232. }
  18233. else
  18234. {
  18235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  18236. }
  18237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  18238. isKnowKey = TRUE;
  18239. }
  18240. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  18241. {
  18242. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  18243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  18244. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  18245. {
  18246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  18247. }
  18248. else
  18249. {
  18250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  18251. }
  18252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  18253. isKnowKey = TRUE;
  18254. }
  18255. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  18256. {
  18257. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  18258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  18259. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  18260. {
  18261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  18262. }
  18263. else
  18264. {
  18265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  18266. }
  18267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  18268. isKnowKey = TRUE;
  18269. }
  18270. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  18271. {
  18272. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  18273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  18274. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  18275. {
  18276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  18277. }
  18278. else
  18279. {
  18280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  18281. }
  18282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  18283. isKnowKey = TRUE;
  18284. }
  18285. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  18286. {
  18287. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  18288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  18289. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  18290. {
  18291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  18292. }
  18293. else
  18294. {
  18295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  18296. }
  18297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  18298. isKnowKey = TRUE;
  18299. }
  18300. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  18301. {
  18302. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  18303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  18304. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  18305. {
  18306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  18307. }
  18308. else
  18309. {
  18310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  18311. }
  18312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  18313. isKnowKey = TRUE;
  18314. }
  18315. //=========================================================
  18316. if(!isEmpty && !isKnowKey)
  18317. {
  18318. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  18319. strcpy(unknownkey[UnknownKeynum], keyReq);
  18320. UnknownKeynum = UnknownKeynum + 1;
  18321. }
  18322. }
  18323. void processUnkownKey(void)
  18324. {
  18325. DEBUG_INFO("processUnkownKey...\n");
  18326. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  18327. for(int index=0; index < UnknownKeynum; index++)
  18328. {
  18329. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  18330. {
  18331. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  18332. }
  18333. }
  18334. }
  18335. int setKeyValue(char *key, char *value)
  18336. {
  18337. int isSuccess = NotSupported;
  18338. int check_ascii=0;
  18339. char str[501]={0};
  18340. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  18341. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  18342. {
  18343. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  18344. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  18345. {
  18346. strcpy(str, (const char*)value);
  18347. for(int i = 0; str[i]; i++){
  18348. str[i] = tolower(str[i]);
  18349. }
  18350. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18351. isSuccess = ConfigurationStatus_Accepted;
  18352. }
  18353. else
  18354. {
  18355. isSuccess = ConfigurationStatus_Rejected;
  18356. }
  18357. }
  18358. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  18359. {
  18360. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  18361. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  18362. {
  18363. strcpy(str, (const char*)value);
  18364. for(int i = 0; str[i]; i++){
  18365. str[i] = tolower(str[i]);
  18366. }
  18367. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18368. isSuccess = ConfigurationStatus_Accepted;
  18369. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  18370. }
  18371. else
  18372. {
  18373. isSuccess = ConfigurationStatus_Rejected;
  18374. }
  18375. }
  18376. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  18377. {
  18378. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  18379. {
  18380. strcpy(str, (const char*)value);
  18381. for(int i = 0; str[i]; i++)
  18382. {
  18383. str[i] = tolower(str[i]);
  18384. }
  18385. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  18386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18387. isSuccess = ConfigurationStatus_Accepted;
  18388. }
  18389. else
  18390. {
  18391. isSuccess = ConfigurationStatus_Rejected;
  18392. }
  18393. }
  18394. if(strcmp(key, "BlinkRepeat") == 0)
  18395. {
  18396. //Charger.BlinkRepeat = Integer.parseInt(value);
  18397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  18398. {
  18399. check_ascii = value[0];
  18400. if( (check_ascii < 48) || (check_ascii > 57) )
  18401. {
  18402. isSuccess = ConfigurationStatus_Rejected;
  18403. }
  18404. else
  18405. {
  18406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  18407. isSuccess = ConfigurationStatus_Accepted;
  18408. }
  18409. }
  18410. else
  18411. {
  18412. isSuccess = ConfigurationStatus_Rejected;
  18413. }
  18414. }
  18415. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  18416. {
  18417. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  18418. {
  18419. check_ascii = value[0];
  18420. if( (check_ascii < 48) || (check_ascii > 57) )
  18421. {
  18422. isSuccess = ConfigurationStatus_Rejected;
  18423. }
  18424. else
  18425. {
  18426. if((atoi(value) == 0) || (atoi(value) >= 5))
  18427. {
  18428. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  18429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  18430. isSuccess = ConfigurationStatus_Accepted;
  18431. }
  18432. else
  18433. isSuccess = ConfigurationStatus_Rejected;
  18434. }
  18435. }
  18436. else
  18437. {
  18438. isSuccess = ConfigurationStatus_Rejected;
  18439. }
  18440. }
  18441. if(strcmp(key, "ConnectionTimeOut") == 0 )
  18442. {
  18443. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  18444. {
  18445. check_ascii = value[0];
  18446. if( (check_ascii < 48) || (check_ascii > 57) )
  18447. {
  18448. isSuccess = ConfigurationStatus_Rejected;
  18449. }
  18450. else
  18451. {
  18452. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  18453. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  18454. isSuccess = ConfigurationStatus_Accepted;
  18455. }
  18456. }
  18457. else
  18458. {
  18459. isSuccess = ConfigurationStatus_Rejected;
  18460. }
  18461. }
  18462. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  18463. {
  18464. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  18465. {
  18466. check_ascii = value[0];
  18467. if( (check_ascii < 48) || (check_ascii > 57) )
  18468. {
  18469. isSuccess = ConfigurationStatus_Rejected;
  18470. }
  18471. else
  18472. {
  18473. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  18475. isSuccess = ConfigurationStatus_Accepted;
  18476. }
  18477. }
  18478. else
  18479. {
  18480. isSuccess = ConfigurationStatus_Rejected;
  18481. }
  18482. }
  18483. if(strcmp(key, "HeartbeatInterval") == 0)
  18484. {
  18485. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  18486. {
  18487. check_ascii = value[0];
  18488. if( (check_ascii < 48) || (check_ascii > 57) )
  18489. {
  18490. isSuccess = ConfigurationStatus_Rejected;
  18491. }
  18492. else
  18493. {
  18494. if((atoi(value) == 0) || (atoi(value) >= 10))
  18495. {
  18496. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18497. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  18498. HeartBeatWaitTime = atoi(value);
  18499. isSuccess = ConfigurationStatus_Accepted;
  18500. }
  18501. else
  18502. {
  18503. isSuccess = ConfigurationStatus_Rejected;
  18504. }
  18505. }
  18506. }
  18507. else
  18508. {
  18509. isSuccess = ConfigurationStatus_Rejected;
  18510. }
  18511. }
  18512. if(strcmp(key, "LightIntensity") == 0)
  18513. {
  18514. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  18515. {
  18516. check_ascii = value[0];
  18517. if( (check_ascii < 48) || (check_ascii > 57) )
  18518. {
  18519. isSuccess = ConfigurationStatus_Rejected;
  18520. }
  18521. else
  18522. {
  18523. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  18524. isSuccess = ConfigurationStatus_Accepted;
  18525. }
  18526. }
  18527. else
  18528. {
  18529. isSuccess = ConfigurationStatus_Rejected;
  18530. }
  18531. }
  18532. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  18533. {
  18534. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  18535. {
  18536. strcpy(str, (const char*)value);
  18537. for(int i = 0; str[i]; i++)
  18538. {
  18539. str[i] = tolower(str[i]);
  18540. }
  18541. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18542. isSuccess = ConfigurationStatus_Accepted;
  18543. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  18544. }
  18545. else
  18546. {
  18547. isSuccess = ConfigurationStatus_Rejected;
  18548. }
  18549. }
  18550. if(strcmp(key, "LocalPreAuthorize") == 0)
  18551. {
  18552. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  18553. {
  18554. strcpy(str, (const char*)value);
  18555. for(int i = 0; str[i]; i++)
  18556. {
  18557. str[i] = tolower(str[i]);
  18558. }
  18559. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18560. isSuccess = ConfigurationStatus_Accepted;
  18561. }
  18562. else
  18563. {
  18564. isSuccess = ConfigurationStatus_Rejected;
  18565. }
  18566. }
  18567. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  18568. {
  18569. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  18570. {
  18571. check_ascii = value[0];
  18572. if( (check_ascii < 48) || (check_ascii > 57) )
  18573. {
  18574. isSuccess = ConfigurationStatus_Rejected;
  18575. }
  18576. else
  18577. {
  18578. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  18579. isSuccess = ConfigurationStatus_Accepted;
  18580. }
  18581. }
  18582. else
  18583. {
  18584. isSuccess = ConfigurationStatus_Rejected;
  18585. }
  18586. }
  18587. if(strcmp(key, "MeterValuesAlignedData") == 0)
  18588. {
  18589. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  18590. {
  18591. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  18592. isSuccess = ConfigurationStatus_Accepted;
  18593. }
  18594. else
  18595. {
  18596. isSuccess = ConfigurationStatus_Rejected;
  18597. }
  18598. }
  18599. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  18600. {
  18601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  18602. {
  18603. check_ascii = value[0];
  18604. if( (check_ascii < 48) || (check_ascii > 57) )
  18605. {
  18606. isSuccess = ConfigurationStatus_Rejected;
  18607. }
  18608. else
  18609. {
  18610. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18611. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  18612. isSuccess = ConfigurationStatus_Accepted;
  18613. }
  18614. }
  18615. else
  18616. {
  18617. isSuccess = ConfigurationStatus_Rejected;
  18618. }
  18619. }
  18620. if(strcmp(key, "MeterValuesSampledData") == 0 )
  18621. {
  18622. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  18623. {
  18624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  18625. isSuccess = ConfigurationStatus_Accepted;
  18626. }
  18627. else
  18628. {
  18629. isSuccess = ConfigurationStatus_Rejected;
  18630. }
  18631. }
  18632. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  18633. {
  18634. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  18635. {
  18636. check_ascii = value[0];
  18637. if( (check_ascii < 48) || (check_ascii > 57) )
  18638. {
  18639. isSuccess = ConfigurationStatus_Rejected;
  18640. }
  18641. else
  18642. {
  18643. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18644. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  18645. isSuccess = ConfigurationStatus_Accepted;
  18646. }
  18647. }
  18648. else
  18649. {
  18650. isSuccess = ConfigurationStatus_Rejected;
  18651. }
  18652. }
  18653. if(strcmp(key, "MeterValueSampleInterval") == 0)
  18654. {
  18655. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  18656. {
  18657. check_ascii = value[0];
  18658. if( (check_ascii < 48) || (check_ascii > 57) )
  18659. {
  18660. isSuccess = ConfigurationStatus_Rejected;
  18661. }
  18662. else
  18663. {
  18664. if((atoi(value) == 0) || (atoi(value) >= 3))
  18665. {
  18666. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18667. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  18668. isSuccess = ConfigurationStatus_Accepted;
  18669. }
  18670. else
  18671. {
  18672. isSuccess = ConfigurationStatus_Rejected;
  18673. }
  18674. }
  18675. }
  18676. else
  18677. {
  18678. isSuccess = ConfigurationStatus_Rejected;
  18679. }
  18680. }
  18681. if(strcmp(key, "MinimumStatusDuration") == 0)
  18682. {
  18683. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  18684. {
  18685. check_ascii = value[0];
  18686. if( (check_ascii < 48) || (check_ascii > 57) )
  18687. {
  18688. isSuccess = ConfigurationStatus_Rejected;
  18689. }
  18690. else
  18691. {
  18692. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  18693. {
  18694. isSuccess = ConfigurationStatus_Rejected;
  18695. }
  18696. else
  18697. {
  18698. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  18699. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  18700. server_cycle_Status = atoi(value); //StatusNotification Cycle
  18701. isSuccess = ConfigurationStatus_Accepted;
  18702. }
  18703. }
  18704. }
  18705. else
  18706. {
  18707. isSuccess = ConfigurationStatus_Rejected;
  18708. }
  18709. }
  18710. if(strcmp(key, "NumberOfConnectors") == 0)
  18711. {
  18712. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  18713. {
  18714. check_ascii = value[0];
  18715. if( (check_ascii < 48) || (check_ascii > 57) )
  18716. {
  18717. isSuccess = ConfigurationStatus_Rejected;
  18718. }
  18719. else
  18720. {
  18721. //Charger.ResetRetries = Integer.parseInt(value);
  18722. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  18723. isSuccess = ConfigurationStatus_Accepted;
  18724. }
  18725. }
  18726. else
  18727. {
  18728. isSuccess = ConfigurationStatus_Rejected;
  18729. }
  18730. }
  18731. if(strcmp(key, "ResetRetries") == 0)
  18732. {
  18733. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  18734. {
  18735. check_ascii = value[0];
  18736. if( (check_ascii < 48) || (check_ascii > 57) )
  18737. {
  18738. isSuccess = ConfigurationStatus_Rejected;
  18739. }
  18740. else
  18741. {
  18742. //Charger.ResetRetries = Integer.parseInt(value);
  18743. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  18744. isSuccess = ConfigurationStatus_Accepted;
  18745. }
  18746. }
  18747. else
  18748. {
  18749. isSuccess = ConfigurationStatus_Rejected;
  18750. }
  18751. }
  18752. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  18753. {
  18754. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  18755. {
  18756. strcpy(str, (const char*)value);
  18757. for(int i = 0; str[i]; i++)
  18758. {
  18759. str[i] = tolower(str[i]);
  18760. }
  18761. if(strcmp(str, "notapplicable")== 0)
  18762. {
  18763. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  18764. isSuccess = ConfigurationStatus_Accepted;
  18765. }
  18766. else if(strcmp(str, "unknown")== 0)
  18767. {
  18768. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  18769. isSuccess = ConfigurationStatus_Accepted;
  18770. }
  18771. else if(strcmp(str, "rst")== 0)
  18772. {
  18773. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  18774. isSuccess = ConfigurationStatus_Accepted;
  18775. }
  18776. else if(strcmp(str, "rts")== 0)
  18777. {
  18778. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  18779. isSuccess = ConfigurationStatus_Accepted;
  18780. }
  18781. else if(strcmp(str, "srt")== 0)
  18782. {
  18783. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  18784. isSuccess = ConfigurationStatus_Accepted;
  18785. }
  18786. else if(strcmp(str, "str")== 0)
  18787. {
  18788. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  18789. isSuccess = ConfigurationStatus_Accepted;
  18790. }
  18791. else if(strcmp(str, "trs")== 0)
  18792. {
  18793. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  18794. isSuccess = ConfigurationStatus_Accepted;
  18795. }
  18796. else if(strcmp(str, "tsr")== 0)
  18797. {
  18798. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  18799. isSuccess = ConfigurationStatus_Accepted;
  18800. }
  18801. else
  18802. {
  18803. isSuccess = ConfigurationStatus_Rejected;
  18804. }
  18805. }
  18806. else
  18807. {
  18808. isSuccess = ConfigurationStatus_Rejected;
  18809. }
  18810. }
  18811. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  18812. {
  18813. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  18814. {
  18815. check_ascii = value[0];
  18816. if( (check_ascii < 48) || (check_ascii > 57) )
  18817. {
  18818. isSuccess = ConfigurationStatus_Rejected;
  18819. }
  18820. else
  18821. {
  18822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  18823. isSuccess = ConfigurationStatus_Accepted;
  18824. }
  18825. }
  18826. else
  18827. {
  18828. isSuccess = ConfigurationStatus_Rejected;
  18829. }
  18830. }
  18831. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  18832. {
  18833. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  18834. {
  18835. strcpy(str, (const char*)value);
  18836. for(int i = 0; str[i]; i++)
  18837. {
  18838. str[i] = tolower(str[i]);
  18839. }
  18840. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18841. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18842. isSuccess = ConfigurationStatus_Accepted;
  18843. }
  18844. else
  18845. {
  18846. isSuccess = ConfigurationStatus_Rejected;
  18847. }
  18848. }
  18849. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  18850. {
  18851. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  18852. {
  18853. strcpy(str, (const char*)value);
  18854. for(int i = 0; str[i]; i++)
  18855. {
  18856. str[i] = tolower(str[i]);
  18857. }
  18858. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  18859. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18860. isSuccess = ConfigurationStatus_Accepted;
  18861. }
  18862. else
  18863. {
  18864. isSuccess = ConfigurationStatus_Rejected;
  18865. }
  18866. }
  18867. if(strcmp(key, "StopTxnAlignedData") == 0)
  18868. {
  18869. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  18870. {
  18871. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  18872. isSuccess = ConfigurationStatus_Accepted;
  18873. }
  18874. else
  18875. {
  18876. isSuccess = ConfigurationStatus_Rejected;
  18877. }
  18878. }
  18879. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  18880. {
  18881. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  18882. {
  18883. check_ascii = value[0];
  18884. if( (check_ascii < 48) || (check_ascii > 57) )
  18885. {
  18886. isSuccess = ConfigurationStatus_Rejected;
  18887. }
  18888. else
  18889. {
  18890. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  18891. isSuccess = ConfigurationStatus_Accepted;
  18892. }
  18893. }
  18894. else
  18895. {
  18896. isSuccess = ConfigurationStatus_Rejected;
  18897. }
  18898. }
  18899. if(strcmp(key, "StopTxnSampledData") == 0)
  18900. {
  18901. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  18902. {
  18903. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  18904. isSuccess = ConfigurationStatus_Accepted;
  18905. }
  18906. else
  18907. {
  18908. isSuccess = ConfigurationStatus_Rejected;
  18909. }
  18910. }
  18911. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  18912. {
  18913. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  18914. {
  18915. check_ascii = value[0];
  18916. if( (check_ascii < 48) || (check_ascii > 57) )
  18917. {
  18918. isSuccess = ConfigurationStatus_Rejected;
  18919. }
  18920. else
  18921. {
  18922. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  18923. isSuccess = ConfigurationStatus_Accepted;
  18924. }
  18925. }
  18926. else
  18927. {
  18928. isSuccess = ConfigurationStatus_Rejected;
  18929. }
  18930. }
  18931. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  18932. {
  18933. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  18934. {
  18935. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  18936. isSuccess = ConfigurationStatus_Accepted;
  18937. }
  18938. else
  18939. {
  18940. isSuccess = ConfigurationStatus_Rejected;
  18941. }
  18942. }
  18943. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  18944. {
  18945. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  18946. {
  18947. check_ascii = value[0];
  18948. if( (check_ascii < 48) || (check_ascii > 57) )
  18949. {
  18950. isSuccess = ConfigurationStatus_Rejected;
  18951. }
  18952. else
  18953. {
  18954. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  18955. isSuccess = ConfigurationStatus_Accepted;
  18956. }
  18957. }
  18958. else
  18959. {
  18960. isSuccess = ConfigurationStatus_Rejected;
  18961. }
  18962. }
  18963. if(strcmp(key, "TransactionMessageAttempts") == 0)
  18964. {
  18965. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  18966. {
  18967. check_ascii = value[0];
  18968. if( (check_ascii < 48) || (check_ascii > 57) )
  18969. {
  18970. isSuccess = ConfigurationStatus_Rejected;
  18971. }
  18972. else
  18973. {
  18974. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  18975. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  18976. TransactionMessageAttemptsValue = atoi(value);
  18977. isSuccess = ConfigurationStatus_Accepted;
  18978. }
  18979. }
  18980. else
  18981. {
  18982. isSuccess = ConfigurationStatus_Rejected;
  18983. }
  18984. }
  18985. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  18986. {
  18987. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  18988. {
  18989. check_ascii = value[0];
  18990. if( (check_ascii < 48) || (check_ascii > 57) )
  18991. {
  18992. isSuccess = ConfigurationStatus_Rejected;
  18993. }
  18994. else
  18995. {
  18996. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  18997. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  18998. TransactionMessageRetryIntervalValue = atoi(value);
  18999. isSuccess = ConfigurationStatus_Accepted;
  19000. }
  19001. }
  19002. else
  19003. {
  19004. isSuccess = ConfigurationStatus_Rejected;
  19005. }
  19006. }
  19007. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  19008. {
  19009. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  19010. {
  19011. strcpy(str, (const char*)value);
  19012. for(int i = 0; str[i]; i++)
  19013. {
  19014. str[i] = tolower(str[i]);
  19015. }
  19016. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  19017. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19018. isSuccess = ConfigurationStatus_Accepted;
  19019. }
  19020. else
  19021. {
  19022. isSuccess = ConfigurationStatus_Rejected;
  19023. }
  19024. }
  19025. if(strcmp(key, "WebSocketPingInterval") == 0)
  19026. {
  19027. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  19028. {
  19029. check_ascii = value[0];
  19030. if( (check_ascii < 48) || (check_ascii > 57) )
  19031. {
  19032. isSuccess = ConfigurationStatus_Rejected;
  19033. }
  19034. else
  19035. {
  19036. if((atoi(value) == 0) || (atoi(value) >= 10))
  19037. {
  19038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  19039. isSuccess = ConfigurationStatus_Accepted;
  19040. }
  19041. else
  19042. isSuccess = ConfigurationStatus_Rejected;
  19043. }
  19044. }
  19045. else
  19046. {
  19047. isSuccess = ConfigurationStatus_Rejected;
  19048. }
  19049. }
  19050. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  19051. {
  19052. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  19053. {
  19054. strcpy(str, (const char*)value);
  19055. for(int i = 0; str[i]; i++)
  19056. {
  19057. str[i] = tolower(str[i]);
  19058. }
  19059. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19060. isSuccess = ConfigurationStatus_Accepted;
  19061. }
  19062. else
  19063. {
  19064. isSuccess = ConfigurationStatus_Rejected;
  19065. }
  19066. }
  19067. if(strcmp(key, "AuthorizationKey") == 0)
  19068. {
  19069. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  19070. {
  19071. strcpy(str, (const char*)value);
  19072. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  19073. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  19074. isSuccess = ConfigurationStatus_Accepted;
  19075. }
  19076. else
  19077. {
  19078. isSuccess = ConfigurationStatus_Rejected;
  19079. }
  19080. }
  19081. if(strcmp(key, "SecurityProfile") == 0)
  19082. {
  19083. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  19084. {
  19085. check_ascii = value[0];
  19086. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  19087. {
  19088. isSuccess = ConfigurationStatus_Rejected;
  19089. }
  19090. else if(check_ascii == 0x33)
  19091. {
  19092. isSuccess = NotSupported;
  19093. }
  19094. else
  19095. {
  19096. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  19097. {
  19098. if(((check_ascii - 0x30) == 1) ||
  19099. ((check_ascii - 0x30) == 2) ||
  19100. (((check_ascii - 0x30) == 3) && (access(CERTIFICATE_CP,F_OK) != -1)))
  19101. {
  19102. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  19103. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  19104. isSuccess = ConfigurationStatus_Accepted;
  19105. }
  19106. else
  19107. isSuccess = ConfigurationStatus_Rejected;
  19108. }
  19109. else
  19110. isSuccess = ConfigurationStatus_Rejected;
  19111. }
  19112. }
  19113. else
  19114. {
  19115. isSuccess = ConfigurationStatus_Rejected;
  19116. }
  19117. }
  19118. if(strcmp(key, "DefaultPrice") == 0)
  19119. {
  19120. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  19121. {
  19122. strcpy(str, (const char*)value);
  19123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  19124. isSuccess = ConfigurationStatus_Accepted;
  19125. }
  19126. else
  19127. {
  19128. isSuccess = ConfigurationStatus_Rejected;
  19129. }
  19130. }
  19131. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  19132. {
  19133. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  19134. {
  19135. strcpy(str, (const char*)value);
  19136. for(int i = 0; str[i]; i++)
  19137. {
  19138. str[i] = tolower(str[i]);
  19139. }
  19140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19141. isSuccess = ConfigurationStatus_Accepted;
  19142. }
  19143. else
  19144. {
  19145. isSuccess = ConfigurationStatus_Rejected;
  19146. }
  19147. }
  19148. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  19149. {
  19150. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  19151. {
  19152. strcpy(str, (const char*)value);
  19153. for(int i = 0; str[i]; i++)
  19154. {
  19155. str[i] = tolower(str[i]);
  19156. }
  19157. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19158. isSuccess = ConfigurationStatus_Accepted;
  19159. }
  19160. else
  19161. {
  19162. isSuccess = ConfigurationStatus_Rejected;
  19163. }
  19164. }
  19165. if(strcmp(key, "TimeOffset") == 0)
  19166. {
  19167. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  19168. {
  19169. strcpy(str, (const char*)value);
  19170. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  19171. isSuccess = ConfigurationStatus_Accepted;
  19172. }
  19173. else
  19174. {
  19175. isSuccess = ConfigurationStatus_Rejected;
  19176. }
  19177. }
  19178. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  19179. {
  19180. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  19181. {
  19182. strcpy(str, (const char*)value);
  19183. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  19184. isSuccess = ConfigurationStatus_Accepted;
  19185. }
  19186. else
  19187. {
  19188. isSuccess = ConfigurationStatus_Rejected;
  19189. }
  19190. }
  19191. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  19192. {
  19193. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  19194. {
  19195. strcpy(str, (const char*)value);
  19196. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  19197. isSuccess = ConfigurationStatus_Accepted;
  19198. }
  19199. else
  19200. {
  19201. isSuccess = ConfigurationStatus_Rejected;
  19202. }
  19203. }
  19204. if(strcmp(key, "SystemUptimeSec") == 0)
  19205. {
  19206. isSuccess = NotSupported;
  19207. }
  19208. if(strcmp(key, "FreeVend") == 0)
  19209. {
  19210. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  19211. {
  19212. strcpy(str, (const char*)value);
  19213. for(int i = 0; str[i]; i++)
  19214. {
  19215. str[i] = tolower(str[i]);
  19216. }
  19217. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  19218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19219. isSuccess = ConfigurationStatus_Accepted;
  19220. }
  19221. else
  19222. {
  19223. isSuccess = ConfigurationStatus_Rejected;
  19224. }
  19225. }
  19226. if(strcmp(key, "FreeVendIdtag") == 0)
  19227. {
  19228. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  19229. {
  19230. strcpy(str, (const char*)value);
  19231. if(strlen(str) <= 20)
  19232. {
  19233. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  19234. isSuccess = ConfigurationStatus_Accepted;
  19235. }
  19236. else
  19237. {
  19238. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  19239. isSuccess = ConfigurationStatus_Rejected;
  19240. }
  19241. }
  19242. else
  19243. {
  19244. isSuccess = ConfigurationStatus_Rejected;
  19245. }
  19246. }
  19247. if(strcmp(key, "OcppServer") == 0)
  19248. {
  19249. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  19250. {
  19251. strcpy(str, (const char*)value);
  19252. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  19253. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  19254. isSuccess = ConfigurationStatus_Accepted;
  19255. }
  19256. else
  19257. {
  19258. isSuccess = ConfigurationStatus_Rejected;
  19259. }
  19260. }
  19261. if(strcmp(key, "MaintainServer") == 0)
  19262. {
  19263. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  19264. {
  19265. strcpy(str, (const char*)value);
  19266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  19267. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  19268. isSuccess = ConfigurationStatus_Accepted;
  19269. }
  19270. else
  19271. {
  19272. isSuccess = ConfigurationStatus_Rejected;
  19273. }
  19274. }
  19275. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  19276. {
  19277. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  19278. {
  19279. strcpy(str, (const char*)value);
  19280. for(int i = 0; str[i]; i++)
  19281. {
  19282. str[i] = tolower(str[i]);
  19283. }
  19284. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  19285. isSuccess = ConfigurationStatus_Accepted;
  19286. }
  19287. else
  19288. {
  19289. isSuccess = ConfigurationStatus_Rejected;
  19290. }
  19291. }
  19292. if(strcmp(key, "StatusNotificationInterval") == 0)
  19293. {
  19294. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  19295. {
  19296. check_ascii = value[0];
  19297. if( (check_ascii < 48) || (check_ascii > 57) )
  19298. {
  19299. isSuccess = ConfigurationStatus_Rejected;
  19300. }
  19301. else
  19302. {
  19303. if((atoi(value) == 0) || (atoi(value) >= 10))
  19304. {
  19305. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  19306. isSuccess = ConfigurationStatus_Accepted;
  19307. }
  19308. else
  19309. isSuccess = ConfigurationStatus_Rejected;
  19310. }
  19311. }
  19312. else
  19313. {
  19314. isSuccess = ConfigurationStatus_Rejected;
  19315. }
  19316. }
  19317. if(strcmp(key, "PreAuthAmount") == 0)
  19318. {
  19319. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  19320. {
  19321. check_ascii = value[0];
  19322. if( (check_ascii < 48) || (check_ascii > 57) )
  19323. {
  19324. isSuccess = ConfigurationStatus_Rejected;
  19325. }
  19326. else
  19327. {
  19328. if(atof(value) >= 0)
  19329. {
  19330. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  19331. isSuccess = ConfigurationStatus_Accepted;
  19332. }
  19333. else
  19334. isSuccess = ConfigurationStatus_Rejected;
  19335. }
  19336. }
  19337. else
  19338. {
  19339. isSuccess = ConfigurationStatus_Rejected;
  19340. }
  19341. }
  19342. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  19343. {
  19344. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  19345. {
  19346. check_ascii = value[0];
  19347. if( (check_ascii < 48) || (check_ascii > 57) )
  19348. {
  19349. isSuccess = ConfigurationStatus_Rejected;
  19350. }
  19351. else
  19352. {
  19353. if(atoi(value) >= 0)
  19354. {
  19355. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  19356. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  19357. isSuccess = ConfigurationStatus_Accepted;
  19358. }
  19359. else
  19360. isSuccess = ConfigurationStatus_Rejected;
  19361. }
  19362. }
  19363. else
  19364. {
  19365. isSuccess = ConfigurationStatus_Rejected;
  19366. }
  19367. }
  19368. if(strcmp(key, "PowerSharingServerIP") == 0)
  19369. {
  19370. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  19371. {
  19372. strcpy(str, (const char*)value);
  19373. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  19374. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  19375. isSuccess = ConfigurationStatus_Accepted;
  19376. }
  19377. else
  19378. {
  19379. isSuccess = ConfigurationStatus_Rejected;
  19380. }
  19381. }
  19382. if(strcmp(key, "EVCCID_PREFIX") == 0)
  19383. {
  19384. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  19385. {
  19386. strcpy(str, (const char*)value);
  19387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  19388. isSuccess = ConfigurationStatus_Accepted;
  19389. }
  19390. else
  19391. {
  19392. isSuccess = ConfigurationStatus_Rejected;
  19393. }
  19394. }
  19395. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  19396. {
  19397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  19398. {
  19399. if(atoi(value) > modelnameInfo.ratedPower)
  19400. {
  19401. isSuccess = ConfigurationStatus_Rejected;
  19402. }
  19403. else{
  19404. strcpy(str, (const char*)value);
  19405. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  19406. isSuccess = ConfigurationStatus_Accepted;
  19407. }
  19408. }
  19409. else
  19410. {
  19411. isSuccess = ConfigurationStatus_Rejected;
  19412. }
  19413. }
  19414. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  19415. {
  19416. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  19417. {
  19418. if((atoi(value) != 0) && (atoi(value) < 5))
  19419. {
  19420. isSuccess = ConfigurationStatus_Rejected;
  19421. }
  19422. else{
  19423. strcpy(str, (const char*)value);
  19424. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  19425. isSuccess = ConfigurationStatus_Accepted;
  19426. }
  19427. }
  19428. else
  19429. {
  19430. isSuccess = ConfigurationStatus_Rejected;
  19431. }
  19432. }
  19433. if(strcmp(key, "CpoName") == 0)
  19434. {
  19435. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  19436. {
  19437. strcpy(str, (const char*)value);
  19438. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", str );
  19439. isSuccess = ConfigurationStatus_Accepted;
  19440. }
  19441. else
  19442. {
  19443. isSuccess = ConfigurationStatus_Rejected;
  19444. }
  19445. }
  19446. #if 0
  19447. //For OCPP Test Case
  19448. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  19449. {
  19450. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19451. {
  19452. strcpy(str, (const char*)value);
  19453. for(int i = 0; str[i]; i++)
  19454. {
  19455. str[i] = tolower(str[i]);
  19456. }
  19457. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19458. isSuccess = ConfigurationStatus_Accepted;
  19459. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19460. }
  19461. else
  19462. {
  19463. isSuccess = ConfigurationStatus_Rejected;
  19464. }
  19465. }
  19466. #endif
  19467. #if 1
  19468. if(strcmp(key, "LocalAuthListEnabled") == 0)
  19469. {
  19470. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19471. {
  19472. strcpy(str, (const char*)value);
  19473. for(int i = 0; str[i]; i++)
  19474. {
  19475. str[i] = tolower(str[i]);
  19476. }
  19477. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19478. isSuccess = ConfigurationStatus_Accepted;
  19479. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19480. }
  19481. else
  19482. {
  19483. isSuccess = ConfigurationStatus_Rejected;
  19484. }
  19485. }
  19486. #endif
  19487. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  19488. {
  19489. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  19490. {
  19491. check_ascii = value[0];
  19492. if( (check_ascii < 48) || (check_ascii > 57) )
  19493. {
  19494. isSuccess = ConfigurationStatus_Rejected;
  19495. }
  19496. else
  19497. {
  19498. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  19499. isSuccess = ConfigurationStatus_Accepted;
  19500. }
  19501. }
  19502. else
  19503. {
  19504. isSuccess = ConfigurationStatus_Rejected;
  19505. }
  19506. }
  19507. if(strcmp(key, "SendLocalListMaxLength") == 0)
  19508. {
  19509. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  19510. {
  19511. check_ascii = value[0];
  19512. if( (check_ascii < 48) || (check_ascii > 57) )
  19513. {
  19514. isSuccess = ConfigurationStatus_Rejected;
  19515. }
  19516. else
  19517. {
  19518. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  19519. isSuccess = ConfigurationStatus_Accepted;
  19520. }
  19521. }
  19522. else
  19523. {
  19524. isSuccess = ConfigurationStatus_Rejected;
  19525. }
  19526. }
  19527. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  19528. {
  19529. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  19530. {
  19531. strcpy(str, (const char*)value);
  19532. for(int i = 0; str[i]; i++)
  19533. {
  19534. str[i] = tolower(str[i]);
  19535. }
  19536. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19537. isSuccess = ConfigurationStatus_Accepted;
  19538. }
  19539. else
  19540. {
  19541. isSuccess = ConfigurationStatus_Rejected;
  19542. }
  19543. }
  19544. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  19545. {
  19546. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  19547. {
  19548. check_ascii = value[0];
  19549. if( (check_ascii < 48) || (check_ascii > 57) )
  19550. {
  19551. isSuccess = ConfigurationStatus_Rejected;
  19552. }
  19553. else
  19554. {
  19555. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  19556. isSuccess = ConfigurationStatus_Accepted;
  19557. }
  19558. }
  19559. else
  19560. {
  19561. isSuccess = ConfigurationStatus_Rejected;
  19562. }
  19563. }
  19564. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  19565. {
  19566. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  19567. {
  19568. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  19569. isSuccess = ConfigurationStatus_Accepted;
  19570. }
  19571. else
  19572. {
  19573. isSuccess = ConfigurationStatus_Rejected;
  19574. }
  19575. }
  19576. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  19577. {
  19578. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  19579. {
  19580. check_ascii = value[0];
  19581. if( (check_ascii < 48) || (check_ascii > 57) )
  19582. {
  19583. isSuccess = ConfigurationStatus_Rejected;
  19584. }
  19585. else
  19586. {
  19587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  19588. isSuccess = ConfigurationStatus_Accepted;
  19589. }
  19590. }
  19591. else
  19592. {
  19593. isSuccess = ConfigurationStatus_Rejected;
  19594. }
  19595. }
  19596. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  19597. {
  19598. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  19599. {
  19600. strcpy(str, (const char*)value);
  19601. for(int i = 0; str[i]; i++)
  19602. {
  19603. str[i] = tolower(str[i]);
  19604. }
  19605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19606. isSuccess = ConfigurationStatus_Accepted;
  19607. }
  19608. else
  19609. {
  19610. isSuccess = ConfigurationStatus_Rejected;
  19611. }
  19612. }
  19613. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  19614. {
  19615. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  19616. {
  19617. check_ascii = value[0];
  19618. if( (check_ascii < 48) || (check_ascii > 57) )
  19619. {
  19620. isSuccess = ConfigurationStatus_Rejected;
  19621. }
  19622. else
  19623. {
  19624. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  19625. isSuccess = ConfigurationStatus_Accepted;
  19626. }
  19627. }
  19628. else
  19629. {
  19630. isSuccess = ConfigurationStatus_Rejected;
  19631. }
  19632. }
  19633. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19634. return isSuccess;
  19635. }
  19636. int TransactionMessageAttemptsGet(void)
  19637. {
  19638. return TransactionMessageAttemptsValue;
  19639. }
  19640. int FirstHeartBeatResponse(void)
  19641. {
  19642. return FirstHeartBeat;
  19643. }
  19644. int TransactionMessageRetryIntervalGet(void)
  19645. {
  19646. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19647. }
  19648. int ReadHttpStatus(int sock)
  19649. {
  19650. //char c;
  19651. char buff[1024]="",*ptr=buff+1;
  19652. int bytes_received, status;
  19653. DEBUG_INFO("Begin Response ..\n");
  19654. while((bytes_received = recv(sock, ptr, 1, 0))){
  19655. if(bytes_received==-1){
  19656. perror("ReadHttpStatus");
  19657. exit(1);
  19658. }
  19659. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  19660. ptr++;
  19661. }
  19662. *ptr=0;
  19663. ptr=buff+1;
  19664. sscanf(ptr,"%*s %d ", &status);
  19665. DEBUG_INFO("%s\n",ptr);
  19666. DEBUG_INFO("status=%d\n",status);
  19667. DEBUG_INFO("End Response ..\n");
  19668. return (bytes_received>0)?status:0;
  19669. }
  19670. //the only filed that it parsed is 'Content-Length'
  19671. int ParseHeader(int sock)
  19672. {
  19673. //char c;
  19674. char buff[1024]="",*ptr=buff+4;
  19675. int bytes_received;
  19676. DEBUG_INFO("Begin HEADER ..\n");
  19677. while((bytes_received = recv(sock, ptr, 1, 0))){
  19678. if(bytes_received==-1){
  19679. perror("Parse Header");
  19680. exit(1);
  19681. }
  19682. if(
  19683. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  19684. (ptr[-1]=='\r') && (*ptr=='\n' )
  19685. ) break;
  19686. ptr++;
  19687. }
  19688. *ptr=0;
  19689. ptr=buff+4;
  19690. //printf("%s",ptr);
  19691. if(bytes_received){
  19692. ptr=strstr(ptr,"Content-Length:");
  19693. if(ptr){
  19694. sscanf(ptr,"%*s %d",&bytes_received);
  19695. }else
  19696. bytes_received=-1; //unknown size
  19697. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  19698. }
  19699. DEBUG_INFO("End HEADER ..\n");
  19700. return bytes_received ;
  19701. }
  19702. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  19703. {
  19704. int result = TRUE;
  19705. char rmFileCmd[100]={0};
  19706. char FilePath[100]={0};
  19707. char ftpbuf[200];
  19708. int systemresult;
  19709. sprintf(FilePath,"/mnt/%s",filename);
  19710. system("ping 8.8.8.8 &");
  19711. if((access(FilePath,F_OK))!=-1)
  19712. {
  19713. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19714. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19715. system(rmFileCmd);
  19716. }
  19717. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19718. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  19719. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19720. systemresult = system(ftpbuf);
  19721. if(systemresult != 0)
  19722. {
  19723. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  19724. result = FALSE;
  19725. }
  19726. system("pkill ping");
  19727. return result;
  19728. }
  19729. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  19730. {
  19731. int result = TRUE;
  19732. char rmFileCmd[100]={0};
  19733. char FilePath[100]={0};
  19734. char ftpbuf[200];
  19735. int systemresult;
  19736. sprintf(FilePath,"/mnt/%s",filename);
  19737. system("ping 8.8.8.8 &");
  19738. if((access(FilePath,F_OK))!=-1)
  19739. {
  19740. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19741. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19742. system(rmFileCmd);
  19743. }
  19744. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19745. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  19746. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19747. systemresult = system(ftpbuf);
  19748. if(systemresult != 0)
  19749. {
  19750. DEBUG_WARN("scp error!\n");
  19751. result = FALSE;
  19752. }
  19753. system("pkill ping");
  19754. return result;
  19755. }
  19756. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  19757. {
  19758. int result = TRUE;
  19759. char rmFileCmd[100]={0};
  19760. char FilePath[100]={0};
  19761. char ftpbuf[200];
  19762. int systemresult;
  19763. sprintf(FilePath,"/mnt/%s",filename);
  19764. system("ping 8.8.8.8 &");
  19765. if((access(FilePath,F_OK))!=-1)
  19766. {
  19767. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19768. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19769. system(rmFileCmd);
  19770. }
  19771. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19772. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  19773. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19774. systemresult = system(ftpbuf);
  19775. if(systemresult != 0)
  19776. {
  19777. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  19778. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19779. systemresult = system(ftpbuf);
  19780. if(systemresult != 0)
  19781. {
  19782. DEBUG_WARN("FTP download fail!\n");
  19783. result = FALSE;
  19784. }
  19785. }
  19786. system("pkill ping");
  19787. return result;
  19788. }
  19789. int httpUploadFile(char *location, char *path, char *filename,char *url)
  19790. {
  19791. char rmFileCmd[100]={0};
  19792. char FilePath[100]={0};
  19793. char buf[512];
  19794. int systemresult = 0;
  19795. //DEBUG_INFO("filename=%s\n",filename);
  19796. //DEBUG_INFO("url=%s\n",url);
  19797. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  19798. if((access(FilePath,F_OK))!=-1)
  19799. {
  19800. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19801. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19802. system(rmFileCmd);
  19803. }
  19804. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  19805. if(fp == NULL)
  19806. {
  19807. DEBUG_INFO("log is NULL\n");
  19808. return FALSE;
  19809. }
  19810. else
  19811. {
  19812. fprintf(fp, "%s\n", url);
  19813. fprintf(fp, "%s\n", filename);
  19814. fclose(fp);
  19815. }
  19816. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  19817. if(phpFP == NULL)
  19818. {
  19819. DEBUG_INFO("PHP upload fail.\n");
  19820. return FALSE;
  19821. }
  19822. else
  19823. {
  19824. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19825. {
  19826. if(strstr(buf, "result") != NULL)
  19827. {
  19828. sscanf(buf, "result: %d", &systemresult);
  19829. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  19830. }
  19831. }
  19832. pclose(phpFP);
  19833. }
  19834. if(systemresult != 1)
  19835. {
  19836. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  19837. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  19838. if(phpFP == NULL)
  19839. {
  19840. DEBUG_WARN("PHP PUT upload fail.\n");
  19841. return FALSE;
  19842. }
  19843. else
  19844. {
  19845. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19846. {
  19847. if(strstr(buf, "result") != NULL)
  19848. {
  19849. sscanf(buf, "result: %d", &systemresult);
  19850. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  19851. }
  19852. }
  19853. pclose(phpFP);
  19854. }
  19855. }
  19856. if(systemresult != 1)
  19857. {
  19858. DEBUG_WARN("PHP PUT upload fail.\n");
  19859. return FALSE;
  19860. }
  19861. return TRUE;
  19862. }
  19863. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  19864. {
  19865. int result = FALSE;
  19866. char ftpbuf[200];
  19867. int systemresult;
  19868. /*
  19869. // Domaind name transfer to IP address
  19870. struct hostent* server;
  19871. char *IPbuffer;
  19872. server = gethostbyname(location);
  19873. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  19874. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19875. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  19876. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  19877. systemresult = system(ftpbuf);
  19878. if(systemresult != 0)
  19879. {
  19880. DEBUG_INFO("ftpput error!\n");
  19881. }
  19882. else
  19883. {
  19884. result = TRUE;
  19885. DEBUG_INFO("ftpput OK!\n");
  19886. }
  19887. return result;
  19888. }
  19889. int GetOcppServerURL()
  19890. {
  19891. int result = FALSE;
  19892. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  19893. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  19894. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  19895. struct yuarel url;
  19896. char urlStr[512];
  19897. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  19898. {
  19899. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  19900. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19901. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19902. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  19903. if(yuarel_parse(&url, urlStr) != -1)
  19904. {
  19905. sprintf(OcppProtocol, "%s", url.scheme);
  19906. sprintf(OcppHost, "%s", url.host);
  19907. if(url.path == NULL)
  19908. OcppTempPath[0] = '\0';
  19909. else
  19910. {
  19911. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  19912. {
  19913. sprintf(OcppTempPath, "%s/", url.path);
  19914. }
  19915. else
  19916. {
  19917. sprintf(OcppTempPath, "%s", url.path);
  19918. }
  19919. }
  19920. if(url.port == 0)
  19921. {
  19922. if(strcmp(OcppProtocol, "wss") == 0)
  19923. OcppPort = 443;
  19924. else
  19925. OcppPort = 80;
  19926. }
  19927. else
  19928. OcppPort = url.port;
  19929. result = TRUE;
  19930. }
  19931. }
  19932. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  19933. {
  19934. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  19935. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19936. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19937. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  19938. if(yuarel_parse(&url, urlStr) != -1)
  19939. {
  19940. sprintf(OcppProtocol, "%s", url.scheme);
  19941. sprintf(OcppHost, "%s", url.host);
  19942. if(url.path == NULL)
  19943. OcppTempPath[0] = '\0';
  19944. else
  19945. sprintf(OcppTempPath, "%s", url.path);
  19946. if(url.port == 0)
  19947. {
  19948. if(strcmp(OcppProtocol, "wss") == 0)
  19949. OcppPort = 443;
  19950. else
  19951. OcppPort = 80;
  19952. }
  19953. else
  19954. OcppPort = url.port;
  19955. result = TRUE;
  19956. }
  19957. }
  19958. else
  19959. {
  19960. strcpy(OcppHost,"");
  19961. }
  19962. return result;
  19963. }
  19964. int GetOcppPath()
  19965. {
  19966. int result = FALSE;
  19967. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  19968. {
  19969. if(OcppTempPath == NULL)
  19970. {
  19971. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19972. }
  19973. else
  19974. {
  19975. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19976. }
  19977. result = TRUE;
  19978. goto End;
  19979. }
  19980. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  19981. {
  19982. if(OcppTempPath == NULL)
  19983. {
  19984. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  19985. }
  19986. else
  19987. {
  19988. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  19989. }
  19990. result = TRUE;
  19991. goto End;
  19992. }
  19993. else
  19994. {
  19995. strcpy(OcppPath,"");
  19996. }
  19997. End:
  19998. return result;
  19999. }
  20000. int GetOcppPort()
  20001. {
  20002. return OcppPort;
  20003. }
  20004. int GetOcppConnStatus(void)
  20005. {
  20006. return ShmOCPP16Data->OcppConnStatus;
  20007. }
  20008. void SetOcppConnStatus(uint8_t status)
  20009. {
  20010. ShmOCPP16Data->OcppConnStatus = status;
  20011. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  20012. }
  20013. int GetHeartBeatWithNOResponse(void)
  20014. {
  20015. return HeartBeatWithNOResponse;
  20016. }
  20017. void SetHeartBeatWithNOResponse(void)
  20018. {
  20019. HeartBeatWithNOResponse = 0;
  20020. }
  20021. void GetStartTransactionIdTag(int gun_index)
  20022. {
  20023. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  20024. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  20025. }
  20026. int GetStartTransactionId(int gun_index)
  20027. {
  20028. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  20029. }
  20030. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  20031. {
  20032. char ch;
  20033. FILE *fptr1;
  20034. int temptransactionId;
  20035. char str[100]={0};
  20036. temptransactionId = 0;
  20037. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  20038. {
  20039. DEBUG_INFO("IdTag is empty.\n");
  20040. return temptransactionId;
  20041. }
  20042. /*------ Read the file ----------------*/
  20043. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  20044. if (!fptr1)
  20045. {
  20046. DEBUG_INFO("QueueTransactionId file open error.\n");
  20047. //printf(" File not found or unable to open the input file!!\n");
  20048. return temptransactionId;
  20049. }
  20050. ch=fgetc(fptr1);
  20051. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  20052. rewind(fptr1);
  20053. if(ch!=EOF)
  20054. {
  20055. // printf("%c",ch);
  20056. while (fgets(str, 100, fptr1) != NULL)
  20057. {
  20058. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  20059. if(str[0]=='\0')
  20060. {
  20061. break;
  20062. }
  20063. char *revbuf[8] = {0}; // Variable store string split
  20064. int num = 0;// Quantity after string split
  20065. DEBUG_INFO("Transaction queue data= %s\n", str);
  20066. splitstring(str,",",revbuf,&num); // String split
  20067. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  20068. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  20069. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  20070. DEBUG_INFO("------------------------------\n");
  20071. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  20072. {
  20073. if(isStopTransaction)
  20074. {
  20075. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  20076. {
  20077. temptransactionId = atoi(revbuf[2]);
  20078. //break;
  20079. }
  20080. }
  20081. else
  20082. {
  20083. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  20084. {
  20085. temptransactionId = atoi(revbuf[2]);
  20086. //break;
  20087. }
  20088. }
  20089. }
  20090. }
  20091. }
  20092. else
  20093. DEBUG_INFO("EOF\n");
  20094. fclose(fptr1);
  20095. /*------- End of reading ---------------*/
  20096. return temptransactionId;
  20097. }
  20098. void SetTransactionIdZero(int transactionId)
  20099. {
  20100. char ch;
  20101. FILE *fptr1, *fptr2;
  20102. int temptransactionId = 0;
  20103. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  20104. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  20105. if (!fptr1)
  20106. {
  20107. //printf(" File not found or unable to open the input file!!\n");
  20108. return ;
  20109. }
  20110. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  20111. if (!fptr2)
  20112. {
  20113. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  20114. fclose(fptr1);
  20115. return ;
  20116. }
  20117. ch=fgetc(fptr1);
  20118. rewind(fptr1);
  20119. if(ch!=EOF)
  20120. {
  20121. // copy all contents to the temporary file except the specific line
  20122. while (fgets(str, 100, fptr1) != NULL)
  20123. {
  20124. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  20125. if(str[0]=='\0')
  20126. {
  20127. break;
  20128. }
  20129. char *revbuf[8] = {0};
  20130. int num = 0;
  20131. strcpy(strtemp, str);
  20132. splitstring(str,",",revbuf,&num);
  20133. if(revbuf[2][0] != '\0')
  20134. {
  20135. temptransactionId = atoi(revbuf[2]);
  20136. if(transactionId != temptransactionId)
  20137. {
  20138. fprintf(fptr2, "%s\n", strtemp);
  20139. }
  20140. }
  20141. }
  20142. }
  20143. fclose(fptr1);
  20144. fclose(fptr2);
  20145. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  20146. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  20147. /*------ Read the file ----------------*/
  20148. }
  20149. int InternetDisconnect(void)
  20150. {
  20151. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  20152. }
  20153. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  20154. void storeTempStopTransaction(int gun_index)
  20155. {
  20156. char guid[37]={0};
  20157. int tempIndex = 0;
  20158. char TempStopTransaction[256];
  20159. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  20160. DEBUG_INFO("storeTempStopTransaction...\n");
  20161. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  20162. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  20163. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  20164. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  20165. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20166. {
  20167. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20168. {
  20169. tempIndex = ((gun_index==2) ? 1: 0);
  20170. }
  20171. else
  20172. {
  20173. tempIndex = gun_index;
  20174. }
  20175. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20176. {
  20177. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20178. {
  20179. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  20180. }
  20181. }// END OF CHAdeMO_QUANTITY
  20182. }
  20183. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20184. {
  20185. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20186. {
  20187. tempIndex = ((gun_index==2) ? 1: 0);
  20188. }
  20189. else
  20190. {
  20191. tempIndex = gun_index;
  20192. }
  20193. for (int index = 0; index < CCS_QUANTITY; index++)
  20194. {
  20195. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20196. {
  20197. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  20198. }
  20199. }// END OF CCS_QUANTITY
  20200. }
  20201. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20202. {
  20203. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20204. {
  20205. tempIndex = ((gun_index==2) ? 1: 0);
  20206. }
  20207. else
  20208. {
  20209. tempIndex = gun_index;
  20210. }
  20211. for (int index = 0; index < GB_QUANTITY; index++)
  20212. {
  20213. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20214. {
  20215. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  20216. }
  20217. }// END OF GB_QUANTITY
  20218. }
  20219. else if(gunType[gun_index] == GUN_TYPE_DO)
  20220. {
  20221. tempIndex = gun_index;
  20222. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20223. {
  20224. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20225. {
  20226. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  20227. }
  20228. }
  20229. }
  20230. else
  20231. {
  20232. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20233. {
  20234. tempIndex = 2;
  20235. }
  20236. else
  20237. {
  20238. tempIndex = gun_index;
  20239. }
  20240. for (int index = 0; index < AC_QUANTITY; index++)
  20241. {
  20242. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20243. {
  20244. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  20245. }
  20246. }// END OF AC_QUANTITY
  20247. }
  20248. //Stop Transaction Time
  20249. struct timeval tmnow;
  20250. struct tm *tm;
  20251. char buf[28];//, usec_buf[6];
  20252. gettimeofday(&tmnow, NULL);
  20253. time_t t;
  20254. t = time(NULL);
  20255. /*UTC time and date*/
  20256. tm = gmtime(&t);
  20257. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  20258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  20259. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  20260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  20261. random_uuid(guid);
  20262. /***********************************transactionData******************************************************/
  20263. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  20264. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  20265. //=================================
  20266. //1. Transaction_Begin
  20267. //=================================
  20268. //============================== Energy.Active.Import.Interval ===========================================
  20269. //=================================
  20270. //2. Transaction_End
  20271. //=================================
  20272. //2.1====================================== Current.Import L1 ==============================================
  20273. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  20274. {
  20275. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  20276. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20277. {
  20278. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20279. {
  20280. tempIndex = ((gun_index==2) ? 1: 0);
  20281. }
  20282. else
  20283. {
  20284. tempIndex = gun_index;
  20285. }
  20286. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20287. {
  20288. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20289. {
  20290. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  20291. }
  20292. }// End of for CHAdeMO_QUANTITY
  20293. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  20294. }
  20295. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20296. {
  20297. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20298. {
  20299. tempIndex = ((gun_index==2) ? 1: 0);
  20300. }
  20301. else
  20302. {
  20303. tempIndex = gun_index;
  20304. }
  20305. for (int index = 0; index < CCS_QUANTITY; index++)
  20306. {
  20307. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20308. {
  20309. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  20310. }
  20311. }// End of for CCS_QUANTITY
  20312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  20313. }
  20314. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20315. {
  20316. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20317. {
  20318. tempIndex = ((gun_index==2) ? 1: 0);
  20319. }
  20320. else
  20321. {
  20322. tempIndex = gun_index;
  20323. }
  20324. for (int index = 0; index < GB_QUANTITY; index++)
  20325. {
  20326. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20327. {
  20328. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  20329. }
  20330. }// End of for GB_QUANTITY
  20331. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  20332. }
  20333. else if(gunType[gun_index] == GUN_TYPE_DO)
  20334. {
  20335. tempIndex = gun_index;
  20336. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20337. {
  20338. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20339. {
  20340. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  20341. }
  20342. }
  20343. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  20344. }
  20345. else
  20346. {
  20347. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20348. {
  20349. tempIndex = 2;
  20350. }
  20351. else
  20352. {
  20353. tempIndex = gun_index;
  20354. }
  20355. for (int index = 0; index < AC_QUANTITY; index++)
  20356. {
  20357. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20358. {
  20359. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  20360. }
  20361. }// End of for AC_QUANTITY
  20362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  20363. }
  20364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20365. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  20366. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  20367. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  20368. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  20369. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  20370. }
  20371. //2.2===================================== Energy.Active.Import.Interval ==========================================
  20372. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  20373. {
  20374. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20375. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20376. {
  20377. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20378. {
  20379. tempIndex = ((gun_index==2) ? 1: 0);
  20380. }
  20381. else
  20382. {
  20383. tempIndex = gun_index;
  20384. }
  20385. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20386. {
  20387. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20388. {
  20389. 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
  20390. }
  20391. }// END OF CHAdeMO_QUANTITY
  20392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  20393. }
  20394. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20395. {
  20396. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20397. {
  20398. tempIndex = ((gun_index==2) ? 1: 0);
  20399. }
  20400. else
  20401. {
  20402. tempIndex = gun_index;
  20403. }
  20404. for (int index = 0; index < CCS_QUANTITY; index++)
  20405. {
  20406. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20407. {
  20408. 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
  20409. }
  20410. }// END OF CCS_QUANTITY
  20411. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  20412. }
  20413. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20414. {
  20415. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20416. {
  20417. tempIndex = ((gun_index==2) ? 1: 0);
  20418. }
  20419. else
  20420. {
  20421. tempIndex = gun_index;
  20422. }
  20423. for (int index = 0; index < GB_QUANTITY; index++)
  20424. {
  20425. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20426. {
  20427. 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
  20428. }
  20429. }// END OF GB_QUANTITY
  20430. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  20431. }
  20432. else if(gunType[gun_index] == GUN_TYPE_DO)
  20433. {
  20434. tempIndex = gun_index;
  20435. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20436. {
  20437. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20438. {
  20439. 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
  20440. }
  20441. }
  20442. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  20443. }
  20444. else
  20445. {
  20446. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20447. {
  20448. tempIndex = 2;
  20449. }
  20450. else
  20451. {
  20452. tempIndex = gun_index;
  20453. }
  20454. for (int index = 0; index < AC_QUANTITY; index++)
  20455. {
  20456. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20457. {
  20458. 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
  20459. }
  20460. }// END OF AC_QUANTITY
  20461. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  20462. }
  20463. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20464. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  20465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  20466. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  20467. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  20468. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  20469. }
  20470. //2.3====================================== Power.Active.Import =========================================
  20471. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  20472. {
  20473. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20474. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20475. {
  20476. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20477. {
  20478. tempIndex = ((gun_index==2) ? 1: 0);
  20479. }
  20480. else
  20481. {
  20482. tempIndex = gun_index;
  20483. }
  20484. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20485. {
  20486. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20487. {
  20488. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20489. }
  20490. } // End for CHAdeMO_QUANTITY
  20491. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  20492. }
  20493. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20494. {
  20495. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20496. {
  20497. tempIndex = ((gun_index==2) ? 1: 0);
  20498. }
  20499. else
  20500. {
  20501. tempIndex = gun_index;
  20502. }
  20503. for (int index = 0; index < CCS_QUANTITY; index++)
  20504. {
  20505. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20506. {
  20507. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20508. }
  20509. } // END for CCS_QUANTITY
  20510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  20511. }
  20512. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20513. {
  20514. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20515. {
  20516. tempIndex = ((gun_index==2) ? 1: 0);
  20517. }
  20518. else
  20519. {
  20520. tempIndex = gun_index;
  20521. }
  20522. for (int index = 0; index < GB_QUANTITY; index++)
  20523. {
  20524. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20525. {
  20526. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20527. }
  20528. }// END for GB_QUANTITY
  20529. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  20530. }
  20531. else if(gunType[gun_index] == GUN_TYPE_DO)
  20532. {
  20533. tempIndex = gun_index;
  20534. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20535. {
  20536. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20537. {
  20538. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20539. }
  20540. }
  20541. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  20542. }
  20543. else
  20544. {
  20545. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20546. {
  20547. tempIndex = 2;
  20548. }
  20549. else
  20550. {
  20551. tempIndex = gun_index;
  20552. }
  20553. for (int index = 0; index < AC_QUANTITY; index++)
  20554. {
  20555. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20556. {
  20557. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20558. }
  20559. } // END for AC_QUANTITY
  20560. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  20561. }
  20562. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20563. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  20564. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  20565. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  20566. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  20567. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  20568. }
  20569. //2.4====================================== Voltage L1 ====================================================
  20570. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  20571. {
  20572. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20573. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20574. {
  20575. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20576. {
  20577. tempIndex = ((gun_index==2) ? 1: 0);
  20578. }
  20579. else
  20580. {
  20581. tempIndex = gun_index;
  20582. }
  20583. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20584. {
  20585. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20586. {
  20587. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  20588. }
  20589. } // END OF FOR CHAdeMO_QUANTITY
  20590. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  20591. }
  20592. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20593. {
  20594. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20595. {
  20596. tempIndex = ((gun_index==2) ? 1: 0);
  20597. }
  20598. else
  20599. {
  20600. tempIndex = gun_index;
  20601. }
  20602. for (int index = 0; index < CCS_QUANTITY; index++)
  20603. {
  20604. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20605. {
  20606. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  20607. }
  20608. } // END OF FOR CCS_QUANTITY
  20609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  20610. }
  20611. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20612. {
  20613. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20614. {
  20615. tempIndex = ((gun_index==2) ? 1: 0);
  20616. }
  20617. else
  20618. {
  20619. tempIndex = gun_index;
  20620. }
  20621. for (int index = 0; index < GB_QUANTITY; index++)
  20622. {
  20623. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20624. {
  20625. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  20626. }
  20627. } // END OF FOR GB_QUANTITY
  20628. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  20629. }
  20630. else if(gunType[gun_index] == GUN_TYPE_DO)
  20631. {
  20632. tempIndex = gun_index;
  20633. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20634. {
  20635. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20636. {
  20637. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  20638. }
  20639. }
  20640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  20641. }
  20642. else
  20643. {
  20644. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20645. {
  20646. tempIndex = 2;
  20647. }
  20648. else
  20649. {
  20650. tempIndex = gun_index;
  20651. }
  20652. for (int index = 0; index < AC_QUANTITY; index++)
  20653. {
  20654. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20655. {
  20656. 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
  20657. }
  20658. } // END OF FOR AC_QUANTITY
  20659. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  20660. }
  20661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  20663. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  20664. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  20665. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  20666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  20667. }
  20668. //2.5============================================== End SoC =========================================================
  20669. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  20670. {
  20671. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20672. 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))
  20673. {
  20674. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  20675. {
  20676. tempIndex = ((gun_index==2) ? 1: 0);
  20677. }
  20678. else
  20679. {
  20680. tempIndex = gun_index;
  20681. }
  20682. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20683. {
  20684. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20685. {
  20686. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20687. {
  20688. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  20689. }
  20690. }
  20691. }
  20692. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20693. {
  20694. for (int index = 0; index < CCS_QUANTITY; index++)
  20695. {
  20696. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20697. {
  20698. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  20699. }
  20700. }
  20701. }
  20702. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20703. {
  20704. for (int index = 0; index < GB_QUANTITY; index++)
  20705. {
  20706. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20707. {
  20708. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  20709. }
  20710. }
  20711. }
  20712. else if(gunType[gun_index] == GUN_TYPE_DO)
  20713. {
  20714. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20715. {
  20716. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20717. {
  20718. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  20719. }
  20720. }
  20721. }
  20722. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  20724. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  20725. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  20726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  20727. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  20728. } // END FOR DC CASE
  20729. }
  20730. //2.6====================================== Current.Import L2 ==============================================
  20731. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  20732. {
  20733. // AC 3 phase L2 current
  20734. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  20735. {
  20736. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20737. {
  20738. tempIndex = 2;
  20739. }
  20740. else
  20741. {
  20742. tempIndex = gun_index;
  20743. }
  20744. for (int index = 0; index < AC_QUANTITY; index++)
  20745. {
  20746. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20747. {
  20748. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  20749. }
  20750. }// End of for AC_QUANTITY
  20751. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  20752. }
  20753. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20754. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  20755. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  20756. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  20757. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  20758. }
  20759. //2.7====================================== Current.Import L3 ==============================================
  20760. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  20761. {
  20762. // AC 3 phase L3 current
  20763. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  20764. {
  20765. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20766. {
  20767. tempIndex = 2;
  20768. }
  20769. else
  20770. {
  20771. tempIndex = gun_index;
  20772. }
  20773. for (int index = 0; index < AC_QUANTITY; index++)
  20774. {
  20775. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20776. {
  20777. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  20778. }
  20779. }// End of for AC_QUANTITY
  20780. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  20781. }
  20782. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20783. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  20784. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  20785. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  20786. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  20787. }
  20788. //2.9====================================== Voltage L2 ====================================================
  20789. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  20790. {
  20791. // AC 3 phase L2 volatge
  20792. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  20793. {
  20794. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20795. {
  20796. tempIndex = 2;
  20797. }
  20798. else
  20799. {
  20800. tempIndex = gun_index;
  20801. }
  20802. for (int index = 0; index < AC_QUANTITY; index++)
  20803. {
  20804. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20805. {
  20806. 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
  20807. }
  20808. } // END OF FOR AC_QUANTITY
  20809. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  20810. }
  20811. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20812. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  20813. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  20814. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  20815. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  20816. }
  20817. //2.10====================================== Voltage L3 ====================================================
  20818. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  20819. {
  20820. // AC 3 phase L3 volatge
  20821. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  20822. {
  20823. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20824. {
  20825. tempIndex = 2;
  20826. }
  20827. else
  20828. {
  20829. tempIndex = gun_index;
  20830. }
  20831. for (int index = 0; index < AC_QUANTITY; index++)
  20832. {
  20833. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20834. {
  20835. 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
  20836. }
  20837. } // END OF FOR AC_QUANTITY
  20838. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  20839. }
  20840. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20841. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  20842. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  20843. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  20844. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  20845. }
  20846. //====================== Start SoC ================================
  20847. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  20848. {
  20849. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20850. 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))
  20851. {
  20852. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  20853. {
  20854. tempIndex = ((gun_index==2) ? 1: 0);
  20855. }
  20856. else
  20857. {
  20858. tempIndex = gun_index;
  20859. }
  20860. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20861. {
  20862. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20863. {
  20864. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20865. {
  20866. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  20867. }
  20868. }
  20869. }
  20870. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20871. {
  20872. for (int index = 0; index < CCS_QUANTITY; index++)
  20873. {
  20874. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20875. {
  20876. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  20877. }
  20878. }
  20879. }
  20880. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20881. {
  20882. for (int index = 0; index < GB_QUANTITY; index++)
  20883. {
  20884. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20885. {
  20886. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  20887. }
  20888. }
  20889. }
  20890. else if(gunType[gun_index] == GUN_TYPE_DO)
  20891. {
  20892. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20893. {
  20894. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20895. {
  20896. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  20897. }
  20898. }
  20899. }
  20900. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  20901. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  20902. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  20903. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  20904. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  20905. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  20906. } // END FOR DC CASE
  20907. }
  20908. //======================================== Message create ==============================================
  20909. json_object *StopTransaction = json_object_new_object();
  20910. json_object *transactionDatas = json_object_new_array();
  20911. json_object *sampledValues = json_object_new_array();
  20912. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  20913. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  20914. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  20915. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  20916. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  20917. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  20918. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  20919. {
  20920. json_object *transactionData = json_object_new_object();
  20921. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  20922. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  20923. {
  20924. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  20925. {
  20926. json_object *sampledValue = json_object_new_object();
  20927. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  20928. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  20929. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  20930. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  20931. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  20932. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  20933. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  20934. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  20935. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  20936. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  20937. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  20938. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  20939. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  20940. json_object_array_add(sampledValues, sampledValue);
  20941. }
  20942. }
  20943. json_object_object_add(transactionData, "sampledValue", sampledValues);
  20944. json_object_array_add(transactionDatas, transactionData);
  20945. }
  20946. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  20947. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  20948. ,MESSAGE_TYPE_CALL
  20949. ,guid
  20950. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  20951. json_object_put(StopTransaction);
  20952. // Check File "TempStopTransaction" Exist
  20953. if((access(TempStopTransaction,F_OK))!=-1)
  20954. {
  20955. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  20956. fclose(fopen(TempStopTransaction, "w"));
  20957. }
  20958. else
  20959. {
  20960. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  20961. FILE *log = fopen(TempStopTransaction, "w+");
  20962. if(log == NULL)
  20963. {
  20964. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  20965. return ;
  20966. }
  20967. else
  20968. {
  20969. fclose(log);
  20970. }
  20971. }
  20972. //Add TempStopTransaction | Update TempStopTransaction
  20973. // open file for writing
  20974. FILE *outfile;
  20975. outfile = fopen (TempStopTransaction, "a");
  20976. //DEBUG_INFO("data = %s\n", queuedata);
  20977. fputs(queuedata, outfile);
  20978. fputs("\n", outfile);
  20979. fclose (outfile);
  20980. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  20981. OCPP_updatePeriodEnergy(gun_index);
  20982. }
  20983. void checkTempStopTransaction(int gun_index)
  20984. {
  20985. FILE *fptr1;
  20986. char ch;
  20987. char str[QUEUE_MESSAGE_LENGTH]={0};
  20988. char guid[37]={0};
  20989. char tempdata[65]={0};
  20990. char connectorStr[2]={0};
  20991. char TempStopTransaction[256];
  20992. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  20993. fptr1 = fopen(TempStopTransaction, "r");
  20994. //TempStopTransaction格式: 槍號,StopTransaction封包
  20995. if (!fptr1)
  20996. {
  20997. //printf(" File not found or unable to open the input file!!\n");
  20998. return ;
  20999. }
  21000. ch=fgetc(fptr1);
  21001. //printf(" Now the content of the file %s is : \n",fname);
  21002. rewind(fptr1);
  21003. if(ch!=EOF)
  21004. {
  21005. // copy all contents to the temporary file except the specific line
  21006. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  21007. {
  21008. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  21009. if(str[0]=='\0')
  21010. {
  21011. break;
  21012. }
  21013. //TempStopTransaction格式: 槍號,StopTransaction封包
  21014. strncpy(connectorStr, str, 1);
  21015. if(atoi(connectorStr) != (gun_index+1))
  21016. {
  21017. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  21018. fclose(fptr1);
  21019. return ;
  21020. }
  21021. //random_uuid(guid);
  21022. strncpy(guid, str+6, 36); //copy guid
  21023. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  21024. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  21025. {
  21026. //DEBUG_INFO("StopTransaction mapitem pass\n");
  21027. }
  21028. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  21029. OCPP_insert_transaction_msg(NO, str);
  21030. memset(str,0,ARRAY_SIZE(str));
  21031. }
  21032. }
  21033. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  21034. fclose(fptr1);
  21035. remove(TempStopTransaction); // remove the original file
  21036. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  21037. }
  21038. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  21039. {
  21040. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  21041. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  21042. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  21043. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  21044. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  21045. }
  21046. void FillTransactionId(int ConnectorId, int TransactionId)
  21047. {
  21048. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  21049. ShmOCPP16Data->StartTransaction[ConnectorId-1].ResponseTransactionId = TransactionId;
  21050. }
  21051. int GetWebSocketPingInterval(void)
  21052. {
  21053. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  21054. }
  21055. int GetServerSign(void)
  21056. {
  21057. return server_sign;
  21058. }
  21059. uint8_t GetOcppSecurityProfile()
  21060. {
  21061. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  21062. }
  21063. void MergeCertificates()
  21064. {
  21065. char cmdBuf[2048]={0};
  21066. if(access(ROOTCA_CS,F_OK) != -1)
  21067. {
  21068. sprintf(cmdBuf, "cat /root/cacert.pem %s > /root/certCA.pem", ROOTCA_CS);
  21069. }
  21070. else
  21071. {
  21072. sprintf(cmdBuf, "cat /root/cacert.pem > /root/certCA.pem");
  21073. }
  21074. system(cmdBuf);
  21075. }
  21076. void GetOcppChargerBoxId(uint8_t *data)
  21077. {
  21078. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  21079. }
  21080. void GetOcppSecurityPassword(uint8_t *data)
  21081. {
  21082. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  21083. }
  21084. void SetOcppVersion(uint8_t *version)
  21085. {
  21086. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  21087. DEBUG_INFO("ocpp version: %s\n", version);
  21088. if(strstr((char*)version, "ocpp1.6") != NULL)
  21089. {
  21090. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  21091. }
  21092. else if(strstr((char*)version, "ocpp2.0") != NULL)
  21093. {
  21094. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  21095. system("pkill OcppBackend");
  21096. }
  21097. }
  21098. void SetServerSign(int value)
  21099. {
  21100. server_sign = value;
  21101. }
  21102. int GetBootNotificationInterval(void)
  21103. {
  21104. return BootNotificationInterval;
  21105. }
  21106. int GetInternetConn(void)
  21107. {
  21108. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  21109. }
  21110. int GetBackendConnectionTimeout(void)
  21111. {
  21112. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  21113. }
  21114. int isConnectorInitMode(int gun_index)
  21115. {
  21116. int tempIndex = 0;
  21117. int result = TRUE;
  21118. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  21119. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  21120. {
  21121. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  21122. {
  21123. tempIndex = ((gun_index==2) ? 1: 0);
  21124. }
  21125. else
  21126. {
  21127. tempIndex = gun_index;
  21128. }
  21129. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  21130. {
  21131. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  21132. {
  21133. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  21134. } //end of the same index
  21135. }//end of for CHAdeMO_QUANTITY
  21136. }
  21137. else if(gunType[gun_index] == GUN_TYPE_CCS)
  21138. {
  21139. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  21140. {
  21141. tempIndex = ((gun_index==2) ? 1: 0);
  21142. }
  21143. else
  21144. {
  21145. tempIndex = gun_index;
  21146. }
  21147. for (int index = 0; index < CCS_QUANTITY; index++)
  21148. {
  21149. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  21150. {
  21151. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  21152. } //end of the same index
  21153. } // end of for CCS_QUANTITY
  21154. }
  21155. else if(gunType[gun_index] == GUN_TYPE_GBT)
  21156. {
  21157. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  21158. {
  21159. tempIndex = ((gun_index==2) ? 1: 0);
  21160. }
  21161. else
  21162. {
  21163. tempIndex = gun_index;
  21164. }
  21165. for (int index = 0; index < GB_QUANTITY; index++)
  21166. {
  21167. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  21168. {
  21169. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  21170. } //end of the same index
  21171. } // end of for GB_QUANTITY
  21172. }
  21173. else if(gunType[gun_index] == GUN_TYPE_DO)
  21174. {
  21175. tempIndex = gun_index;
  21176. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  21177. {
  21178. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  21179. {
  21180. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  21181. } //end of the same index
  21182. }
  21183. }
  21184. else
  21185. {
  21186. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  21187. {
  21188. tempIndex = 2;
  21189. }
  21190. else
  21191. {
  21192. tempIndex = gun_index;
  21193. }
  21194. for (int index = 0; index < AC_QUANTITY; index++)
  21195. {
  21196. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  21197. {
  21198. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  21199. }//end of the same index
  21200. }//end of for AC_QUANTITY
  21201. }
  21202. return result;
  21203. }
  21204. void refreshProcDogTimer()
  21205. {
  21206. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  21207. }
  21208. void InitialSystemValue(void)
  21209. {
  21210. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  21211. locallistVersion=0;
  21212. BootNotificationInterval = 0;
  21213. authorizeRetryTimes = 0;
  21214. GunStatusInterval = 10;
  21215. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  21216. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  21217. //Hear Beat
  21218. HeartBeatWithNOResponse = 0;
  21219. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  21220. FirstHeartBeat = 0;
  21221. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  21222. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  21223. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  21224. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  21225. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  21226. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  21227. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  21228. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  21229. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  21230. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  21231. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  21232. //Status && ConnectorPlugIn Setting
  21233. Connector0PreviousSystemStatus = 99;
  21234. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  21235. {
  21236. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  21237. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  21238. }
  21239. for (int index = 0; index < CCS_QUANTITY; index++)
  21240. {
  21241. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  21242. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  21243. }
  21244. for (int index = 0; index < GB_QUANTITY; index++)
  21245. {
  21246. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  21247. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  21248. }
  21249. for (int index = 0; index < AC_QUANTITY; index++)
  21250. {
  21251. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  21252. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  21253. }
  21254. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  21255. {
  21256. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  21257. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  21258. }
  21259. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  21260. {
  21261. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  21262. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  21263. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  21264. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  21265. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  21266. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  21267. }
  21268. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  21269. refreshStartTimer(&clientTime.Heartbeat);
  21270. sleep(1);
  21271. }
  21272. void LWS_Send(char *str)
  21273. {
  21274. //=====================================================
  21275. // Check InternetConn 0: disconnected, 1: connected
  21276. //====================================================
  21277. if(GetOcppConnStatus() == 0)
  21278. {
  21279. DEBUG_INFO("offline now !!!\n");
  21280. return;
  21281. }
  21282. // Only disable isWebsocketSendable operation initiated by charger
  21283. if((strstr((char*)str, "\"Authorize\"") != NULL)
  21284. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  21285. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  21286. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  21287. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  21288. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  21289. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  21290. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  21291. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  21292. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  21293. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  21294. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  21295. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  21296. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  21297. {
  21298. isWebsocketSendable = 0;
  21299. }
  21300. pthread_mutex_lock(&lock_send);
  21301. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  21302. sprintf((char *)SendBuffer, "%s", str);
  21303. SendBufLen = strlen(str);
  21304. pthread_mutex_unlock(&lock_send);
  21305. lws_callback_on_writable(wsi_client);
  21306. //lws_service(context, 0);
  21307. //sleep(1);
  21308. }
  21309. void LWS_SendNow(char *str)
  21310. {
  21311. //=====================================================
  21312. // Check InternetConn 0: disconnected, 1: connected
  21313. //====================================================
  21314. if(GetOcppConnStatus() == 0)
  21315. {
  21316. DEBUG_INFO("offline now !!!\n");
  21317. return;
  21318. }
  21319. // Only disable isWebsocketSendable operation initiated by charger
  21320. if((strstr((char*)str, "\"Authorize\"") != NULL)
  21321. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  21322. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  21323. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  21324. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  21325. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  21326. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  21327. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  21328. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  21329. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  21330. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  21331. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  21332. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  21333. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  21334. {
  21335. isWebsocketSendable = 0;
  21336. }
  21337. pthread_mutex_lock(&lock_send);
  21338. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  21339. sprintf((char *)SendBuffer, "%s", str);
  21340. SendBufLen = strlen(str);
  21341. pthread_mutex_unlock(&lock_send);
  21342. lws_callback_on_writable(wsi_client);
  21343. lws_service(context, 0);
  21344. //sleep(1);
  21345. }