MessageHandler.c 1.0 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957
  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 = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  54. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  55. //========================================
  56. // OCPP status/previous related variables
  57. //========================================
  58. static int GunStatusInterval = 10;
  59. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  60. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  61. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  62. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  63. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  64. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  65. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  66. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  67. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  68. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  69. static int TransactionMessageAttemptsValue = 0;
  70. static int TransactionMessageRetryIntervalValue = 0;
  71. static int TempMeterValueInterval = 0;
  72. static struct OCPPAuthLocalElemet
  73. {
  74. int listVersionInt;
  75. char idTagstr[21];
  76. char parentIdTag[21];
  77. char expiryDate[36];
  78. char idTagstatus[16];
  79. }idTagQuery;
  80. //============================================
  81. // OCPP MeterValue request flag
  82. //============================================
  83. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  84. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  85. //============================================
  86. // OCPP HeartBeat Response Not Receive Counts
  87. //============================================
  88. static int HeartBeatWithNOResponse = 0;
  89. //============================================
  90. // OCPP California Pricing Requirements
  91. //============================================
  92. static char dmsVersion[21] = {0};
  93. extern sqlite3 *db;
  94. int TransactionMessageAttemptsGet(void);
  95. int TransactionMessageRetryIntervalGet(void);
  96. int GetOcppConnStatus(void);
  97. void SetOcppConnStatus(uint8_t status);
  98. int setKeyValue(char *key, char *value);
  99. void OCPP_get_TableAuthlocalAllData(void);
  100. void processUnkownKey(void);
  101. struct InterLock
  102. {
  103. unsigned char isSentUnplug[CONNECTOR_QUANTITY];
  104. unsigned char isGetDiagnosticGoing:1;
  105. unsigned char isUpdateFirmwareGoing:1;
  106. }interLock;
  107. struct ClientTime
  108. {
  109. struct timespec Heartbeat;
  110. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  111. struct timespec StartTransaction;
  112. struct timespec StopTransaction;
  113. struct timespec MeterValues[CONNECTOR_QUANTITY];
  114. struct timespec RemoteStartWait;
  115. struct timespec TcciQueryDeduct;
  116. struct timespec CharingProfileRefresh[CONNECTOR_QUANTITY];
  117. }clientTime;
  118. typedef union
  119. {
  120. //Operations Initiated by Central System
  121. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  122. struct
  123. {
  124. //CsMsgValue[0]
  125. unsigned char StatusNotificationReq:1; //bit 0,
  126. unsigned char StatusNotificationConf:1; //bit 1,
  127. unsigned char TriggerMeterValue:1; //bit 2,
  128. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  129. unsigned char isOnCharging:1; //bit 4,
  130. unsigned char :3; //bit5~7
  131. }bits[CONNECTOR_QUANTITY];
  132. }CpinitiateMsg;
  133. CpinitiateMsg cpinitateMsg;
  134. //GetConfiguration Array
  135. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  136. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  137. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  138. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  139. static char *ChargePointErrorCodeStr[] = {
  140. MACROSTR(ConnectorLockFailure),
  141. MACROSTR(EVCommunicationError),
  142. MACROSTR(GroundFailure),
  143. MACROSTR(HighTemperature),
  144. MACROSTR(InternalError),
  145. MACROSTR(LocalListConflict),
  146. MACROSTR(NoError),
  147. MACROSTR(OtherError),
  148. MACROSTR(OverCurrentFailure),
  149. MACROSTR(OverVoltage),
  150. MACROSTR(PowerMeterFailure),
  151. MACROSTR(PowerSwitchFailure),
  152. MACROSTR(ReaderFailure),
  153. MACROSTR(ResetFailure),
  154. MACROSTR(UnderVoltage),
  155. MACROSTR(WeakSignal)
  156. };
  157. static char * ChargePointStatusStr[] = {
  158. MACROSTR(Available),
  159. MACROSTR(Preparing),
  160. MACROSTR(Charging),
  161. MACROSTR(SuspendedEVSE),
  162. MACROSTR(SuspendedEV),
  163. MACROSTR(Finishing),
  164. MACROSTR(Reserved),
  165. MACROSTR(Unavailable),
  166. MACROSTR(Faulted)
  167. };
  168. static char *RegistrationStatusStr[] = {
  169. MACROSTR(Accepted),
  170. MACROSTR(Pending),
  171. MACROSTR(Rejected)
  172. };
  173. static char *AvailabilityTypeStr[] = {
  174. MACROSTR(Inoperative),
  175. MACROSTR(Operative)
  176. };
  177. static char *AvailabilityStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected),
  180. MACROSTR(Scheduled)
  181. };
  182. static char *ConfigurationStatusStr[] = {
  183. MACROSTR(Accepted),
  184. MACROSTR(Rejected),
  185. MACROSTR(RebootRequired),
  186. MACROSTR(NotSupported)
  187. };
  188. static char *ClearCacheStatusStr[] = {
  189. MACROSTR(Accepted),
  190. MACROSTR(Rejected)
  191. };
  192. static char *ChargingProfilePurposeTypeStr[] = {
  193. MACROSTR(ChargePointMaxProfile),
  194. MACROSTR(TxDefaultProfile),
  195. MACROSTR(TxProfile)
  196. };
  197. static char *ChargingProfileStatusStr[] = {
  198. MACROSTR(Accepted),
  199. MACROSTR(Rejected),
  200. MACROSTR(NotSupported)
  201. };
  202. static char *ClearChargingProfileStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Unknown)
  205. };
  206. static char *GetCompositeScheduleStatusStr[] = {
  207. MACROSTR(Accepted),
  208. MACROSTR(Rejected)
  209. };
  210. static char *UpdateTypeStr[] = {
  211. MACROSTR(Differential),
  212. MACROSTR(Full)
  213. };
  214. static char *UpdateStatusStr[] = {
  215. MACROSTR(Accepted),
  216. MACROSTR(Failed),
  217. MACROSTR(NotSupported),
  218. MACROSTR(VersionMismatch)
  219. };
  220. static char *RemoteStartStopStatusStr[] = {
  221. MACROSTR(Accepted),
  222. MACROSTR(Rejected)
  223. };
  224. static char *ReservationStatusStr[] = {
  225. MACROSTR(Accepted),
  226. MACROSTR(Faulted),
  227. MACROSTR(Occupied),
  228. MACROSTR(Rejected),
  229. MACROSTR(Unavailable)
  230. };
  231. static char *ResetTypeStr[] = {
  232. MACROSTR(Hard),
  233. MACROSTR(Soft)
  234. };
  235. static char *ResetStatusStr[] = {
  236. MACROSTR(Accepted),
  237. MACROSTR(Rejected)
  238. };
  239. static char * DiagnosticsStatusStr[] = {
  240. MACROSTR(Idle),
  241. MACROSTR(Uploaded),
  242. MACROSTR(UploadFailed),
  243. MACROSTR(Uploading)
  244. };
  245. static char * FirmwareStatusStr[] = {
  246. MACROSTR(Downloaded),
  247. MACROSTR(DownloadFailed),
  248. MACROSTR(Downloading),
  249. MACROSTR(Idle),
  250. MACROSTR(InstallationFailed),
  251. MACROSTR(Installing),
  252. MACROSTR(Installed)
  253. };
  254. static char * MessageTriggerStr[] = {
  255. MACROSTR(BootNotification),
  256. MACROSTR(DiagnosticsStatusNotification),
  257. MACROSTR(FirmwareStatusNotification),
  258. MACROSTR(Heartbeat),
  259. MACROSTR(MeterValues),
  260. MACROSTR(StatusNotification)
  261. };
  262. static char * TriggerMessageStatusStr[] = {
  263. MACROSTR(Accepted),
  264. MACROSTR(Rejected),
  265. MACROSTR(NotImplemented)
  266. };
  267. static char * UnlockStatusStr[] = {
  268. MACROSTR(Unlocked),
  269. MACROSTR(UnlockFailed),
  270. MACROSTR(NotSupported)
  271. };
  272. #if 0
  273. static char * StopTransactionReasonStr[] = {
  274. MACROSTR(EmergencyStop),
  275. MACROSTR(EVDisconnected),
  276. MACROSTR(HardReset),
  277. MACROSTR(Local),
  278. MACROSTR(Other),
  279. MACROSTR(PowerLoss),
  280. MACROSTR(Reboot),
  281. MACROSTR(Remote),
  282. MACROSTR(SoftReset),
  283. MACROSTR(UnlockCommand),
  284. MACROSTR(DeAuthorized)
  285. };
  286. #endif
  287. static char * CancelReservationStatusStr[] = {
  288. MACROSTR(Accepted),
  289. MACROSTR(Rejected)
  290. };
  291. static char * ReadingContextStr[] = {
  292. MACROSTR(Interruption.Begin),
  293. MACROSTR(Interruption.End),
  294. MACROSTR(Other),
  295. MACROSTR(Sample.Clock),
  296. MACROSTR(Sample.Periodic),
  297. MACROSTR(Transaction.Begin),
  298. MACROSTR(Transaction.End),
  299. MACROSTR(Trigger)
  300. };
  301. static char * ValueFormatStr[] = {
  302. MACROSTR(Raw),
  303. MACROSTR(SignedData)
  304. };
  305. static char * MeasurandStr[] = {
  306. MACROSTR(Current.Export),
  307. MACROSTR(Current.Import),
  308. MACROSTR(Current.Offered),
  309. MACROSTR(Energy.Active.Export.Register),
  310. MACROSTR(Energy.Active.Import.Register),
  311. MACROSTR(Energy.Reactive.Export.Register),
  312. MACROSTR(Energy.Reactive.Import.Register),
  313. MACROSTR(Energy.Active.Export.Interval),
  314. MACROSTR(Energy.Active.Import.Interval),
  315. MACROSTR(Energy.Reactive.Export.Interval),
  316. MACROSTR(Energy.Reactive.Import.Interval),
  317. MACROSTR(Frequency),
  318. MACROSTR(Power.Active.Export),
  319. MACROSTR(Power.Active.Import),
  320. MACROSTR(Power.Factor),
  321. MACROSTR(Power.Offered),
  322. MACROSTR(Power.Reactive.ExportMACROSTR),
  323. MACROSTR(Power.Reactive.Import),
  324. MACROSTR(RPM),
  325. MACROSTR(SoC),
  326. MACROSTR(Temperature),
  327. MACROSTR(Voltage)
  328. };
  329. static char * LocationStr[] = {
  330. MACROSTR(Body),
  331. MACROSTR(Cable),
  332. MACROSTR(EV),
  333. MACROSTR(Inlet),
  334. MACROSTR(Outlet)
  335. };
  336. static char * PhaseStr[] = {
  337. MACROSTR(L1),
  338. MACROSTR(L2),
  339. MACROSTR(L3),
  340. MACROSTR(N),
  341. MACROSTR(L1-N),
  342. MACROSTR(L2-N),
  343. MACROSTR(L3-N),
  344. MACROSTR(L1-L2),
  345. MACROSTR(L2-L3),
  346. MACROSTR(L3-L1)
  347. };
  348. static char * UnitOfMeasureStr[] = {
  349. MACROSTR(Wh),
  350. MACROSTR(kWh),
  351. MACROSTR(varh),
  352. MACROSTR(kvarh),
  353. MACROSTR(W),
  354. MACROSTR(kW),
  355. MACROSTR(VA),
  356. MACROSTR(kVA),
  357. MACROSTR(var),
  358. MACROSTR(kvar),
  359. MACROSTR(A),
  360. MACROSTR(V),
  361. MACROSTR(Celsius),
  362. MACROSTR(Fahrenheit),
  363. MACROSTR(K),
  364. MACROSTR(Percent)
  365. };
  366. //=========================================
  367. // Certificate related routine
  368. //=========================================
  369. int certVerify(char *privateKey, char *cert)
  370. {
  371. int result = PASS;
  372. SSL_CTX *ctx = SSL_CTX_new(TLS_method());
  373. // Load certificate file
  374. if(SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM) <= 0)
  375. {
  376. DEBUG_ERROR("Load certificate error!\n");
  377. result = FAIL;
  378. }
  379. // Load private key file
  380. if(SSL_CTX_use_PrivateKey_file(ctx, privateKey, SSL_FILETYPE_PEM) <= 0)
  381. {
  382. DEBUG_ERROR("Load private key error!\n");
  383. result = FAIL;
  384. }
  385. if(!SSL_CTX_check_private_key(ctx))
  386. {
  387. result = FAIL;
  388. }
  389. SSL_CTX_free(ctx);
  390. return result;
  391. }
  392. //=========================================
  393. // TTIA routine
  394. //=========================================
  395. int sendTTIAInfo(uint8_t gun_index)
  396. {
  397. static int sn = 0;
  398. int result = FAIL;
  399. struct hostent *server;
  400. int udp_socket_fd;
  401. struct sockaddr_in dest_addr = {0};
  402. uint8_t tx_buf[80] = {0};
  403. uint8_t logBuf[256]= {0};
  404. uint8_t tx_len, tempIndex, socStart, socEnd;
  405. uint16_t PresentChargedEnergy;
  406. struct tm tmStart, tmEnd;
  407. DEBUG_INFO("sendTTIAInfo...\n");
  408. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  409. {
  410. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  411. {
  412. tempIndex = ((gun_index==2) ? 1: 0);
  413. }
  414. else
  415. {
  416. tempIndex = gun_index;
  417. }
  418. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  419. {
  420. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  421. {
  422. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  423. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  424. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  425. }
  426. }
  427. }
  428. else if(gunType[gun_index] == GUN_TYPE_CCS)
  429. {
  430. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  431. {
  432. tempIndex = ((gun_index==2) ? 1: 0);
  433. }
  434. else
  435. {
  436. tempIndex = gun_index;
  437. }
  438. for (int index = 0; index < CCS_QUANTITY; index++)
  439. {
  440. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  441. {
  442. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  443. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  444. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  445. }
  446. }
  447. }
  448. else if(gunType[gun_index] == GUN_TYPE_GBT)
  449. {
  450. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  451. {
  452. tempIndex = ((gun_index==2) ? 1: 0);
  453. }
  454. else
  455. {
  456. tempIndex = gun_index;
  457. }
  458. for (int index = 0; index < GB_QUANTITY; index++)
  459. {
  460. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  461. {
  462. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  463. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  464. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  465. }
  466. }
  467. }
  468. else if(gunType[gun_index] == GUN_TYPE_DO)
  469. {
  470. tempIndex = gun_index;
  471. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  472. {
  473. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  474. {
  475. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  476. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  477. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  478. }
  479. }
  480. }
  481. else
  482. {
  483. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  484. {
  485. tempIndex = 2;
  486. }
  487. else
  488. {
  489. tempIndex = gun_index;
  490. }
  491. for (int index = 0; index < AC_QUANTITY; index++)
  492. {
  493. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  494. {
  495. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  496. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  497. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  498. }
  499. }// END
  500. }
  501. // Message assembly
  502. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  503. tx_buf[4] = 0x02; // Protocol Version
  504. tx_buf[5] = 0xb0; // Message ID
  505. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  506. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  507. tx_buf[8] = 0x00; // CarID low byte
  508. tx_buf[9] = 0x00; // CarID high byte
  509. tx_buf[10] = 0x00; // ID Storage
  510. tx_buf[11] = 0x00; // Driver lowest byte
  511. tx_buf[12] = 0x00; // Driver 2nd byte
  512. tx_buf[13] = 0x00; // Driver 3rd byte
  513. tx_buf[14] = 0x00; // Driver highest byte
  514. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  515. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  516. tx_buf[17] = 0x00; // Reserve
  517. tx_buf[18] = 60 & 0xff; // Payload length low byte
  518. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  519. // EVSE provider
  520. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  521. // EVSE provider
  522. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  523. // EVSE id
  524. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  525. // Connector id
  526. tx_buf[37] = gun_index;
  527. // EVSE station
  528. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  529. // Vehicle SN
  530. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  531. // Mileage
  532. tx_buf[61] = 0x00; // lowest byte
  533. tx_buf[62] = 0x00; // 2nd byte
  534. tx_buf[63] = 0x00; // highest byte
  535. // Start date time 6 bytes
  536. 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))
  537. {
  538. struct tm *tmTarget;
  539. struct timeb tbTarget;
  540. tmStart.tm_year -= 1900;
  541. tmStart.tm_mon -= 1;
  542. tmStart.tm_gmtoff = 0;
  543. tbTarget.time = mktime(&tmStart);
  544. tbTarget.timezone = 0;
  545. tbTarget.time += (8*3600);
  546. tmTarget = gmtime(&tbTarget.time);
  547. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  548. tx_buf[65] = (tmTarget->tm_mon+1);
  549. tx_buf[66] = tmTarget->tm_mday;
  550. tx_buf[67] = tmTarget->tm_hour;
  551. tx_buf[68] = tmTarget->tm_min;
  552. tx_buf[69] = tmTarget->tm_sec;
  553. }
  554. // Stop date time 6 bytes
  555. 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))
  556. {
  557. struct tm *tmTarget;
  558. struct timeb tbTarget;
  559. tmEnd.tm_year -= 1900;
  560. tmEnd.tm_mon -= 1;
  561. tmEnd.tm_gmtoff = 0;
  562. tbTarget.time = mktime(&tmEnd);
  563. tbTarget.timezone = 0;
  564. tbTarget.time += (8*3600);
  565. tmTarget = gmtime(&tbTarget.time);
  566. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  567. tx_buf[71] = (tmTarget->tm_mon+1);
  568. tx_buf[72] = tmTarget->tm_mday;
  569. tx_buf[73] = tmTarget->tm_hour;
  570. tx_buf[74] = tmTarget->tm_min;
  571. tx_buf[75] = tmTarget->tm_sec;
  572. }
  573. // Session energy 2 bytes
  574. tx_buf[76] = PresentChargedEnergy & 0xff;
  575. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  576. // Start SOC 1 byte
  577. tx_buf[78] = socStart;
  578. // Stop SOC 1 byte
  579. tx_buf[79] = socEnd;
  580. // Open socket
  581. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  582. if(udp_socket_fd == -1)
  583. {
  584. DEBUG_ERROR("UDP socket create failed!\n");
  585. }
  586. else
  587. {
  588. // Get server DNS entry
  589. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  590. if (server == NULL)
  591. {
  592. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  593. }
  594. else
  595. {
  596. // Build the server's Internet address
  597. bzero((char *) &dest_addr, sizeof(dest_addr));
  598. dest_addr.sin_family = AF_INET;
  599. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  600. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  601. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  602. {
  603. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  604. {
  605. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  606. }
  607. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  608. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  609. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  610. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  611. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  612. DEBUG_TTIA_INFO("---------- Header ----------\n");
  613. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  614. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  615. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  616. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  617. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  618. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  619. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  620. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  621. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  622. DEBUG_TTIA_INFO("Len: 0x3C\n");
  623. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  624. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  625. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  626. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  627. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  628. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  629. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  630. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  631. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  632. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  633. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  634. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  635. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  636. DEBUG_TTIA_INFO("=========================================\n");
  637. sn++;
  638. result = PASS;
  639. }
  640. else
  641. {
  642. DEBUG_ERROR("UDP sent out fail.\n");
  643. }
  644. }
  645. }
  646. return result;
  647. }
  648. //=========================================
  649. // Save configuration
  650. //=========================================
  651. int runShellCmd(const char*cmd)
  652. {
  653. int result = FAIL;
  654. char buf[256];
  655. FILE *fp;
  656. fp = popen(cmd, "r");
  657. if(fp != NULL)
  658. {
  659. while(fgets(buf, sizeof(buf), fp) != NULL)
  660. {
  661. DEBUG_INFO("%s\n", buf);
  662. }
  663. result = PASS;
  664. }
  665. pclose(fp);
  666. return result;
  667. }
  668. int StoreUsrConfigData(struct SysConfigData *UsrData)
  669. {
  670. int result = PASS;
  671. int fd,wrd;
  672. unsigned int i,Chk;
  673. unsigned char *ptr, *BufTmp;
  674. int MtdBlockSize = 0x300000;
  675. Chk=0;
  676. ptr=(unsigned char *)UsrData;
  677. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  678. {
  679. memset(BufTmp,0,MtdBlockSize);
  680. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  681. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  682. Chk+=*(BufTmp+i);
  683. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  684. // Output configuration to file.
  685. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  686. if (fd < 0)
  687. {
  688. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  689. free(BufTmp);
  690. return 0;
  691. }
  692. wrd=write(fd, BufTmp, MtdBlockSize);
  693. close(fd);
  694. if(wrd<MtdBlockSize)
  695. {
  696. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  697. free(BufTmp);
  698. return 0;
  699. }
  700. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  701. DEBUG_INFO("Erase /dev/mtd10.\n");
  702. runShellCmd("flash_erase /dev/mtd10 0 0");
  703. DEBUG_INFO("Write /dev/mtd10.\n");
  704. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  705. DEBUG_INFO("Erase /dev/mtd11.\n");
  706. runShellCmd("flash_erase /dev/mtd11 0 0");
  707. DEBUG_INFO("Write /dev/mtd11.\n");
  708. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  709. system("rm -f /mnt/EvseConfig.bin");
  710. DEBUG_INFO("EvseConfig write to flash OK\n");
  711. }
  712. else
  713. {
  714. DEBUG_ERROR("alloc BlockSize NG\r\n");
  715. result = FAIL;
  716. }
  717. if(BufTmp!=NULL)
  718. free(BufTmp);
  719. return result;
  720. }
  721. //=========================================
  722. // Sqlite3 related function
  723. //=========================================
  724. static int selectSqlCount = 0;
  725. static int callback(void *data, int argc, char **argv, char **azColName){
  726. int i;
  727. //printf("%s: ", (const char*)data);
  728. selectSqlCount = argc;
  729. for(i = 0; i<argc; i++){
  730. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  731. }
  732. //printf("\n");
  733. return 0;
  734. }
  735. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  736. //int i;
  737. //printf("%s:\n", (const char*)data);
  738. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  739. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  740. return 0;
  741. }
  742. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  743. //printf("%s:\n", (const char*)data);
  744. //idTag
  745. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  746. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  747. //parentIdTag
  748. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  749. //expir_date
  750. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  751. //status
  752. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  753. //version
  754. if(columenCount > 5)
  755. idTagQuery.listVersionInt = atoi(columnValue[5]);
  756. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  757. return 0;
  758. }
  759. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  760. {
  761. // localversion = argv[5] ? atoi(argv[5]) : 0;
  762. // printf("localversion=%d\n", localversion);
  763. return 0;
  764. }
  765. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  766. {
  767. for (int i = 0; i < n_columns; i++)
  768. {
  769. DEBUG_INFO("%s\t", col_values[i]);
  770. }
  771. DEBUG_INFO("\n");
  772. return 0;
  773. }
  774. int OCPP_cleanLocalCache()
  775. {
  776. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  777. char *errMsg = 0;
  778. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  779. if (SQLITE_OK != rc)
  780. {
  781. DEBUG_INFO("SQL error: %s\n",errMsg);
  782. return FALSE;
  783. }
  784. return TRUE;
  785. }
  786. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  787. {
  788. int isSuccess = TRUE;
  789. int ret = 0;
  790. //const char* data = "Callback function called";
  791. char sql[300];
  792. char zErrMsg[200];
  793. memset(sql, 0, 300);
  794. memset(zErrMsg, 0, 200);
  795. 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);
  796. //* Execute SQL statement */
  797. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  798. if( ret != SQLITE_OK )
  799. {
  800. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  801. isSuccess = FALSE;
  802. }
  803. return isSuccess;
  804. }
  805. void OCPP_getIdTagFromLocalCache(char idTag[])
  806. {
  807. int rc = 0;
  808. char sql[100];
  809. char zErrMsg[100];
  810. memset(sql, 0, 100);
  811. memset(zErrMsg, 0, 100);
  812. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  813. memset(&idTagQuery, 0, sizeof(idTagQuery));
  814. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  815. /* Execute SQL statement */
  816. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  817. if( rc != SQLITE_OK )
  818. {
  819. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  820. }
  821. }
  822. void OCPP_getListVerion()
  823. {
  824. int rc = 0;
  825. // const char* data = "Callback function called";
  826. char sql[100];
  827. char zErrMsg[100];
  828. memset(sql, 0, 100);
  829. memset(zErrMsg, 0, 100);
  830. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  831. /* Execute SQL statement */
  832. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  833. if( rc != SQLITE_OK )
  834. {
  835. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  836. }
  837. }
  838. void OCPP_get_TableAuthlocalAllData(void)
  839. {
  840. int rc = 0;
  841. char sql[100];
  842. char zErrMsg[100];
  843. memset(sql, 0, 100);
  844. memset(zErrMsg, 0, 100);
  845. sprintf(sql,"select * from ocpp_auth_local ");
  846. /* Execute SQL statement */
  847. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  848. if( rc != SQLITE_OK )
  849. {
  850. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  851. }
  852. //return ver;
  853. }
  854. int OCPP_cleanLocalList()
  855. {
  856. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  857. char *errMsg = 0;
  858. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  859. if (SQLITE_OK != rc)
  860. {
  861. DEBUG_INFO("%s\n",errMsg);
  862. return FALSE;
  863. }
  864. return TRUE;
  865. }
  866. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  867. {
  868. int isSuccess = FALSE;
  869. int ret = 0;
  870. //const char* data = "Callback function called";
  871. char sql[300];
  872. char zErrMsg[200];
  873. memset(sql, 0, 300);
  874. memset(zErrMsg, 0, 200);
  875. 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);
  876. //* Execute SQL statement */
  877. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  878. if( ret != SQLITE_OK )
  879. {
  880. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  881. return isSuccess;
  882. }
  883. memset(sql, 0, 300);
  884. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  885. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  886. if( ret != SQLITE_OK )
  887. {
  888. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  889. return isSuccess;
  890. }
  891. isSuccess = TRUE;
  892. return isSuccess;
  893. }
  894. void OCPP_getIdTagFromLocalList(char idTag[])
  895. {
  896. int rc = 0;
  897. // const char* data = "Callback function called";
  898. char sql[100];
  899. char zErrMsg[100];
  900. memset(sql, 0, 100);
  901. memset(zErrMsg, 0, 100);
  902. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  903. memset(&idTagQuery, 0, sizeof(idTagQuery));
  904. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  905. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  906. /* Execute SQL statement */
  907. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  908. if( rc != SQLITE_OK )
  909. {
  910. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  911. }
  912. //return ver;
  913. }
  914. void OCPP_deleteIdTagFromLocalList(char idTag[])
  915. {
  916. //int ver = 0;
  917. //int isSuccess = FALSE;
  918. int rc = 0;
  919. char sql[100];
  920. char zErrMsg[100];
  921. memset(sql, 0, 100);
  922. memset(zErrMsg, 0, 100);
  923. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  924. //* Execute SQL statement */
  925. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  926. if( rc != SQLITE_OK )
  927. {
  928. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  929. }
  930. }
  931. int getCurrentYear()
  932. {
  933. int result = 0;
  934. time_t CurrentTime;
  935. struct tm *tm;
  936. CurrentTime = time(NULL);
  937. tm=localtime(&CurrentTime);
  938. result = (tm->tm_year + 1900);
  939. return result;
  940. }
  941. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  942. {
  943. int result = PASS;
  944. char* errMsg = NULL;
  945. char sqlStr[8192];
  946. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  947. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  948. {
  949. result = FAIL;
  950. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  951. }
  952. 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));
  953. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  954. {
  955. result = FAIL;
  956. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  957. }
  958. return result;
  959. }
  960. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  961. {
  962. int isSuccess = TRUE;
  963. int tempIndex;
  964. json_object *EnergyDataTransfer = json_object_new_object();
  965. json_object *periodEnergys = json_object_new_object();
  966. char sql[1024];
  967. char zErrMsg[200];
  968. memset(sql, 0, ARRAY_SIZE(sql));
  969. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  970. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  971. {
  972. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  973. {
  974. tempIndex = ((gun_index==2) ? 1: 0);
  975. }
  976. else
  977. {
  978. tempIndex = gun_index;
  979. }
  980. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  981. {
  982. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  983. {
  984. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  985. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  986. {
  987. uint8_t period[3];
  988. sprintf((char*)period, "%d", idxPeriod);
  989. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  990. }
  991. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  992. } //end of the same index
  993. }//end of for CHAdeMO_QUANTITY
  994. }
  995. else if(gunType[gun_index] == GUN_TYPE_CCS)
  996. {
  997. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  998. {
  999. tempIndex = ((gun_index==2) ? 1: 0);
  1000. }
  1001. else
  1002. {
  1003. tempIndex = gun_index;
  1004. }
  1005. for (int index = 0; index < CCS_QUANTITY; index++)
  1006. {
  1007. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1008. {
  1009. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1010. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1011. {
  1012. uint8_t period[3];
  1013. sprintf((char*)period, "%d", idxPeriod);
  1014. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1015. }
  1016. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1017. } //end of the same index
  1018. } // end of for CCS_QUANTITY
  1019. }
  1020. else if(gunType[gun_index] == GUN_TYPE_GBT)
  1021. {
  1022. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1023. {
  1024. tempIndex = ((gun_index==2) ? 1: 0);
  1025. }
  1026. else
  1027. {
  1028. tempIndex = gun_index;
  1029. }
  1030. for (int index = 0; index < GB_QUANTITY; index++)
  1031. {
  1032. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1033. {
  1034. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1035. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1036. {
  1037. uint8_t period[3];
  1038. sprintf((char*)period, "%d", idxPeriod);
  1039. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1040. }
  1041. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1042. } //end of the same index
  1043. } // end of for GB_QUANTITY
  1044. }
  1045. else if(gunType[gun_index] == GUN_TYPE_DO)
  1046. {
  1047. tempIndex = gun_index;
  1048. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1049. {
  1050. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1051. {
  1052. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1053. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1054. {
  1055. uint8_t period[3];
  1056. sprintf((char*)period, "%d", idxPeriod);
  1057. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1058. }
  1059. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1060. } //end of the same index
  1061. }
  1062. }
  1063. else
  1064. {
  1065. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1066. {
  1067. tempIndex = 2;
  1068. }
  1069. else
  1070. {
  1071. tempIndex = gun_index;
  1072. }
  1073. for (int index = 0; index < AC_QUANTITY; index++)
  1074. {
  1075. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1076. {
  1077. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1078. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1079. {
  1080. uint8_t period[3];
  1081. sprintf((char*)period, "%d", idxPeriod);
  1082. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1083. }
  1084. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1085. }//end of the same index
  1086. }//end of for AC_QUANTITY
  1087. }
  1088. 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));
  1089. json_object_put(EnergyDataTransfer);
  1090. //* Execute SQL statement */
  1091. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1092. {
  1093. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1094. isSuccess = FALSE;
  1095. }
  1096. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1097. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1098. {
  1099. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1100. isSuccess = FALSE;
  1101. }
  1102. return isSuccess;
  1103. }
  1104. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1105. {
  1106. int isSuccess = TRUE;
  1107. char sql[512];
  1108. char zErrMsg[200];
  1109. int rows, cols;
  1110. char **resultData;
  1111. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1112. /* Execute SQL statement */
  1113. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1114. {
  1115. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1116. isSuccess = FALSE;
  1117. }
  1118. else
  1119. {
  1120. if((rows > 0) && (atoi(resultData[4]) > 0))
  1121. {
  1122. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1123. }
  1124. else
  1125. {
  1126. DEBUG_WARN("There is not match transaction data.\n");
  1127. isSuccess = FALSE;
  1128. }
  1129. }
  1130. return isSuccess;
  1131. }
  1132. 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)
  1133. {
  1134. int result = PASS;
  1135. char* errMsg = NULL;
  1136. char sqlStr[8192];
  1137. 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');",
  1138. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1139. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1140. {
  1141. result = FAIL;
  1142. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1143. }
  1144. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1145. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1146. {
  1147. result = FAIL;
  1148. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1149. }
  1150. return result;
  1151. }
  1152. int OCPP_update_deduct_info(int txId, char *creditNo)
  1153. {
  1154. int result = PASS;
  1155. char* errMsg = NULL;
  1156. char sqlStr[8192];
  1157. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1158. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1159. {
  1160. result = FAIL;
  1161. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1162. }
  1163. return result;
  1164. }
  1165. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1166. {
  1167. json_object *dataBuf = json_object_new_object();
  1168. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1169. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1170. json_object_object_add(dataBuf, "txId", json_object_new_int(atoi(columnValue[1])));
  1171. json_object_object_add(dataBuf, "creditNo", json_object_new_string(columnValue[2]));
  1172. json_object_object_add(dataBuf, "deductResult", json_object_new_boolean(atoi(columnValue[3])));
  1173. json_object_object_add(dataBuf, "isDonateInvoice", json_object_new_boolean(atoi(columnValue[4])));
  1174. json_object_object_add(dataBuf, "amount", json_object_new_double(atof(columnValue[5])));
  1175. json_object_object_add(dataBuf, "approvalNo", json_object_new_string(columnValue[9]));
  1176. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1177. json_object_put(dataBuf);
  1178. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1179. return 0;
  1180. }
  1181. void OCPP_query_deduct_info()
  1182. {
  1183. int rc = 0;
  1184. char sql[100];
  1185. char zErrMsg[100];
  1186. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1187. /* Execute SQL statement */
  1188. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1189. if( rc != SQLITE_OK )
  1190. {
  1191. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1192. }
  1193. }
  1194. void reportReaderStatus(int gun_index)
  1195. {
  1196. struct timeval tmnow;
  1197. struct tm *tm;
  1198. char buf[28];//, usec_buf[6];
  1199. gettimeofday(&tmnow, NULL);
  1200. time_t t;
  1201. t = time(NULL);
  1202. /*UTC time and date*/
  1203. tm = gmtime(&t);
  1204. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1205. #if 0 // remove temporally
  1206. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1207. strcat(buf,".");
  1208. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1209. strcat(buf,usec_buf);
  1210. #endif
  1211. json_object *dataBuf = json_object_new_object();
  1212. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1213. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_ReaderStatus");
  1214. json_object_object_add(dataBuf, "connectorId", json_object_new_int((gun_index+1)));
  1215. json_object_object_add(dataBuf, "readerStatus", json_object_new_int(ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus));
  1216. json_object_object_add(dataBuf, "timestamp", json_object_new_string(buf));
  1217. json_object_object_add(dataBuf, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  1218. json_object_object_add(dataBuf, "creditNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo));
  1219. json_object_object_add(dataBuf, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  1220. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1221. json_object_put(dataBuf);
  1222. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1223. }
  1224. //==========================================
  1225. // Check time passed since today
  1226. //==========================================
  1227. long long DiffTimebWithNow(struct timeb ST)
  1228. {
  1229. //return milli-second
  1230. struct timeb ET;
  1231. long long StartTime,StopTime;
  1232. ftime(&ET);
  1233. StartTime=(long long)ST.time;
  1234. StopTime=(long long)ET.time;
  1235. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1236. }
  1237. int getTimePassSinceToday(uint8_t gun_index)
  1238. {
  1239. int result = -1;
  1240. static time_t lastTime[4];
  1241. time_t t;
  1242. struct tm *tmStartToday;
  1243. struct timeb tbStartToday;
  1244. t=time(NULL);
  1245. if(difftime(t, lastTime[gun_index])>0)
  1246. {
  1247. tmStartToday=localtime(&t);
  1248. tmStartToday->tm_hour = 0;
  1249. tmStartToday->tm_min = 0;
  1250. tmStartToday->tm_sec = 0;
  1251. tbStartToday.time = mktime(tmStartToday);
  1252. tbStartToday.millitm = 0;
  1253. result = DiffTimebWithNow(tbStartToday)/1000;
  1254. lastTime[gun_index] = t;
  1255. }
  1256. return result;
  1257. }
  1258. void getNowDatetime(uint8_t *data)
  1259. {
  1260. time_t t = time(NULL);
  1261. struct tm tm = *localtime(&t);
  1262. 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);
  1263. }
  1264. int syncDateTimeRTC(uint8_t *data)
  1265. {
  1266. struct ParsingResult
  1267. {
  1268. int result;
  1269. int scanedElement;
  1270. int year;
  1271. int month;
  1272. int mday;
  1273. int hour;
  1274. int min;
  1275. int sec;
  1276. int tz_hour;
  1277. int tz_min;
  1278. float minSec;
  1279. }result;
  1280. struct tm tmOrg;
  1281. struct tm *tmTarget;
  1282. struct timeb tbTarget;
  1283. char buf[128];
  1284. memset(&result, 0x00, sizeof(struct ParsingResult));
  1285. result.result = PASS;
  1286. if(strstr((char*)data, ".") != NULL)
  1287. {
  1288. // Original data with mini second
  1289. if(strstr((char*)data, "Z") != NULL)
  1290. {
  1291. // Original data with Z
  1292. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1293. &result.year,
  1294. &result.month,
  1295. &result.mday,
  1296. &result.hour,
  1297. &result.min,
  1298. &result.sec,
  1299. &result.minSec);
  1300. }
  1301. else
  1302. {
  1303. // Original data without Z
  1304. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1305. &result.year,
  1306. &result.month,
  1307. &result.mday,
  1308. &result.hour,
  1309. &result.min,
  1310. &result.sec,
  1311. &result.minSec,
  1312. &result.tz_hour,
  1313. &result.tz_min);
  1314. }
  1315. }
  1316. else
  1317. {
  1318. // Original data without mini second
  1319. if(strstr((char*)data, "Z") != NULL)
  1320. {
  1321. // Original data with Z
  1322. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1323. &result.year,
  1324. &result.month,
  1325. &result.mday,
  1326. &result.hour,
  1327. &result.min,
  1328. &result.sec);
  1329. }
  1330. else
  1331. {
  1332. // Original data without Z
  1333. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1334. &result.year,
  1335. &result.month,
  1336. &result.mday,
  1337. &result.hour,
  1338. &result.min,
  1339. &result.sec,
  1340. &result.tz_hour,
  1341. &result.tz_min);
  1342. }
  1343. }
  1344. tmOrg.tm_year = result.year - 1900;
  1345. tmOrg.tm_mon = result.month - 1;
  1346. tmOrg.tm_mday = result.mday;
  1347. tmOrg.tm_hour = result.hour;
  1348. tmOrg.tm_min = result.min;
  1349. tmOrg.tm_sec = result.sec;
  1350. tmOrg.tm_gmtoff = 0;
  1351. tbTarget.time = mktime(&tmOrg);
  1352. tbTarget.timezone = 0;
  1353. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1354. tmTarget = gmtime(&tbTarget.time);
  1355. 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);
  1356. //DEBUG_INFO(" org date time: %s\n", data);
  1357. //DEBUG_INFO("parse date time: %s\n", buf);
  1358. system(buf);
  1359. system("/sbin/hwclock -w --systohc");
  1360. if(result.scanedElement < 6)
  1361. result.result = FAIL;
  1362. return result.result;
  1363. }
  1364. //==========================================
  1365. // Parse certificate content
  1366. //==========================================
  1367. int parseCertInfo(char *certPath, int parseType, char *data)
  1368. {
  1369. int result = FAIL;
  1370. if(access(certPath,F_OK) != -1)
  1371. {
  1372. char temp[512] = {0};
  1373. char capturedData[256] = {0};
  1374. char hashType[10] = "SHA256";
  1375. FILE *fp;
  1376. // Need to get hash type first
  1377. sprintf(temp ,"openssl x509 -noout -text -in %s", certPath);
  1378. fp = popen(temp, "r");
  1379. if(fp)
  1380. {
  1381. while(fgets(temp, sizeof(temp), fp) != NULL)
  1382. {
  1383. if(strstr(temp, "Signature Algorithm:") != NULL)
  1384. {
  1385. result = PASS;
  1386. if(strstr(temp, "sha256") != NULL || strstr(temp, "SHA256") != NULL)
  1387. sprintf((char*)hashType, "SHA256");
  1388. else if(strstr(temp, "sha384") != NULL || strstr(temp, "SHA384") != NULL)
  1389. sprintf((char*)hashType, "SHA384");
  1390. else if(strstr(temp, "sha512") != NULL || strstr(temp, "SHA512") != NULL)
  1391. sprintf((char*)hashType, "SHA512");
  1392. else
  1393. {
  1394. DEBUG_INFO("Error: hashAlgorithm is illegal or missing.\n");
  1395. result = FAIL;
  1396. }
  1397. break;
  1398. }
  1399. }
  1400. sprintf((char*)data, hashType);
  1401. }
  1402. switch(parseType)
  1403. {
  1404. case CERT_PARSE_HashAlgorithm:
  1405. // Already parsed
  1406. DEBUG_INFO("hashAlgorithm: %s\n", hashType);
  1407. break;
  1408. case CERT_PARSE_SerialNumber:
  1409. sprintf(temp ,"openssl x509 -noout -serial -in %s", certPath);
  1410. fp = popen(temp, "r");
  1411. if(fp)
  1412. {
  1413. while(fgets(temp, sizeof(temp), fp) != NULL)
  1414. {
  1415. if(strstr(temp, "serial=") != NULL)
  1416. {
  1417. sscanf(temp, "%*[^=]=%s", capturedData);
  1418. result = PASS;
  1419. break;
  1420. }
  1421. }
  1422. DEBUG_INFO("serialNumber: %s\n", capturedData);
  1423. sprintf((char*)data, capturedData);
  1424. }
  1425. break;
  1426. case CERT_PARSE_IssuerNameHash:
  1427. sprintf(temp ,"openssl x509 -noout -issuer -in %s | openssl dgst -%s", certPath, (char*)hashType);
  1428. fp = popen(temp, "r");
  1429. if(fp)
  1430. {
  1431. while(fgets(temp, sizeof(temp), fp) != NULL)
  1432. {
  1433. if(strstr(temp, "(stdin)=") != NULL)
  1434. {
  1435. sscanf(temp, "%*[^=]=%s", capturedData);
  1436. result = PASS;
  1437. break;
  1438. }
  1439. }
  1440. stringtrimspace(capturedData);
  1441. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1442. sprintf((char*)data, capturedData);
  1443. }
  1444. break;
  1445. case CERT_PARSE_IssuerKeyHash:
  1446. sprintf(temp ,"openssl x509 -noout -pubkey -in %s | openssl dgst -%s", certPath, (char*)hashType);
  1447. fp = popen(temp, "r");
  1448. if(fp)
  1449. {
  1450. while(fgets(temp, sizeof(temp), fp) != NULL)
  1451. {
  1452. if(strstr(temp, "(stdin)=") != NULL)
  1453. {
  1454. sscanf(temp, "%*[^=]=%s", capturedData);
  1455. result = PASS;
  1456. break;
  1457. }
  1458. }
  1459. stringtrimspace(capturedData);
  1460. DEBUG_INFO("issuerKeyHash: %s\n", capturedData);
  1461. sprintf((char*)data, capturedData);
  1462. }
  1463. break;
  1464. case CERT_PARSE_OcspUrl:
  1465. sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", certPath);
  1466. fp = popen(temp, "r");
  1467. if(fp)
  1468. {
  1469. while(fgets(temp, sizeof(temp), fp) != NULL)
  1470. {
  1471. if(strstr(temp, "://") != NULL)
  1472. {
  1473. strcpy((char*)data, temp);
  1474. result = PASS;
  1475. break;
  1476. }
  1477. }
  1478. }
  1479. break;
  1480. default:
  1481. DEBUG_INFO("Parse type is invalid.\n");
  1482. break;
  1483. }
  1484. pclose(fp);
  1485. }
  1486. return result;
  1487. }
  1488. //==========================================
  1489. // GetCompositeSchedule logic related function
  1490. //==========================================
  1491. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1492. {
  1493. //return milli-second
  1494. unsigned int StartTime,StopTime;
  1495. StartTime=(unsigned int)ST.time;
  1496. StopTime=(unsigned int)ET.time;
  1497. return (StopTime-StartTime);
  1498. }
  1499. int DiffTimebWithNowSec(struct timeb ST)
  1500. {
  1501. //return milli-second
  1502. struct timeb ET;
  1503. unsigned int StartTime,StopTime;
  1504. ftime(&ET);
  1505. StartTime=(unsigned int)ST.time;
  1506. StopTime=(unsigned int)ET.time;
  1507. return (StopTime-StartTime);
  1508. }
  1509. int getStartStop(uint8_t *start, uint8_t *stop)
  1510. {
  1511. struct ParsingResult
  1512. {
  1513. int result;
  1514. int scanedElement;
  1515. int year;
  1516. int month;
  1517. int mday;
  1518. int hour;
  1519. int min;
  1520. int sec;
  1521. int tz_hour;
  1522. int tz_min;
  1523. float minSec;
  1524. };
  1525. struct ParsingResult parseStart;
  1526. struct ParsingResult parseStop;
  1527. int result = -1;
  1528. struct tm tmStart;
  1529. struct timeb tbStart;
  1530. struct tm tmStop;
  1531. struct timeb tbStop;
  1532. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1533. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1534. // Scan start & stop date time
  1535. if(strstr((char*)start, ".") != NULL)
  1536. {
  1537. // Original data with mini second
  1538. if(strstr((char*)start, "Z") != NULL)
  1539. {
  1540. // Original data with Z
  1541. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1542. &parseStart.year,
  1543. &parseStart.month,
  1544. &parseStart.mday,
  1545. &parseStart.hour,
  1546. &parseStart.min,
  1547. &parseStart.sec,
  1548. &parseStart.minSec);
  1549. }
  1550. else
  1551. {
  1552. // Original data without Z
  1553. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1554. &parseStart.year,
  1555. &parseStart.month,
  1556. &parseStart.mday,
  1557. &parseStart.hour,
  1558. &parseStart.min,
  1559. &parseStart.sec,
  1560. &parseStart.minSec,
  1561. &parseStart.tz_hour,
  1562. &parseStart.tz_min);
  1563. }
  1564. }
  1565. else
  1566. {
  1567. // Original data without mini second
  1568. if(strstr((char*)start, "Z") != NULL)
  1569. {
  1570. // Original data with Z
  1571. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1572. &parseStart.year,
  1573. &parseStart.month,
  1574. &parseStart.mday,
  1575. &parseStart.hour,
  1576. &parseStart.min,
  1577. &parseStart.sec);
  1578. }
  1579. else
  1580. {
  1581. // Original data without Z
  1582. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1583. &parseStart.year,
  1584. &parseStart.month,
  1585. &parseStart.mday,
  1586. &parseStart.hour,
  1587. &parseStart.min,
  1588. &parseStart.sec,
  1589. &parseStart.tz_hour,
  1590. &parseStart.tz_min);
  1591. }
  1592. }
  1593. if(strstr((char*)stop, ".") != NULL)
  1594. {
  1595. // Original data with mini second
  1596. if(strstr((char*)stop, "Z") != NULL)
  1597. {
  1598. // Original data with Z
  1599. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1600. &parseStop.year,
  1601. &parseStop.month,
  1602. &parseStop.mday,
  1603. &parseStop.hour,
  1604. &parseStop.min,
  1605. &parseStop.sec,
  1606. &parseStop.minSec);
  1607. }
  1608. else
  1609. {
  1610. // Original data without Z
  1611. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1612. &parseStop.year,
  1613. &parseStop.month,
  1614. &parseStop.mday,
  1615. &parseStop.hour,
  1616. &parseStop.min,
  1617. &parseStop.sec,
  1618. &parseStop.minSec,
  1619. &parseStop.tz_hour,
  1620. &parseStop.tz_min);
  1621. }
  1622. }
  1623. else
  1624. {
  1625. // Original data without mini second
  1626. if(strstr((char*)stop, "Z") != NULL)
  1627. {
  1628. // Original data with Z
  1629. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1630. &parseStop.year,
  1631. &parseStop.month,
  1632. &parseStop.mday,
  1633. &parseStop.hour,
  1634. &parseStop.min,
  1635. &parseStop.sec);
  1636. }
  1637. else
  1638. {
  1639. // Original data without Z
  1640. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1641. &parseStop.year,
  1642. &parseStop.month,
  1643. &parseStop.mday,
  1644. &parseStop.hour,
  1645. &parseStop.min,
  1646. &parseStop.sec,
  1647. &parseStop.tz_hour,
  1648. &parseStop.tz_min);
  1649. }
  1650. }
  1651. // Calculate date time difference
  1652. if((parseStart.scanedElement >=6) &&
  1653. (parseStop.scanedElement >=6))
  1654. {
  1655. //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);
  1656. //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);
  1657. tmStart.tm_year = parseStart.year - 1900;
  1658. tmStart.tm_mon = parseStart.month - 1;
  1659. tmStart.tm_mday = parseStart.mday;
  1660. tmStart.tm_hour = parseStart.hour;
  1661. tmStart.tm_min = parseStart.min;
  1662. tmStart.tm_sec = parseStart.sec;
  1663. tmStart.tm_gmtoff = 0;
  1664. tbStart.time = mktime(&tmStart);
  1665. tbStart.timezone = 0;
  1666. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1667. tmStop.tm_year = parseStop.year - 1900;
  1668. tmStop.tm_mon = parseStop.month - 1;
  1669. tmStop.tm_mday = parseStop.mday;
  1670. tmStop.tm_hour = parseStop.hour;
  1671. tmStop.tm_min = parseStop.min;
  1672. tmStop.tm_sec = parseStop.sec;
  1673. tmStop.tm_gmtoff = 0;
  1674. tbStop.time = mktime(&tmStop);
  1675. tbStop.timezone = 0;
  1676. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1677. result = DiffTimebSec(tbStart, tbStop);
  1678. //DEBUG_INFO("getStartStop(): %d\n", result);
  1679. }
  1680. else
  1681. {
  1682. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1683. }
  1684. return result;
  1685. }
  1686. int isOvertNow(uint8_t *start)
  1687. {
  1688. int result = NO;
  1689. struct ParsingResult
  1690. {
  1691. int result;
  1692. int scanedElement;
  1693. int year;
  1694. int month;
  1695. int mday;
  1696. int hour;
  1697. int min;
  1698. int sec;
  1699. int tz_hour;
  1700. int tz_min;
  1701. float minSec;
  1702. }parsingResult;
  1703. struct tm tmStart;
  1704. struct timeb tbStart;
  1705. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1706. if(strstr((char*)start, ".") != NULL)
  1707. {
  1708. // Original data with mini second
  1709. if(strstr((char*)start, "Z") != NULL)
  1710. {
  1711. // Original data with Z
  1712. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1713. &parsingResult.year,
  1714. &parsingResult.month,
  1715. &parsingResult.mday,
  1716. &parsingResult.hour,
  1717. &parsingResult.min,
  1718. &parsingResult.sec,
  1719. &parsingResult.minSec);
  1720. }
  1721. else
  1722. {
  1723. // Original data without Z
  1724. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1725. &parsingResult.year,
  1726. &parsingResult.month,
  1727. &parsingResult.mday,
  1728. &parsingResult.hour,
  1729. &parsingResult.min,
  1730. &parsingResult.sec,
  1731. &parsingResult.minSec,
  1732. &parsingResult.tz_hour,
  1733. &parsingResult.tz_min);
  1734. }
  1735. }
  1736. else
  1737. {
  1738. // Original data without mini second
  1739. if(strstr((char*)start, "Z") != NULL)
  1740. {
  1741. // Original data with Z
  1742. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1743. &parsingResult.year,
  1744. &parsingResult.month,
  1745. &parsingResult.mday,
  1746. &parsingResult.hour,
  1747. &parsingResult.min,
  1748. &parsingResult.sec);
  1749. }
  1750. else
  1751. {
  1752. // Original data without Z
  1753. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1754. &parsingResult.year,
  1755. &parsingResult.month,
  1756. &parsingResult.mday,
  1757. &parsingResult.hour,
  1758. &parsingResult.min,
  1759. &parsingResult.sec,
  1760. &parsingResult.tz_hour,
  1761. &parsingResult.tz_min);
  1762. }
  1763. }
  1764. if(parsingResult.scanedElement >= 6)
  1765. {
  1766. tmStart.tm_year = parsingResult.year - 1900;
  1767. tmStart.tm_mon = parsingResult.month - 1;
  1768. tmStart.tm_mday = parsingResult.mday;
  1769. tmStart.tm_hour = parsingResult.hour;
  1770. tmStart.tm_min = parsingResult.min;
  1771. tmStart.tm_sec = parsingResult.sec;
  1772. tmStart.tm_gmtoff = 0;
  1773. tbStart.time = mktime(&tmStart);
  1774. tbStart.timezone = 0;
  1775. tbStart.millitm = 0;
  1776. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1777. if(DiffTimebWithNowSec(tbStart) <= 0)
  1778. result = NO;
  1779. else
  1780. result = YES;
  1781. }
  1782. else
  1783. {
  1784. DEBUG_WARN("Start date parsing error.\n");
  1785. }
  1786. return result;
  1787. }
  1788. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1789. {
  1790. struct ParsingResult
  1791. {
  1792. int result;
  1793. int scanedElement;
  1794. int year;
  1795. int month;
  1796. int mday;
  1797. int hour;
  1798. int min;
  1799. int sec;
  1800. int tz_hour;
  1801. int tz_min;
  1802. float minSec;
  1803. };
  1804. struct ParsingResult parseStart;
  1805. struct ParsingResult parseStop;
  1806. int result = -1;
  1807. struct tm tmStart;
  1808. struct timeb tbStart;
  1809. struct tm tmStop;
  1810. struct timeb tbStop;
  1811. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1812. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1813. // Scan start & stop date time
  1814. if(strstr((char*)start, ".") != NULL)
  1815. {
  1816. // Original data with mini second
  1817. if(strstr((char*)start, "Z") != NULL)
  1818. {
  1819. // Original data with Z
  1820. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1821. &parseStart.year,
  1822. &parseStart.month,
  1823. &parseStart.mday,
  1824. &parseStart.hour,
  1825. &parseStart.min,
  1826. &parseStart.sec,
  1827. &parseStart.minSec);
  1828. }
  1829. else
  1830. {
  1831. // Original data without Z
  1832. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1833. &parseStart.year,
  1834. &parseStart.month,
  1835. &parseStart.mday,
  1836. &parseStart.hour,
  1837. &parseStart.min,
  1838. &parseStart.sec,
  1839. &parseStart.minSec,
  1840. &parseStart.tz_hour,
  1841. &parseStart.tz_min);
  1842. }
  1843. }
  1844. else
  1845. {
  1846. // Original data without mini second
  1847. if(strstr((char*)start, "Z") != NULL)
  1848. {
  1849. // Original data with Z
  1850. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1851. &parseStart.year,
  1852. &parseStart.month,
  1853. &parseStart.mday,
  1854. &parseStart.hour,
  1855. &parseStart.min,
  1856. &parseStart.sec);
  1857. }
  1858. else
  1859. {
  1860. // Original data without Z
  1861. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1862. &parseStart.year,
  1863. &parseStart.month,
  1864. &parseStart.mday,
  1865. &parseStart.hour,
  1866. &parseStart.min,
  1867. &parseStart.sec,
  1868. &parseStart.tz_hour,
  1869. &parseStart.tz_min);
  1870. }
  1871. }
  1872. if(strstr((char*)stop, ".") != NULL)
  1873. {
  1874. // Original data with mini second
  1875. if(strstr((char*)stop, "Z") != NULL)
  1876. {
  1877. // Original data with Z
  1878. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1879. &parseStop.year,
  1880. &parseStop.month,
  1881. &parseStop.mday,
  1882. &parseStop.hour,
  1883. &parseStop.min,
  1884. &parseStop.sec,
  1885. &parseStop.minSec);
  1886. }
  1887. else
  1888. {
  1889. // Original data without Z
  1890. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1891. &parseStop.year,
  1892. &parseStop.month,
  1893. &parseStop.mday,
  1894. &parseStop.hour,
  1895. &parseStop.min,
  1896. &parseStop.sec,
  1897. &parseStop.minSec,
  1898. &parseStop.tz_hour,
  1899. &parseStop.tz_min);
  1900. }
  1901. }
  1902. else
  1903. {
  1904. // Original data without mini second
  1905. if(strstr((char*)stop, "Z") != NULL)
  1906. {
  1907. // Original data with Z
  1908. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1909. &parseStop.year,
  1910. &parseStop.month,
  1911. &parseStop.mday,
  1912. &parseStop.hour,
  1913. &parseStop.min,
  1914. &parseStop.sec);
  1915. }
  1916. else
  1917. {
  1918. // Original data without Z
  1919. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1920. &parseStop.year,
  1921. &parseStop.month,
  1922. &parseStop.mday,
  1923. &parseStop.hour,
  1924. &parseStop.min,
  1925. &parseStop.sec,
  1926. &parseStop.tz_hour,
  1927. &parseStop.tz_min);
  1928. }
  1929. }
  1930. // Calculate date time difference
  1931. if((parseStart.scanedElement >=6) &&
  1932. (parseStop.scanedElement >=6))
  1933. {
  1934. //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);
  1935. //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);
  1936. tmStart.tm_year = parseStart.year - 1900;
  1937. tmStart.tm_mon = parseStart.month - 1;
  1938. tmStart.tm_mday = parseStart.mday;
  1939. tmStart.tm_hour = parseStart.hour;
  1940. tmStart.tm_min = parseStart.min;
  1941. tmStart.tm_sec = parseStart.sec;
  1942. tmStart.tm_gmtoff = 0;
  1943. tbStart.time = mktime(&tmStart);
  1944. tbStart.timezone = 0;
  1945. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1946. tmStop.tm_year = parseStop.year - 1900;
  1947. tmStop.tm_mon = parseStop.month - 1;
  1948. tmStop.tm_mday = parseStop.mday;
  1949. tmStop.tm_hour = parseStop.hour;
  1950. tmStop.tm_min = parseStop.min;
  1951. tmStop.tm_sec = parseStop.sec;
  1952. tmStop.tm_gmtoff = 0;
  1953. tbStop.time = mktime(&tmStop);
  1954. tbStop.timezone = 0;
  1955. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1956. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1957. //DEBUG_INFO("getStartStop(): %d\n", result);
  1958. }
  1959. else
  1960. {
  1961. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1962. }
  1963. return result;
  1964. }
  1965. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  1966. {
  1967. FILE *fp;
  1968. char profileFileName[128];
  1969. char *line = NULL;
  1970. size_t len = 0;
  1971. time_t CurrentTime;
  1972. struct tm *tmComposite;
  1973. struct StructChargingProfile maxProfile;
  1974. struct StructChargingProfile compositeProfile;
  1975. uint8_t limitMax=0;
  1976. int compositePeriodIdx = 0;
  1977. //uint8_t isDurationNull = FALSE;
  1978. CurrentTime = time(NULL);
  1979. tmComposite=localtime(&CurrentTime);
  1980. 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);
  1981. if(isUnitA)
  1982. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  1983. else
  1984. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  1985. compositeProfile.ChargingSchedule.Duration = durationReq;
  1986. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1987. {
  1988. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1989. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1990. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1991. }
  1992. compositeProfile.ChargingProfileId = 0;
  1993. compositeProfile.StackLevel = 99 ;
  1994. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  1995. maxProfile.ChargingProfileId = -1;
  1996. maxProfile.ChargingSchedule.Duration = -1;
  1997. system("rm -f /tmp/*.json");
  1998. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1999. // Search max profile
  2000. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2001. if((access(profileFileName, F_OK))!=-1)
  2002. {
  2003. fp = fopen(profileFileName, "r");
  2004. while(getline(&line, &len, fp) != -1)
  2005. {
  2006. json_object *obj = NULL;
  2007. obj = json_tokener_parse(line);
  2008. if(is_error(obj))
  2009. {
  2010. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2011. }
  2012. else
  2013. {
  2014. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2015. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2016. )
  2017. {
  2018. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2019. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2020. )
  2021. {
  2022. struct tm tmFrom, tmTo;
  2023. struct timeb tbFrom, tbTo;
  2024. 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) &&
  2025. (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))
  2026. {
  2027. tmFrom.tm_year -= 1900;
  2028. tmFrom.tm_mon -= 1;
  2029. tbFrom.time = mktime(&tmFrom);
  2030. tmTo.tm_year -= 1900;
  2031. tmTo.tm_mon -= 1;
  2032. tbTo.time = mktime(&tmTo);
  2033. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2034. {
  2035. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2036. {
  2037. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2038. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2039. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2040. }
  2041. if(maxProfile.ChargingProfileId == -1)
  2042. DEBUG_INFO("MaxProfile found.\n");
  2043. else
  2044. DEBUG_INFO("MaxProfile updated.\n");
  2045. // Required item
  2046. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2047. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2048. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2049. if(isUnitA)
  2050. {
  2051. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2052. 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++)
  2053. {
  2054. 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"));
  2055. 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?
  2056. 3:
  2057. 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")));
  2058. 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")));
  2059. }
  2060. }
  2061. else
  2062. {
  2063. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2064. 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++)
  2065. {
  2066. 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"));
  2067. 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?
  2068. 3:
  2069. 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")));
  2070. 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));
  2071. }
  2072. }
  2073. // Optional item
  2074. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2075. {
  2076. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2077. }
  2078. else
  2079. {
  2080. sprintf((char*)maxProfile.ValidFrom, " ");
  2081. }
  2082. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2083. {
  2084. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2085. }
  2086. else
  2087. {
  2088. sprintf((char*)maxProfile.ValidTo, " ");
  2089. }
  2090. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2091. {
  2092. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2093. }
  2094. else
  2095. {
  2096. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2097. }
  2098. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2099. {
  2100. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2101. }
  2102. else
  2103. {
  2104. maxProfile.TransactionId = -1;
  2105. }
  2106. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2107. {
  2108. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2109. }
  2110. else
  2111. {
  2112. maxProfile.ChargingSchedule.Duration = 86400;
  2113. //isDurationNull = TRUE;
  2114. }
  2115. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2116. {
  2117. 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")));
  2118. }
  2119. else
  2120. {
  2121. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2122. }
  2123. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2124. {
  2125. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2126. }
  2127. else
  2128. {
  2129. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2130. }
  2131. }
  2132. }
  2133. }
  2134. else
  2135. {
  2136. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2137. {
  2138. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2139. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2140. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2141. }
  2142. if(maxProfile.ChargingProfileId == -1)
  2143. DEBUG_INFO("MaxProfile found.\n");
  2144. else
  2145. DEBUG_INFO("MaxProfile updated.\n");
  2146. // Required item
  2147. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2148. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2149. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2150. if(isUnitA)
  2151. {
  2152. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2153. 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++)
  2154. {
  2155. 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"));
  2156. 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?
  2157. 3:
  2158. 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")));
  2159. 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")));
  2160. }
  2161. }
  2162. else
  2163. {
  2164. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2165. 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++)
  2166. {
  2167. 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"));
  2168. 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?
  2169. 3:
  2170. 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")));
  2171. 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));
  2172. }
  2173. }
  2174. // Optional item
  2175. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2176. {
  2177. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2178. }
  2179. else
  2180. {
  2181. sprintf((char*)maxProfile.ValidFrom, " ");
  2182. }
  2183. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2184. {
  2185. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2186. }
  2187. else
  2188. {
  2189. sprintf((char*)maxProfile.ValidTo, " ");
  2190. }
  2191. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2192. {
  2193. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2194. }
  2195. else
  2196. {
  2197. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2198. }
  2199. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2200. {
  2201. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2202. }
  2203. else
  2204. {
  2205. maxProfile.TransactionId = -1;
  2206. }
  2207. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2208. {
  2209. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2210. }
  2211. else
  2212. {
  2213. maxProfile.ChargingSchedule.Duration = 86400;
  2214. //isDurationNull = TRUE;
  2215. }
  2216. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2217. {
  2218. 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")));
  2219. }
  2220. else
  2221. {
  2222. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2223. }
  2224. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2225. {
  2226. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2227. }
  2228. else
  2229. {
  2230. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2231. }
  2232. }
  2233. }
  2234. }
  2235. json_object_put(obj);
  2236. }
  2237. fclose(fp);
  2238. /*
  2239. if(maxProfile.ChargingProfileId !=-1)
  2240. {
  2241. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2242. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2243. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2244. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2245. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2246. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2247. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2248. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2249. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2250. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2251. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2252. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2253. {
  2254. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2255. {
  2256. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2257. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2258. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2259. }
  2260. }
  2261. }
  2262. else
  2263. DEBUG_INFO("MaxProfile not found.\n");
  2264. DEBUG_INFO("------------------------------------\n");*/
  2265. }
  2266. if(maxProfile.ChargingProfileId != -1)
  2267. {
  2268. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2269. {
  2270. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  2271. {
  2272. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2273. 0:
  2274. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2275. }
  2276. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2277. {
  2278. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2279. {
  2280. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2281. 0:
  2282. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2283. if(idxPeriod > 0)
  2284. {
  2285. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2286. {
  2287. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2288. }
  2289. }
  2290. }
  2291. }
  2292. }
  2293. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2294. {
  2295. if(maxProfile.ChargingSchedule.Duration != -1)
  2296. {
  2297. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2298. }
  2299. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2300. {
  2301. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2302. {
  2303. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2304. if(idxPeriod > 0)
  2305. {
  2306. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2307. {
  2308. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2309. }
  2310. }
  2311. }
  2312. }
  2313. }
  2314. else
  2315. {
  2316. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2317. {
  2318. if(maxProfile.ChargingSchedule.Duration != -1)
  2319. {
  2320. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2321. 0:
  2322. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2323. }
  2324. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2325. {
  2326. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2327. {
  2328. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2329. 0:
  2330. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2331. if(idxPeriod > 0)
  2332. {
  2333. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2334. {
  2335. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2336. }
  2337. }
  2338. }
  2339. }
  2340. }
  2341. else
  2342. {
  2343. if(maxProfile.ChargingSchedule.Duration != -1)
  2344. {
  2345. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2346. 0:
  2347. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2348. }
  2349. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2350. {
  2351. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2352. {
  2353. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2354. 0:
  2355. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2356. if(idxPeriod > 0)
  2357. {
  2358. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2359. {
  2360. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2361. }
  2362. }
  2363. }
  2364. }
  2365. }
  2366. }
  2367. /*
  2368. DEBUG_INFO("MaxProfile after align.\n");
  2369. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2370. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2371. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2372. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2373. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2374. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2375. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2376. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2377. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2378. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2379. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2380. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2381. {
  2382. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2383. {
  2384. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2385. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2386. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2387. }
  2388. }
  2389. DEBUG_INFO("------------------------------------\n");*/
  2390. }
  2391. // Find each profile period quantity
  2392. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2393. {
  2394. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2395. limitMax = idx+1;
  2396. }
  2397. if(maxProfile.ChargingProfileId != -1)
  2398. {
  2399. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2400. {
  2401. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2402. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2403. (maxProfile.ChargingSchedule.Duration > 0))
  2404. {
  2405. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2406. {
  2407. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2408. compositePeriodIdx++;
  2409. }
  2410. else
  2411. {
  2412. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2413. }
  2414. }
  2415. }
  2416. }
  2417. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2418. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2419. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2420. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2421. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2422. {
  2423. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2424. {
  2425. compositeProfile.ChargingProfileId = 1;
  2426. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2427. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2428. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2429. }
  2430. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2431. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2432. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2433. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2434. }
  2435. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2436. if(line)
  2437. free(line);
  2438. }
  2439. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2440. {
  2441. FILE *fp;
  2442. char profileFileName[128];
  2443. char *line = NULL;
  2444. size_t len = 0;
  2445. time_t CurrentTime;
  2446. struct tm *tmComposite;
  2447. struct StructChargingProfile maxProfile;
  2448. struct StructChargingProfile defaultTxProfile;
  2449. struct StructChargingProfile txProfile;
  2450. struct StructChargingProfile compositeProfile;
  2451. struct StructChargingSchedulePeriod tmpPeriod;
  2452. uint8_t limitMax=0;
  2453. uint8_t limitDef=0;
  2454. uint8_t limitTx=0;
  2455. int compositePeriodIdx = 0;
  2456. CurrentTime = time(NULL);
  2457. tmComposite=localtime(&CurrentTime);
  2458. 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);
  2459. if(isUnitA)
  2460. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2461. else
  2462. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2463. compositeProfile.ChargingSchedule.Duration = durationReq;
  2464. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2465. {
  2466. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2467. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2468. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2469. }
  2470. compositeProfile.ChargingProfileId = 0;
  2471. compositeProfile.StackLevel = 99 ;
  2472. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2473. maxProfile.ChargingProfileId = -1;
  2474. defaultTxProfile.ChargingProfileId = -1;
  2475. txProfile.ChargingProfileId = -1;
  2476. maxProfile.ChargingSchedule.Duration = -1;
  2477. defaultTxProfile.ChargingSchedule.Duration = -1;
  2478. txProfile.ChargingSchedule.Duration = -1;
  2479. system("rm -f /tmp/*.json");
  2480. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2481. /*
  2482. * Search valid charging profile
  2483. */
  2484. //DEBUG_INFO("====================================\n");
  2485. // Search tx profile
  2486. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2487. if((access(profileFileName, F_OK))!=-1)
  2488. {
  2489. fp = fopen(profileFileName, "r");
  2490. while(getline(&line, &len, fp) != -1)
  2491. {
  2492. json_object *obj = NULL;
  2493. obj = json_tokener_parse(line);
  2494. if(is_error(obj))
  2495. {
  2496. DEBUG_ERROR("Parse txProfile from file error.\n");
  2497. }
  2498. else
  2499. {
  2500. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2501. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2502. )
  2503. {
  2504. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2505. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2506. )
  2507. {
  2508. struct tm tmFrom, tmTo;
  2509. struct timeb tbFrom, tbTo;
  2510. 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) &&
  2511. (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))
  2512. {
  2513. tmFrom.tm_year -= 1900;
  2514. tmFrom.tm_mon -= 1;
  2515. tbFrom.time = mktime(&tmFrom);
  2516. tmTo.tm_year -= 1900;
  2517. tmTo.tm_mon -= 1;
  2518. tbTo.time = mktime(&tmTo);
  2519. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2520. {
  2521. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2522. {
  2523. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2524. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2525. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2526. }
  2527. if(txProfile.ChargingProfileId == -1)
  2528. DEBUG_INFO("TxProfile found.\n");
  2529. else
  2530. DEBUG_INFO("TxProfile updated.\n");
  2531. // Required item
  2532. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2533. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2534. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2535. if(isUnitA)
  2536. {
  2537. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2538. 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++)
  2539. {
  2540. 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"));
  2541. 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?
  2542. 3:
  2543. 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")));
  2544. 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")));
  2545. }
  2546. }
  2547. else
  2548. {
  2549. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2550. 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++)
  2551. {
  2552. 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"));
  2553. 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?
  2554. 3:
  2555. 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")));
  2556. 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));
  2557. }
  2558. }
  2559. // Optional item
  2560. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2561. {
  2562. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2563. }
  2564. else
  2565. {
  2566. sprintf((char*)txProfile.ValidFrom, " ");
  2567. }
  2568. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2569. {
  2570. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2571. }
  2572. else
  2573. {
  2574. sprintf((char*)txProfile.ValidTo, " ");
  2575. }
  2576. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2577. {
  2578. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2579. }
  2580. else
  2581. {
  2582. sprintf((char*)txProfile.RecurrencyKind, " ");
  2583. }
  2584. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2585. {
  2586. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2587. }
  2588. else
  2589. {
  2590. txProfile.TransactionId = -1;
  2591. }
  2592. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2593. {
  2594. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2595. }
  2596. else
  2597. {
  2598. txProfile.ChargingSchedule.Duration = 86400;
  2599. }
  2600. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2601. {
  2602. 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")));
  2603. }
  2604. else
  2605. {
  2606. 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));
  2607. }
  2608. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2609. {
  2610. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2611. }
  2612. else
  2613. {
  2614. txProfile.ChargingSchedule.MinChargingRate = -1;
  2615. }
  2616. }
  2617. }
  2618. }
  2619. else
  2620. {
  2621. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2622. {
  2623. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2624. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2625. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2626. }
  2627. if(txProfile.ChargingProfileId == -1)
  2628. DEBUG_INFO("TxProfile found.\n");
  2629. else
  2630. DEBUG_INFO("TxProfile updated.\n");
  2631. // Required item
  2632. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2633. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2634. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2635. if(isUnitA)
  2636. {
  2637. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2638. 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++)
  2639. {
  2640. 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"));
  2641. 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?
  2642. 3:
  2643. 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")));
  2644. 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")));
  2645. }
  2646. }
  2647. else
  2648. {
  2649. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2650. 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++)
  2651. {
  2652. 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"));
  2653. 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?
  2654. 3:
  2655. 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")));
  2656. 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));
  2657. }
  2658. }
  2659. // Optional item
  2660. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2661. {
  2662. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2663. }
  2664. else
  2665. {
  2666. sprintf((char*)txProfile.ValidFrom, " ");
  2667. }
  2668. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2669. {
  2670. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2671. }
  2672. else
  2673. {
  2674. sprintf((char*)txProfile.ValidTo, " ");
  2675. }
  2676. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2677. {
  2678. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2679. }
  2680. else
  2681. {
  2682. sprintf((char*)txProfile.RecurrencyKind, " ");
  2683. }
  2684. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2685. {
  2686. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2687. }
  2688. else
  2689. {
  2690. txProfile.TransactionId = -1;
  2691. }
  2692. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2693. {
  2694. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2695. }
  2696. else
  2697. {
  2698. txProfile.ChargingSchedule.Duration = 86400;
  2699. }
  2700. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2701. {
  2702. 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")));
  2703. }
  2704. else
  2705. {
  2706. 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));
  2707. }
  2708. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2709. {
  2710. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2711. }
  2712. else
  2713. {
  2714. txProfile.ChargingSchedule.MinChargingRate = -1;
  2715. }
  2716. }
  2717. }
  2718. }
  2719. json_object_put(obj);
  2720. }
  2721. fclose(fp);
  2722. /*
  2723. if(txProfile.ChargingProfileId != -1)
  2724. {
  2725. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2726. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2727. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2728. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2729. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2730. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2731. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2732. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2733. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2734. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2735. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2736. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2737. {
  2738. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2739. {
  2740. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2741. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2742. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2743. }
  2744. }
  2745. }
  2746. else
  2747. DEBUG_INFO("TxProfile not found.\n");*/
  2748. }
  2749. // Search default tx profile
  2750. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2751. if((access(profileFileName, F_OK))==-1)
  2752. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2753. if((access(profileFileName, F_OK))!=-1)
  2754. {
  2755. fp = fopen(profileFileName, "r");
  2756. while(getline(&line, &len, fp) != -1)
  2757. {
  2758. json_object *obj = NULL;
  2759. obj = json_tokener_parse(line);
  2760. if(is_error(obj))
  2761. {
  2762. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2763. }
  2764. else
  2765. {
  2766. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2767. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2768. )
  2769. {
  2770. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2771. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2772. )
  2773. {
  2774. struct tm tmFrom, tmTo;
  2775. struct timeb tbFrom, tbTo;
  2776. 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) &&
  2777. (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))
  2778. {
  2779. tmFrom.tm_year -= 1900;
  2780. tmFrom.tm_mon -= 1;
  2781. tbFrom.time = mktime(&tmFrom);
  2782. tmTo.tm_year -= 1900;
  2783. tmTo.tm_mon -= 1;
  2784. tbTo.time = mktime(&tmTo);
  2785. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2786. {
  2787. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2788. {
  2789. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2790. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2791. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2792. }
  2793. if(defaultTxProfile.ChargingProfileId == -1)
  2794. DEBUG_INFO("TxDefaultProfile found.\n");
  2795. else
  2796. DEBUG_INFO("TxDefaultProfile updated.\n");
  2797. // Required item
  2798. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2799. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2800. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2801. if(isUnitA)
  2802. {
  2803. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2804. 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++)
  2805. {
  2806. 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"));
  2807. 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?
  2808. 3:
  2809. 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")));
  2810. 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")));
  2811. }
  2812. }
  2813. else
  2814. {
  2815. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2816. 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++)
  2817. {
  2818. 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"));
  2819. 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?
  2820. 3:
  2821. 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")));
  2822. 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));
  2823. }
  2824. }
  2825. // Optional item
  2826. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2827. {
  2828. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2829. }
  2830. else
  2831. {
  2832. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2833. }
  2834. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2835. {
  2836. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2837. }
  2838. else
  2839. {
  2840. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2841. }
  2842. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2843. {
  2844. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2845. }
  2846. else
  2847. {
  2848. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2849. }
  2850. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2851. {
  2852. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2853. }
  2854. else
  2855. {
  2856. defaultTxProfile.TransactionId = -1;
  2857. }
  2858. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2859. {
  2860. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2861. }
  2862. else
  2863. {
  2864. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2865. }
  2866. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2867. {
  2868. 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")));
  2869. }
  2870. else
  2871. {
  2872. 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));
  2873. }
  2874. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2875. {
  2876. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2877. }
  2878. else
  2879. {
  2880. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2881. }
  2882. }
  2883. }
  2884. }
  2885. else
  2886. {
  2887. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2888. {
  2889. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2890. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2891. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2892. }
  2893. if(defaultTxProfile.ChargingProfileId == -1)
  2894. DEBUG_INFO("TxDefaultProfile found.\n");
  2895. else
  2896. DEBUG_INFO("TxDefaultProfile updated.\n");
  2897. // Required item
  2898. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2899. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2900. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2901. if(isUnitA)
  2902. {
  2903. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2904. 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++)
  2905. {
  2906. 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"));
  2907. 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?
  2908. 3:
  2909. 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")));
  2910. 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")));
  2911. }
  2912. }
  2913. else
  2914. {
  2915. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2916. 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++)
  2917. {
  2918. 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"));
  2919. 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?
  2920. 3:
  2921. 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")));
  2922. 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));
  2923. }
  2924. }
  2925. // Optional item
  2926. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2927. {
  2928. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2929. }
  2930. else
  2931. {
  2932. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2933. }
  2934. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2935. {
  2936. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2937. }
  2938. else
  2939. {
  2940. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2941. }
  2942. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2943. {
  2944. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2945. }
  2946. else
  2947. {
  2948. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2949. }
  2950. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2951. {
  2952. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2953. }
  2954. else
  2955. {
  2956. defaultTxProfile.TransactionId = -1;
  2957. }
  2958. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2959. {
  2960. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2961. }
  2962. else
  2963. {
  2964. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2965. }
  2966. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2967. {
  2968. 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")));
  2969. }
  2970. else
  2971. {
  2972. 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));
  2973. }
  2974. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2975. {
  2976. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2977. }
  2978. else
  2979. {
  2980. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2981. }
  2982. }
  2983. }
  2984. }
  2985. json_object_put(obj);
  2986. }
  2987. fclose(fp);
  2988. /*
  2989. if(defaultTxProfile.ChargingProfileId != -1)
  2990. {
  2991. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2992. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2993. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2994. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2995. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2996. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2997. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2998. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2999. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3000. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3001. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3002. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3003. {
  3004. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3005. {
  3006. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3007. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3008. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3009. }
  3010. }
  3011. }
  3012. else
  3013. DEBUG_INFO("TxDefaultProfile not found.\n");
  3014. DEBUG_INFO("------------------------------------\n");*/
  3015. }
  3016. // Search max profile
  3017. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  3018. if((access(profileFileName, F_OK))!=-1)
  3019. {
  3020. fp = fopen(profileFileName, "r");
  3021. while(getline(&line, &len, fp) != -1)
  3022. {
  3023. json_object *obj = NULL;
  3024. obj = json_tokener_parse(line);
  3025. if(is_error(obj))
  3026. {
  3027. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  3028. }
  3029. else
  3030. {
  3031. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  3032. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  3033. )
  3034. {
  3035. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3036. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3037. )
  3038. {
  3039. struct tm tmFrom, tmTo;
  3040. struct timeb tbFrom, tbTo;
  3041. 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) &&
  3042. (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))
  3043. {
  3044. tmFrom.tm_year -= 1900;
  3045. tmFrom.tm_mon -= 1;
  3046. tbFrom.time = mktime(&tmFrom);
  3047. tmTo.tm_year -= 1900;
  3048. tmTo.tm_mon -= 1;
  3049. tbTo.time = mktime(&tmTo);
  3050. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3051. {
  3052. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3053. {
  3054. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3055. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3056. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3057. }
  3058. if(maxProfile.ChargingProfileId == -1)
  3059. DEBUG_INFO("MaxProfile found.\n");
  3060. else
  3061. DEBUG_INFO("MaxProfile updated.\n");
  3062. // Required item
  3063. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3064. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3065. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3066. if(isUnitA)
  3067. {
  3068. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3069. 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++)
  3070. {
  3071. 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"));
  3072. 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?
  3073. 3:
  3074. 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")));
  3075. 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")));
  3076. }
  3077. }
  3078. else
  3079. {
  3080. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3081. 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++)
  3082. {
  3083. 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"));
  3084. 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?
  3085. 3:
  3086. 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")));
  3087. 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));
  3088. }
  3089. }
  3090. // Optional item
  3091. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3092. {
  3093. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3094. }
  3095. else
  3096. {
  3097. sprintf((char*)maxProfile.ValidFrom, " ");
  3098. }
  3099. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3100. {
  3101. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3102. }
  3103. else
  3104. {
  3105. sprintf((char*)maxProfile.ValidTo, " ");
  3106. }
  3107. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3108. {
  3109. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3110. }
  3111. else
  3112. {
  3113. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3114. }
  3115. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3116. {
  3117. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3118. }
  3119. else
  3120. {
  3121. maxProfile.TransactionId = -1;
  3122. }
  3123. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3124. {
  3125. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3126. }
  3127. else
  3128. {
  3129. maxProfile.ChargingSchedule.Duration = 86400;
  3130. }
  3131. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3132. {
  3133. 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")));
  3134. }
  3135. else
  3136. {
  3137. 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));
  3138. }
  3139. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3140. {
  3141. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3142. }
  3143. else
  3144. {
  3145. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3146. }
  3147. }
  3148. }
  3149. }
  3150. else
  3151. {
  3152. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3153. {
  3154. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3155. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3156. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3157. }
  3158. if(maxProfile.ChargingProfileId == -1)
  3159. DEBUG_INFO("MaxProfile found.\n");
  3160. else
  3161. DEBUG_INFO("MaxProfile updated.\n");
  3162. // Required item
  3163. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3164. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3165. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3166. if(isUnitA)
  3167. {
  3168. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3169. 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++)
  3170. {
  3171. 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"));
  3172. 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?
  3173. 3:
  3174. 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")));
  3175. 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")));
  3176. }
  3177. }
  3178. else
  3179. {
  3180. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3181. 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++)
  3182. {
  3183. 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"));
  3184. 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?
  3185. 3:
  3186. 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")));
  3187. 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));
  3188. }
  3189. }
  3190. // Optional item
  3191. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3192. {
  3193. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3194. }
  3195. else
  3196. {
  3197. sprintf((char*)maxProfile.ValidFrom, " ");
  3198. }
  3199. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3200. {
  3201. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3202. }
  3203. else
  3204. {
  3205. sprintf((char*)maxProfile.ValidTo, " ");
  3206. }
  3207. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3208. {
  3209. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3210. }
  3211. else
  3212. {
  3213. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3214. }
  3215. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3216. {
  3217. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3218. }
  3219. else
  3220. {
  3221. maxProfile.TransactionId = -1;
  3222. }
  3223. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3224. {
  3225. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3226. }
  3227. else
  3228. {
  3229. maxProfile.ChargingSchedule.Duration = 86400;
  3230. }
  3231. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3232. {
  3233. 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")));
  3234. }
  3235. else
  3236. {
  3237. 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));
  3238. }
  3239. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3240. {
  3241. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3242. }
  3243. else
  3244. {
  3245. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3246. }
  3247. }
  3248. }
  3249. }
  3250. json_object_put(obj);
  3251. }
  3252. fclose(fp);
  3253. /*
  3254. if(maxProfile.ChargingProfileId !=-1)
  3255. {
  3256. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3257. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3258. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3259. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3260. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3261. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3262. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3263. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3264. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3265. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3266. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3267. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3268. {
  3269. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3270. {
  3271. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3272. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3273. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3274. }
  3275. }
  3276. }
  3277. else
  3278. DEBUG_INFO("MaxProfile not found.\n");
  3279. DEBUG_INFO("------------------------------------\n");*/
  3280. }
  3281. /*
  3282. * Align found profile start schedule & periods
  3283. */
  3284. //DEBUG_INFO("====================================\n");
  3285. /*
  3286. // For local test usage, force modify found profile start schedule info
  3287. 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);
  3288. 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);
  3289. 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);
  3290. */
  3291. if(txProfile.ChargingProfileId != -1)
  3292. {
  3293. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3294. {
  3295. if(txProfile.ChargingSchedule.Duration != -1)
  3296. {
  3297. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3298. 0:
  3299. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3300. }
  3301. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3302. {
  3303. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3304. {
  3305. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3306. 0:
  3307. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3308. if(idxPeriod > 0)
  3309. {
  3310. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3311. {
  3312. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3313. }
  3314. }
  3315. }
  3316. }
  3317. }
  3318. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3319. {
  3320. if(txProfile.ChargingSchedule.Duration != -1)
  3321. {
  3322. 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?
  3323. 0:
  3324. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3325. }
  3326. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3327. {
  3328. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3329. {
  3330. 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?
  3331. 0:
  3332. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3333. if(idxPeriod > 0)
  3334. {
  3335. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3336. {
  3337. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3338. }
  3339. }
  3340. }
  3341. }
  3342. }
  3343. else
  3344. {
  3345. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3346. {
  3347. if(txProfile.ChargingSchedule.Duration != -1)
  3348. {
  3349. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3350. 0:
  3351. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3352. }
  3353. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3354. {
  3355. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3356. {
  3357. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3358. 0:
  3359. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3360. if(idxPeriod > 0)
  3361. {
  3362. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3363. {
  3364. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3365. }
  3366. }
  3367. }
  3368. }
  3369. }
  3370. else
  3371. {
  3372. if(txProfile.ChargingSchedule.Duration != -1)
  3373. {
  3374. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3375. 0:
  3376. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3377. }
  3378. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3379. {
  3380. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3381. {
  3382. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3383. 0:
  3384. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3385. if(idxPeriod > 0)
  3386. {
  3387. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3388. {
  3389. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3390. }
  3391. }
  3392. }
  3393. }
  3394. }
  3395. }
  3396. /*
  3397. DEBUG_INFO("txProfile after align.\n");
  3398. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3399. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3400. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3401. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3402. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3403. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3404. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3405. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3406. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3407. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3408. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3409. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3410. {
  3411. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3412. {
  3413. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3414. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3415. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3416. }
  3417. }*/
  3418. }
  3419. if(defaultTxProfile.ChargingProfileId != -1)
  3420. {
  3421. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3422. {
  3423. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3424. {
  3425. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3426. 0:
  3427. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3428. }
  3429. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3430. {
  3431. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3432. {
  3433. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3434. 0:
  3435. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3436. if(idxPeriod > 0)
  3437. {
  3438. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3439. {
  3440. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3441. }
  3442. }
  3443. }
  3444. }
  3445. }
  3446. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3447. {
  3448. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3449. {
  3450. 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?
  3451. 0:
  3452. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3453. }
  3454. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3455. {
  3456. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3457. {
  3458. 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?
  3459. 0:
  3460. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3461. if(idxPeriod > 0)
  3462. {
  3463. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3464. {
  3465. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3466. }
  3467. }
  3468. }
  3469. }
  3470. }
  3471. else
  3472. {
  3473. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3474. {
  3475. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3476. {
  3477. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3478. 0:
  3479. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3480. }
  3481. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3482. {
  3483. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3484. {
  3485. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3486. 0:
  3487. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3488. if(idxPeriod > 0)
  3489. {
  3490. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3491. {
  3492. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3493. }
  3494. }
  3495. }
  3496. }
  3497. }
  3498. else
  3499. {
  3500. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3501. {
  3502. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3503. 0:
  3504. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3505. }
  3506. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3507. {
  3508. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3509. {
  3510. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3511. 0:
  3512. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3513. if(idxPeriod > 0)
  3514. {
  3515. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3516. {
  3517. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3518. }
  3519. }
  3520. }
  3521. }
  3522. }
  3523. }
  3524. /*
  3525. DEBUG_INFO("defaultTxProfile after align.\n");
  3526. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3527. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3528. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3529. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3530. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3531. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3532. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3533. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3534. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3535. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3536. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3537. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3538. {
  3539. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3540. {
  3541. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3542. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3543. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3544. }
  3545. }
  3546. DEBUG_INFO("------------------------------------\n");*/
  3547. }
  3548. if(maxProfile.ChargingProfileId != -1)
  3549. {
  3550. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3551. {
  3552. if(maxProfile.ChargingSchedule.Duration != -1)
  3553. {
  3554. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3555. 0:
  3556. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3557. }
  3558. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3559. {
  3560. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3561. {
  3562. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3563. 0:
  3564. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3565. if(idxPeriod > 0)
  3566. {
  3567. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3568. {
  3569. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3570. }
  3571. }
  3572. }
  3573. }
  3574. }
  3575. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3576. {
  3577. if(maxProfile.ChargingSchedule.Duration != -1)
  3578. {
  3579. 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?
  3580. 0:
  3581. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3582. }
  3583. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3584. {
  3585. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3586. {
  3587. 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?
  3588. 0:
  3589. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3590. if(idxPeriod > 0)
  3591. {
  3592. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3593. {
  3594. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3595. }
  3596. }
  3597. }
  3598. }
  3599. }
  3600. else
  3601. {
  3602. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3603. {
  3604. if(maxProfile.ChargingSchedule.Duration != -1)
  3605. {
  3606. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3607. 0:
  3608. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3609. }
  3610. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3611. {
  3612. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3613. {
  3614. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3615. 0:
  3616. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3617. if(idxPeriod > 0)
  3618. {
  3619. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3620. {
  3621. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3622. }
  3623. }
  3624. }
  3625. }
  3626. }
  3627. else
  3628. {
  3629. if(maxProfile.ChargingSchedule.Duration != -1)
  3630. {
  3631. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3632. 0:
  3633. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3634. }
  3635. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3636. {
  3637. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3638. {
  3639. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3640. 0:
  3641. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3642. if(idxPeriod > 0)
  3643. {
  3644. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3645. {
  3646. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3647. }
  3648. }
  3649. }
  3650. }
  3651. }
  3652. }
  3653. /*
  3654. DEBUG_INFO("MaxProfile after align.\n");
  3655. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3656. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3657. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3658. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3659. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3660. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3661. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3662. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3663. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3664. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3665. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3666. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3667. {
  3668. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3669. {
  3670. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3671. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3672. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3673. }
  3674. }
  3675. DEBUG_INFO("------------------------------------\n");*/
  3676. }
  3677. /*
  3678. * Merge to conposite schedule
  3679. */
  3680. //DEBUG_INFO("====================================\n");
  3681. // Find each profile period quantity
  3682. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3683. {
  3684. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3685. limitMax = idx+1;
  3686. }
  3687. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3688. {
  3689. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3690. limitDef = idx+1;
  3691. }
  3692. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3693. {
  3694. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3695. limitTx = idx+1;
  3696. }
  3697. // TxProfile found, composite schedule based on it
  3698. if(txProfile.ChargingProfileId != -1)
  3699. {
  3700. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3701. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3702. {
  3703. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3704. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3705. (txProfile.ChargingSchedule.Duration > 0))
  3706. {
  3707. if(maxProfile.ChargingProfileId != -1)
  3708. {
  3709. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3710. {
  3711. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3712. {
  3713. if((maxProfile.ChargingSchedule.Duration > 0))
  3714. {
  3715. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3716. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3717. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3718. }
  3719. else
  3720. {
  3721. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3722. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3723. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3724. }
  3725. }
  3726. if(idxMaxPeriod == (limitMax-1))
  3727. {
  3728. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3729. {
  3730. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3731. {
  3732. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3733. compositePeriodIdx++;
  3734. }
  3735. else
  3736. {
  3737. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3738. }
  3739. }
  3740. }
  3741. }
  3742. }
  3743. else
  3744. {
  3745. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3746. {
  3747. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3748. compositePeriodIdx++;
  3749. }
  3750. else
  3751. {
  3752. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3753. }
  3754. }
  3755. }
  3756. if(idxTxPeriod == (limitTx-1))
  3757. {
  3758. if(defaultTxProfile.ChargingProfileId != -1)
  3759. {
  3760. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3761. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3762. {
  3763. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3764. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3765. (defaultTxProfile.ChargingSchedule.Duration>0))
  3766. {
  3767. if(maxProfile.ChargingProfileId != -1)
  3768. {
  3769. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3770. {
  3771. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3772. {
  3773. if((maxProfile.ChargingSchedule.Duration > 0))
  3774. {
  3775. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3776. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3777. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3778. }
  3779. else
  3780. {
  3781. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3782. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3783. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3784. }
  3785. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3786. {
  3787. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3788. {
  3789. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3790. compositePeriodIdx++;
  3791. }
  3792. else
  3793. {
  3794. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3795. }
  3796. }
  3797. // Delete duplicate period
  3798. if(compositePeriodIdx > 1)
  3799. {
  3800. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3801. {
  3802. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3803. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3804. compositePeriodIdx -= 1;
  3805. }
  3806. }
  3807. }
  3808. else
  3809. {
  3810. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3811. {
  3812. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3813. compositePeriodIdx++;
  3814. }
  3815. else
  3816. {
  3817. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3818. }
  3819. break;
  3820. }
  3821. }
  3822. }
  3823. else
  3824. {
  3825. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3826. {
  3827. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3828. compositePeriodIdx++;
  3829. }
  3830. else
  3831. {
  3832. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3833. }
  3834. }
  3835. }
  3836. }
  3837. }
  3838. }
  3839. }
  3840. }
  3841. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3842. else if(defaultTxProfile.ChargingProfileId != -1)
  3843. {
  3844. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3845. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3846. {
  3847. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3848. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3849. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3850. {
  3851. if(maxProfile.ChargingProfileId != -1)
  3852. {
  3853. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3854. {
  3855. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3856. {
  3857. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3858. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3859. if((maxProfile.ChargingSchedule.Duration > 0))
  3860. {
  3861. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3862. }
  3863. else
  3864. {
  3865. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3866. }
  3867. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3868. {
  3869. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3870. {
  3871. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3872. compositePeriodIdx++;
  3873. }
  3874. else
  3875. {
  3876. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3877. }
  3878. }
  3879. // Delete duplicate period
  3880. if(compositePeriodIdx > 1)
  3881. {
  3882. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3883. {
  3884. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3885. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3886. compositePeriodIdx -= 1;
  3887. }
  3888. }
  3889. }
  3890. else
  3891. {
  3892. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3893. {
  3894. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3895. compositePeriodIdx++;
  3896. }
  3897. else
  3898. {
  3899. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3900. }
  3901. break;
  3902. }
  3903. }
  3904. }
  3905. else
  3906. {
  3907. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3908. {
  3909. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3910. compositePeriodIdx++;
  3911. }
  3912. else
  3913. {
  3914. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3915. }
  3916. }
  3917. }
  3918. }
  3919. }
  3920. // Fill other period by MaxProfile
  3921. if(maxProfile.ChargingProfileId != -1)
  3922. {
  3923. if(compositePeriodIdx==0)
  3924. {
  3925. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3926. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3927. {
  3928. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3929. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3930. (maxProfile.ChargingSchedule.Duration > 0))
  3931. {
  3932. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3933. {
  3934. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3935. compositePeriodIdx++;
  3936. }
  3937. else
  3938. {
  3939. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3940. }
  3941. }
  3942. }
  3943. }
  3944. else
  3945. {
  3946. int lastCompositePeriodIdx = compositePeriodIdx;
  3947. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3948. {
  3949. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3950. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3951. (maxProfile.ChargingSchedule.Duration > 0))
  3952. {
  3953. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3954. {
  3955. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3956. {
  3957. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3958. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3959. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3960. }
  3961. else
  3962. {
  3963. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3964. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3965. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3966. }
  3967. }
  3968. if(tmpPeriod.Limit != -1)
  3969. {
  3970. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3971. {
  3972. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3973. {
  3974. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3975. compositePeriodIdx++;
  3976. }
  3977. else
  3978. {
  3979. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3980. }
  3981. }
  3982. // Delete duplicate period
  3983. if(compositePeriodIdx > 1)
  3984. {
  3985. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3986. {
  3987. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3988. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3989. compositePeriodIdx -= 1;
  3990. }
  3991. }
  3992. }
  3993. }
  3994. }
  3995. }
  3996. }
  3997. compositeProfile.ChargingSchedule.Duration = durationReq;
  3998. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3999. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  4000. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  4001. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  4002. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  4003. {
  4004. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4005. {
  4006. compositeProfile.ChargingProfileId = 1;
  4007. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4008. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  4009. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4010. }
  4011. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  4012. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  4013. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  4014. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  4015. }
  4016. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  4017. if(line)
  4018. free(line);
  4019. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  4020. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  4021. }
  4022. //==========================================
  4023. // Init all share memory
  4024. //==========================================
  4025. int InitShareMemory()
  4026. {
  4027. int result = PASS;
  4028. int MeterSMId;
  4029. //creat ShmSysConfigAndInfo
  4030. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  4031. {
  4032. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  4033. result = FAIL;
  4034. }
  4035. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4036. {
  4037. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  4038. result = FAIL;
  4039. }
  4040. else
  4041. {}
  4042. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  4043. {
  4044. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  4045. result = FAIL;
  4046. }
  4047. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4048. {
  4049. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  4050. result = FAIL;
  4051. }
  4052. else
  4053. {}
  4054. //creat ShmPsuData
  4055. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  4056. {
  4057. DEBUG_ERROR("shmget ShmPsuData NG\n");
  4058. result = FAIL;
  4059. }
  4060. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4061. {
  4062. DEBUG_ERROR("shmat ShmPsuData NG\n");
  4063. result = FAIL;
  4064. }
  4065. else
  4066. {}
  4067. //creat ShmOCPP16Data
  4068. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  4069. {
  4070. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  4071. result = FAIL;
  4072. }
  4073. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4074. {
  4075. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  4076. result = FAIL;
  4077. }
  4078. else
  4079. {}
  4080. /****************************** For Initial Settings************************************************/
  4081. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  4082. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  4083. // allocate Configuration memory address
  4084. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  4085. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  4086. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  4087. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  4088. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  4089. //offline MeterValue Interval
  4090. TempMeterValueInterval = 0;
  4091. return result;
  4092. }
  4093. int ProcessShareMemory()
  4094. {
  4095. int result = PASS;
  4096. if(InitShareMemory() == FAIL)
  4097. {
  4098. DEBUG_ERROR("InitShareMemory NG\n");
  4099. if(ShmStatusCodeData!=NULL)
  4100. {
  4101. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  4102. }
  4103. result = FAIL;
  4104. }
  4105. // Model name parsing
  4106. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  4107. {
  4108. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  4109. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  4110. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  4111. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  4112. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  4113. ) // 'D' means DC
  4114. {
  4115. // DO series
  4116. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  4117. {
  4118. gunTotalNumber += 1;
  4119. gunType[gun_index] = GUN_TYPE_DO;
  4120. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4121. {
  4122. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  4123. {
  4124. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4125. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4126. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  4127. }
  4128. }
  4129. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4130. {
  4131. case Gun_Type_Chademo:
  4132. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  4133. break;
  4134. case Gun_Type_CCS_2:
  4135. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  4136. break;
  4137. case Gun_Type_GB:
  4138. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  4139. break;
  4140. case Gun_Type_AC:
  4141. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  4142. break;
  4143. default:
  4144. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  4145. break;
  4146. }
  4147. }
  4148. }
  4149. else
  4150. {
  4151. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  4152. {
  4153. gunTotalNumber += 1;
  4154. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4155. {
  4156. case Gun_Type_Chademo:
  4157. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  4158. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  4159. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  4160. {
  4161. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4162. {
  4163. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4164. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4165. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4166. }
  4167. }
  4168. break;
  4169. case Gun_Type_CCS_2:
  4170. gunType[gun_index] = GUN_TYPE_CCS;
  4171. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4172. for (int index = 0; index < CCS_QUANTITY; index++)
  4173. {
  4174. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4175. {
  4176. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4177. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4178. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4179. }
  4180. }
  4181. break;
  4182. case Gun_Type_GB:
  4183. gunType[gun_index] = GUN_TYPE_GBT;
  4184. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4185. for (int index = 0; index < GB_QUANTITY; index++)
  4186. {
  4187. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4188. {
  4189. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4190. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4191. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4192. }
  4193. }
  4194. break;
  4195. case Gun_Type_AC:
  4196. gunType[gun_index] = GUN_TYPE_AC;
  4197. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4198. for (int index = 0; index < AC_QUANTITY; index++)
  4199. {
  4200. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4201. {
  4202. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4203. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4204. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4205. }
  4206. }
  4207. break;
  4208. default:
  4209. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4210. break;
  4211. }
  4212. }
  4213. }
  4214. }
  4215. else
  4216. {
  4217. DEBUG_ERROR("Model name parsing fail.\n");
  4218. result = FAIL;
  4219. }
  4220. if(result != PASS)sleep(5);
  4221. return result;
  4222. }
  4223. void checkRemoteStart(uint8_t connectorIdInt)
  4224. {
  4225. uint8_t tempIndex;
  4226. int result = PASS;
  4227. char cmdBuf[512];
  4228. //check Transaction active
  4229. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4230. {
  4231. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4232. {
  4233. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4234. }
  4235. else
  4236. {
  4237. tempIndex = connectorIdInt -1;
  4238. }
  4239. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4240. {
  4241. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4242. {
  4243. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4244. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4245. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4246. {
  4247. //Reserved
  4248. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4249. }
  4250. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4251. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4252. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4253. {
  4254. //Reserved
  4255. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4256. result = FAIL;
  4257. goto end;
  4258. }
  4259. else
  4260. {
  4261. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4262. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4263. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4264. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4265. {
  4266. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4267. result = FAIL;
  4268. goto end;
  4269. }
  4270. }//END FOR ELSE
  4271. }
  4272. }// END FOR CHAdeMO_QUANTITY
  4273. }
  4274. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4275. {
  4276. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4277. {
  4278. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4279. }
  4280. else
  4281. {
  4282. tempIndex = connectorIdInt -1;
  4283. }
  4284. for (int index = 0; index < CCS_QUANTITY; index++)
  4285. {
  4286. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4287. {
  4288. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4289. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4290. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4291. {
  4292. //Reserved
  4293. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4294. }
  4295. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4296. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4297. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4298. {
  4299. //Reserved
  4300. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4301. result = FAIL;
  4302. goto end;
  4303. }
  4304. else
  4305. {
  4306. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4307. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4308. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4309. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4310. {
  4311. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4312. result = FAIL;
  4313. goto end;
  4314. }
  4315. }// END FOR ELSE
  4316. }
  4317. }// END FOR CCS_QUANTITY
  4318. }
  4319. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4320. {
  4321. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4322. {
  4323. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4324. }
  4325. else
  4326. {
  4327. tempIndex = connectorIdInt -1;
  4328. }
  4329. for (int index = 0; index < GB_QUANTITY; index++)
  4330. {
  4331. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4332. {
  4333. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4334. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4335. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4336. {
  4337. //Reserved
  4338. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4339. }
  4340. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4341. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4342. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4343. {
  4344. //Reserved
  4345. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4346. result = FAIL;
  4347. goto end;
  4348. }
  4349. else
  4350. {
  4351. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4352. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4353. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4354. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4355. {
  4356. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4357. result = FAIL;
  4358. goto end;
  4359. }
  4360. }// END FOR ELSE
  4361. }
  4362. } // END FOR GB_QUANTITY
  4363. }
  4364. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4365. {
  4366. tempIndex = connectorIdInt -1;
  4367. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4368. {
  4369. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4370. {
  4371. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4372. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4373. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4374. {
  4375. //Reserved
  4376. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4377. }
  4378. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4379. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4380. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4381. {
  4382. //Reserved
  4383. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4384. result = FAIL;
  4385. goto end;
  4386. }
  4387. else
  4388. {
  4389. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4390. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4391. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4392. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4393. {
  4394. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4395. result = FAIL;
  4396. goto end;
  4397. }
  4398. }// END FOR ELSE
  4399. }
  4400. } // END FOR GB_QUANTITY
  4401. }
  4402. else
  4403. {
  4404. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4405. {
  4406. tempIndex = 2;
  4407. }
  4408. else
  4409. {
  4410. tempIndex = connectorIdInt -1;
  4411. }
  4412. for (int index = 0; index < AC_QUANTITY; index++)
  4413. {
  4414. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4415. {
  4416. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4417. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4418. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4419. {
  4420. //Reserved
  4421. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4422. }
  4423. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4424. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4425. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4426. {
  4427. //Reserved
  4428. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4429. result = FAIL;
  4430. goto end;
  4431. }
  4432. else
  4433. {
  4434. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4435. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4436. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4437. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4438. {
  4439. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4440. result = FAIL;
  4441. goto end;
  4442. }
  4443. }//END FOR ELSE
  4444. }
  4445. }// END FOR AC_QUANTITY
  4446. }
  4447. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4448. {
  4449. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4450. {
  4451. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4452. {
  4453. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4454. system(cmdBuf);
  4455. }
  4456. }
  4457. else
  4458. {
  4459. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4460. result = FAIL;
  4461. }
  4462. }
  4463. end:
  4464. if(result == PASS)
  4465. {
  4466. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4467. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4468. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4469. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4470. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4471. }
  4472. }
  4473. void CheckSystemValue(void)
  4474. {
  4475. char filenmae[100]={0};
  4476. char str[100]={0};
  4477. int tempIndex = 0;
  4478. //===============================
  4479. // send Heartbeat
  4480. //===============================
  4481. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4482. {
  4483. //parameter for test
  4484. sendHeartbeatRequest(0);
  4485. //===========================
  4486. // Reset Waiting Time
  4487. //===========================
  4488. HeartBeatWithNOResponse += 1;
  4489. }
  4490. //===============================
  4491. // Credit deduct report
  4492. //===============================
  4493. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4494. {
  4495. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4496. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4497. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4498. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4499. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4500. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4501. }
  4502. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4503. {
  4504. OCPP_query_deduct_info();
  4505. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4506. }
  4507. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4508. {
  4509. // ClockAlign MeterValue
  4510. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4511. {
  4512. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4513. {
  4514. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4515. {
  4516. tempIndex = ((gun_index==2) ? 1: 0);
  4517. }
  4518. else
  4519. {
  4520. tempIndex = gun_index;
  4521. }
  4522. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4523. {
  4524. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4525. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4526. {
  4527. reqClockAlignMeter[gun_index] = 1;
  4528. }
  4529. }// End for CHAdeMO
  4530. }
  4531. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4532. {
  4533. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4534. {
  4535. tempIndex = ((gun_index==2) ? 1: 0);
  4536. }
  4537. else
  4538. {
  4539. tempIndex = gun_index;
  4540. }
  4541. for (int index = 0; index < CCS_QUANTITY; index++)
  4542. {
  4543. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4544. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4545. {
  4546. reqClockAlignMeter[gun_index] = 1;
  4547. }
  4548. } // End for CCS
  4549. }
  4550. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4551. {
  4552. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4553. {
  4554. tempIndex = ((gun_index==2) ? 1: 0);
  4555. }
  4556. else
  4557. {
  4558. tempIndex = gun_index;
  4559. }
  4560. for (int index = 0; index < GB_QUANTITY; index++)
  4561. {
  4562. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4563. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4564. {
  4565. reqClockAlignMeter[gun_index] = 1;
  4566. }
  4567. }// End for GB
  4568. }
  4569. else if(gunType[gun_index] == GUN_TYPE_DO)
  4570. {
  4571. tempIndex = gun_index;
  4572. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4573. {
  4574. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4575. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4576. {
  4577. reqClockAlignMeter[gun_index] = 1;
  4578. }
  4579. }
  4580. }
  4581. else
  4582. {
  4583. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4584. {
  4585. tempIndex = 2;
  4586. }
  4587. else
  4588. {
  4589. tempIndex = gun_index;
  4590. }
  4591. for (int index = 0; index < AC_QUANTITY; index++)
  4592. {
  4593. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4594. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4595. {
  4596. reqClockAlignMeter[gun_index] = 1;
  4597. }
  4598. }//End for AC
  4599. }
  4600. }
  4601. }
  4602. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4603. {
  4604. //==========================================
  4605. // Check remote start without connector id
  4606. //==========================================
  4607. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4608. {
  4609. int connectorIdInt = -1;
  4610. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4611. {
  4612. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4613. {
  4614. connectorIdInt = (gun_index+1);
  4615. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4616. checkRemoteStart(connectorIdInt);
  4617. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4618. break;
  4619. }
  4620. }
  4621. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4622. {
  4623. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4624. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  4625. }
  4626. }
  4627. //==========================================
  4628. // csu trigger DataTransferReq
  4629. //==========================================
  4630. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  4631. {
  4632. sendDataTransferRequest(gun_index);
  4633. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  4634. }
  4635. //==========================================
  4636. // CSU Trigger Authorize Request
  4637. //==========================================
  4638. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4639. {
  4640. sendAuthorizeRequest(0);
  4641. authorizeRetryTimes = authorizeRetryTimes + 1;
  4642. if(authorizeRetryTimes < 3)
  4643. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4644. }
  4645. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4646. {
  4647. authorizeRetryTimes = 0;
  4648. SetOcppConnStatus(FALSE);
  4649. server_sign = FALSE;
  4650. }
  4651. 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))
  4652. {
  4653. sendAuthorizeRequest(0);
  4654. }
  4655. //==========================================
  4656. // Charger start transaction
  4657. //==========================================
  4658. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4659. {
  4660. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4661. sendStartTransactionRequest(gun_index);
  4662. refreshStartTimer(&clientTime.StartTransaction);
  4663. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4664. storeTempStopTransaction(gun_index);
  4665. }
  4666. //==========================================
  4667. // Charger stop transaction
  4668. //==========================================
  4669. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4670. {
  4671. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4672. sendStopTransactionRequest(gun_index);
  4673. OCPP_updatePeriodEnergy(gun_index);
  4674. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  4675. refreshStartTimer(&clientTime.StopTransaction);
  4676. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4677. }
  4678. //==========================================
  4679. // Charger OCMF message
  4680. //==========================================
  4681. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq == 1)))
  4682. {
  4683. sendOcmfByDataTransferRequest(gun_index);
  4684. ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq = 0;
  4685. }
  4686. //==========================================
  4687. // Charger status report
  4688. //==========================================
  4689. //--- Check Mode Change ---//
  4690. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4691. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4692. {
  4693. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4694. {
  4695. tempIndex = ((gun_index==2) ? 1: 0);
  4696. }
  4697. else
  4698. {
  4699. tempIndex = gun_index;
  4700. }
  4701. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4702. {
  4703. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4704. {
  4705. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4706. {
  4707. // Sent unplug message for California pricing logic
  4708. 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])
  4709. {
  4710. uint8_t ts[36];
  4711. getNowDatetime(ts);
  4712. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4713. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4714. if(strcmp((char*)dmsVersion, "2.0")==0)
  4715. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4716. else
  4717. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4718. sendUnplugByDataTransferRequest(gun_index);
  4719. interLock.isSentUnplug[gun_index] = 1;
  4720. }
  4721. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4722. {
  4723. interLock.isSentUnplug[gun_index] = 0;
  4724. }
  4725. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4726. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4727. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4728. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4729. {
  4730. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4731. if((access(filenmae,F_OK))!=-1)
  4732. {
  4733. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4734. sprintf(str,"rm -f %s",filenmae);
  4735. system(str);
  4736. }
  4737. }
  4738. }
  4739. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4740. #if 1 // for TempStopTransaction
  4741. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4742. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4743. {
  4744. checkTempStopTransaction(gun_index);
  4745. }
  4746. #endif
  4747. }
  4748. }
  4749. }
  4750. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4751. {
  4752. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4753. {
  4754. tempIndex = ((gun_index==2) ? 1: 0);
  4755. }
  4756. else
  4757. {
  4758. tempIndex = gun_index;
  4759. }
  4760. for (int index = 0; index < CCS_QUANTITY; index++)
  4761. {
  4762. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4763. {
  4764. 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]*/ )
  4765. {
  4766. // Sent unplug message for California pricing logic
  4767. 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])
  4768. {
  4769. uint8_t ts[36];
  4770. getNowDatetime(ts);
  4771. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4772. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4773. if(strcmp((char*)dmsVersion, "2.0")==0)
  4774. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4775. else
  4776. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4777. sendUnplugByDataTransferRequest(gun_index);
  4778. interLock.isSentUnplug[gun_index] = 1;
  4779. }
  4780. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4781. {
  4782. interLock.isSentUnplug[gun_index] = 0;
  4783. }
  4784. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4785. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4786. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4787. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4788. {
  4789. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4790. if((access(filenmae,F_OK))!=-1)
  4791. {
  4792. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4793. sprintf(str,"rm -f %s",filenmae);
  4794. system(str);
  4795. }
  4796. }
  4797. }
  4798. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4799. #if 1 // for TempStopTransaction
  4800. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4801. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4802. {
  4803. checkTempStopTransaction(gun_index);
  4804. }
  4805. #endif
  4806. }
  4807. }
  4808. }
  4809. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4810. {
  4811. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4812. {
  4813. tempIndex = ((gun_index==2) ? 1: 0);
  4814. }
  4815. else
  4816. {
  4817. tempIndex = gun_index;
  4818. }
  4819. for (int index = 0; index < GB_QUANTITY; index++)
  4820. {
  4821. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4822. {
  4823. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4824. {
  4825. // Sent unplug message for California pricing logic
  4826. 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])
  4827. {
  4828. uint8_t ts[36];
  4829. getNowDatetime(ts);
  4830. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4831. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4832. if(strcmp((char*)dmsVersion, "2.0")==0)
  4833. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4834. else
  4835. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4836. sendUnplugByDataTransferRequest(gun_index);
  4837. interLock.isSentUnplug[gun_index] = 1;
  4838. }
  4839. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4840. {
  4841. interLock.isSentUnplug[gun_index] = 0;
  4842. }
  4843. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4844. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4845. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4846. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4847. {
  4848. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4849. if((access(filenmae,F_OK))!=-1)
  4850. {
  4851. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4852. sprintf(str,"rm -f %s",filenmae);
  4853. system(str);
  4854. }
  4855. }
  4856. }
  4857. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4858. #if 1 // for TempStopTransaction
  4859. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4860. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4861. {
  4862. checkTempStopTransaction(gun_index);
  4863. }
  4864. #endif
  4865. }
  4866. }
  4867. }
  4868. else if(gunType[gun_index] == GUN_TYPE_DO)
  4869. {
  4870. tempIndex = gun_index;
  4871. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4872. {
  4873. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4874. {
  4875. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4876. {
  4877. // Sent unplug message for California pricing logic
  4878. 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])
  4879. {
  4880. uint8_t ts[36];
  4881. getNowDatetime(ts);
  4882. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4883. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4884. if(strcmp((char*)dmsVersion, "2.0")==0)
  4885. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4886. else
  4887. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4888. sendUnplugByDataTransferRequest(gun_index);
  4889. interLock.isSentUnplug[gun_index] = 1;
  4890. }
  4891. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  4892. {
  4893. interLock.isSentUnplug[gun_index] = 0;
  4894. }
  4895. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4896. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4897. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4898. 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
  4899. {
  4900. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4901. if((access(filenmae,F_OK))!=-1)
  4902. {
  4903. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4904. sprintf(str,"rm -f %s",filenmae);
  4905. system(str);
  4906. }
  4907. }
  4908. }
  4909. 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);
  4910. #if 1 // for TempStopTransaction
  4911. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4912. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4913. {
  4914. checkTempStopTransaction(gun_index);
  4915. }
  4916. #endif
  4917. }
  4918. }
  4919. }
  4920. else
  4921. {
  4922. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4923. {
  4924. tempIndex = 2;
  4925. }
  4926. else
  4927. {
  4928. tempIndex = gun_index;
  4929. }
  4930. for (int index = 0; index < AC_QUANTITY; index++)
  4931. {
  4932. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4933. {
  4934. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4935. {
  4936. // Sent unplug message for California pricing logic
  4937. 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])
  4938. {
  4939. uint8_t ts[36];
  4940. getNowDatetime(ts);
  4941. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4942. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4943. if(strcmp((char*)dmsVersion, "2.0")==0)
  4944. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4945. else
  4946. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4947. sendUnplugByDataTransferRequest(gun_index);
  4948. interLock.isSentUnplug[gun_index] = 1;
  4949. }
  4950. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  4951. {
  4952. interLock.isSentUnplug[gun_index] = 0;
  4953. }
  4954. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4955. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4956. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4957. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4958. {
  4959. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4960. if((access(filenmae,F_OK))!=-1)
  4961. {
  4962. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4963. sprintf(str,"rm -f %s",filenmae);
  4964. system(str);
  4965. }
  4966. }
  4967. }
  4968. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4969. #if 1 // for TempStopTransaction
  4970. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4971. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4972. {
  4973. checkTempStopTransaction(gun_index);
  4974. }
  4975. #endif
  4976. }
  4977. }// END
  4978. }
  4979. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf != 1) &&
  4980. (
  4981. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4982. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4983. )
  4984. )
  4985. {
  4986. sendStatusNotificationRequest(gun_index);
  4987. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4988. }
  4989. //==============================================
  4990. // TCCI reader status report
  4991. //==============================================
  4992. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  4993. {
  4994. reportReaderStatus(gun_index);
  4995. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4996. }
  4997. //==============================================
  4998. // CSU Trigger or timer timeout refresh Smart Charging Profile
  4999. //==============================================
  5000. if((ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  5001. ((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))))
  5002. {
  5003. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  5004. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  5005. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  5006. }
  5007. //==============================================
  5008. // Meter report
  5009. //==============================================
  5010. // Trigger MeterValue
  5011. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  5012. {
  5013. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  5014. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  5015. }
  5016. // Clock-aligned Meter value
  5017. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  5018. {
  5019. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  5020. reqClockAlignMeter[gun_index] = 0;
  5021. }
  5022. // Sample period MeterValue
  5023. 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))))
  5024. {
  5025. //check Transaction active
  5026. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5027. {
  5028. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5029. {
  5030. tempIndex = ((gun_index==2) ? 1: 0);
  5031. }
  5032. else
  5033. {
  5034. tempIndex = gun_index;
  5035. }
  5036. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5037. {
  5038. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5039. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5040. {
  5041. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5042. {
  5043. reqSampleMeter[gun_index] = 1;
  5044. }
  5045. }
  5046. }// End for CHAdeMO
  5047. }
  5048. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5049. {
  5050. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5051. {
  5052. tempIndex = ((gun_index==2) ? 1: 0);
  5053. }
  5054. else
  5055. {
  5056. tempIndex = gun_index;
  5057. }
  5058. for (int index = 0; index < CCS_QUANTITY; index++)
  5059. {
  5060. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5061. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5062. {
  5063. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5064. {
  5065. reqSampleMeter[gun_index] = 1;
  5066. }
  5067. }
  5068. } // End for CCS
  5069. }
  5070. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5071. {
  5072. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5073. {
  5074. tempIndex = ((gun_index==2) ? 1: 0);
  5075. }
  5076. else
  5077. {
  5078. tempIndex = gun_index;
  5079. }
  5080. for (int index = 0; index < GB_QUANTITY; index++)
  5081. {
  5082. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5083. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5084. {
  5085. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5086. {
  5087. reqSampleMeter[gun_index] = 1;
  5088. }
  5089. }
  5090. }// End for GB
  5091. }
  5092. else if(gunType[gun_index] == GUN_TYPE_DO)
  5093. {
  5094. tempIndex = gun_index;
  5095. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5096. {
  5097. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5098. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5099. {
  5100. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  5101. {
  5102. reqSampleMeter[gun_index] = 1;
  5103. }
  5104. }
  5105. }
  5106. }
  5107. else
  5108. {
  5109. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5110. {
  5111. tempIndex = 2;
  5112. }
  5113. else
  5114. {
  5115. tempIndex = gun_index;
  5116. }
  5117. for (int index = 0; index < AC_QUANTITY; index++)
  5118. {
  5119. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5120. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5121. {
  5122. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  5123. {
  5124. reqSampleMeter[gun_index] = 1;
  5125. }
  5126. }
  5127. }//End for AC
  5128. }
  5129. if(reqSampleMeter[gun_index] == 1)
  5130. {
  5131. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  5132. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  5133. storeTempStopTransaction(gun_index);
  5134. reqSampleMeter[gun_index] = 0;
  5135. }
  5136. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5137. }
  5138. //==============================================
  5139. // Check Connector reserved
  5140. //==============================================
  5141. //===============================
  5142. // Check if Reserve is expired
  5143. //===============================
  5144. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  5145. {
  5146. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  5147. {
  5148. DEBUG_INFO("reserve expired.\n");
  5149. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  5150. }
  5151. }//END OF Check if Reserve is expired
  5152. //==========================================
  5153. // csu trigger FirmwareStatusNotificationReq
  5154. //==========================================
  5155. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  5156. {
  5157. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  5158. }
  5159. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq == 1))
  5160. {
  5161. sendSignedFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status);
  5162. }
  5163. //==========================================
  5164. // csu trigger DiagnosticsStatusNotificationReq
  5165. //==========================================
  5166. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  5167. {
  5168. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  5169. }
  5170. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq == 1))
  5171. {
  5172. sendLogStatusNotificationRequest((char *)ShmOCPP16Data->LogStatusNotification.status);
  5173. }
  5174. //==========================================
  5175. // csu trigger CancelReservationConf
  5176. //==========================================
  5177. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  5178. {
  5179. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  5180. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  5181. }
  5182. //==========================================
  5183. // csu trigger ChangeAvailabilityConf
  5184. //==========================================
  5185. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  5186. {
  5187. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  5188. }
  5189. //==========================================
  5190. // csu trigger UnlockConnectorConf
  5191. //==========================================
  5192. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  5193. {
  5194. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5195. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5196. }
  5197. //==========================================
  5198. // csu trigger ReserveNowConf
  5199. //==========================================
  5200. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5201. {
  5202. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5203. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5204. }
  5205. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access(CSR_CP,F_OK) != -1))
  5206. {
  5207. sendSignCertificateRequest();
  5208. }
  5209. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq == 1))
  5210. {
  5211. sendSecurityEventNotificationRequest();
  5212. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5213. }
  5214. // Support 15118
  5215. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.SignCertificateReq == 1) && (access(CSR_V2G,F_OK) != -1))
  5216. {
  5217. json_object *data = json_object_new_object();
  5218. // Read csr file content
  5219. memset(ShmOCPP16Data->v2g_extend.SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5220. FILE *fp=fopen(CSR_V2G,"r");
  5221. char *line = NULL;
  5222. size_t len = 0;
  5223. while(getline(&line, &len, fp) != -1)
  5224. {
  5225. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5226. {
  5227. memcpy(&ShmOCPP16Data->v2g_extend.SignCertificate.csr[strlen((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr)], line, (strlen(line)-1));
  5228. }
  5229. }
  5230. fclose(fp);
  5231. json_object_object_add(data, "csr", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5232. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5233. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"SignCertificate");
  5234. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5235. json_object_put(data);
  5236. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5237. ShmOCPP16Data->v2g_extend.SignCertificateReq = 0;
  5238. }
  5239. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.AuthorizeReq == 1))
  5240. {
  5241. memset(&ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo,0,sizeof(struct IdTokenInfoType));
  5242. int parseCertResult = FAIL;
  5243. json_object *data = json_object_new_object();
  5244. json_object *idToken = json_object_new_object();
  5245. json_object *iso15118CertificateHashData = json_object_new_array();
  5246. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate) > 0)
  5247. json_object_object_add(data, "certificate", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5248. strcpy((char *)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5249. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken));
  5250. json_object_object_add(data, "idToken", idToken);
  5251. char parseData[512] = {0};
  5252. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  5253. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].hashAlgorithm, parseData);
  5254. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_SerialNumber, parseData) == PASS)
  5255. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].serialNumber, parseData);
  5256. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  5257. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerNameHash, parseData);
  5258. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  5259. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerKeyHash, parseData);
  5260. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_OcspUrl, parseData) == PASS)
  5261. strcpy((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].responderURL, parseData);
  5262. for(int idx=0; idx < 4; idx++)
  5263. {
  5264. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].responderURL) >= 7)
  5265. {
  5266. json_object *OCSPRequestDataType = json_object_new_object();
  5267. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm));
  5268. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerNameHash));
  5269. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerKeyHash));
  5270. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].serialNumber));
  5271. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].responderURL));
  5272. json_object_array_add(iso15118CertificateHashData, OCSPRequestDataType);
  5273. parseCertResult = PASS;
  5274. }
  5275. }
  5276. if(parseCertResult == PASS)
  5277. {
  5278. json_object_object_add(data, "iso15118CertificateHashData", iso15118CertificateHashData);
  5279. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5280. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Authorize");
  5281. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5282. json_object_put(data);
  5283. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5284. ShmOCPP16Data->v2g_extend.AuthorizeReq = 0;
  5285. }
  5286. else
  5287. {
  5288. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "NoCertificateAvailable");
  5289. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.status, "Invalid");
  5290. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  5291. }
  5292. }
  5293. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq == 1))
  5294. {
  5295. json_object *data = json_object_new_object();
  5296. json_object_object_add(data, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.iso15118SchemaVersion));
  5297. json_object_object_add(data, "action", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.action));
  5298. json_object_object_add(data, "exiRequest", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.exiRequest));
  5299. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5300. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Get15118EVCertificate");
  5301. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5302. json_object_put(data);
  5303. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5304. ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq = 0;
  5305. }
  5306. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.GetCertificateStatusReq == 1))
  5307. {
  5308. json_object *data = json_object_new_object();
  5309. json_object *OCSPRequestDataType = json_object_new_object();
  5310. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.hashAlgorithm));
  5311. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerNameHash));
  5312. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerKeyHash));
  5313. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.serialNumber));
  5314. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.responderURL));
  5315. json_object_object_add(data, "ocspRequestData", OCSPRequestDataType);
  5316. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5317. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"GetInstalledCertificateIds");
  5318. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5319. json_object_put(data);
  5320. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5321. ShmOCPP16Data->v2g_extend.GetCertificateStatusReq = 0;
  5322. }
  5323. }
  5324. }
  5325. //==========================================
  5326. // send request routine
  5327. //==========================================
  5328. int sendAuthorizeRequest(int gun_index)
  5329. {
  5330. mtrace();
  5331. int result = FAIL;
  5332. char message[100]={0};
  5333. char guid[37];
  5334. char tempdata[65]={0};
  5335. DEBUG_INFO("sendAuthorizeRequest...\n");
  5336. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5337. //Local Authorize
  5338. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5339. {
  5340. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5341. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5342. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5343. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5344. result = PASS;
  5345. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5346. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5347. authorizeRetryTimes = 0;
  5348. return result;
  5349. }
  5350. 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))||
  5351. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5352. {
  5353. // Query from cache
  5354. DEBUG_INFO("Authorize from cache.\n");
  5355. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5356. // Query from list
  5357. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5358. {
  5359. DEBUG_INFO("Authorize from list.\n");
  5360. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5361. }
  5362. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  5363. {
  5364. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5365. {
  5366. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5367. }
  5368. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5369. {
  5370. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5371. }
  5372. if(!GetOcppConnStatus())
  5373. {
  5374. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5375. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5376. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5377. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5378. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5379. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5380. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5381. authorizeRetryTimes = 0;
  5382. return result;
  5383. }
  5384. }
  5385. else
  5386. {
  5387. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5388. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5389. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5390. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5391. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5392. else
  5393. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5394. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5395. result = PASS;
  5396. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5397. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5398. authorizeRetryTimes = 0;
  5399. return result;
  5400. }
  5401. }
  5402. //initialize struct Authorize
  5403. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5404. //get data from shared memory
  5405. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5406. random_uuid(guid);
  5407. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5408. LWS_Send(message);
  5409. sprintf(tempdata, "Authorize,%d", gun_index);
  5410. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5411. {
  5412. result = PASS;
  5413. DEBUG_INFO("Authorize mapItem pass\n");
  5414. }
  5415. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5416. return result;
  5417. }
  5418. int sendBootNotificationRequest(void)
  5419. {
  5420. mtrace();
  5421. int result = FAIL;
  5422. char message[500]={0}, payload[700]={0};
  5423. char guid[37]={0};
  5424. char tempdata[65]={0};
  5425. // Fill BootNotification fields
  5426. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5427. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5428. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5429. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5430. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5431. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5432. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5433. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5434. ShmOCPP16Data->ChargeBoxId
  5435. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5436. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5437. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5438. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5439. ,ShmOCPP16Data->BootNotification.CpIccid
  5440. ,ShmOCPP16Data->BootNotification.CpImsi);
  5441. random_uuid(guid);
  5442. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5443. LWS_Send(message);
  5444. sprintf(tempdata, "BootNotification,0");
  5445. 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*/)
  5446. {
  5447. result = PASS;
  5448. }
  5449. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5450. strcpy(queuedata,message);
  5451. return result;
  5452. }
  5453. int sendDataTransferRequest(int gun_index)
  5454. {
  5455. mtrace();
  5456. char message[10240]={0};
  5457. char guid[37]={0};
  5458. char tempdata[65]={0};
  5459. int result = FAIL;
  5460. json_object *DataTransfer = json_object_new_object();
  5461. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5462. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5463. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].Data));
  5464. random_uuid(guid);
  5465. sprintf(message,"[%d,\"%s\",\"DataTransfer\",%s]", MESSAGE_TYPE_CALL,
  5466. guid,
  5467. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5468. json_object_put(DataTransfer);
  5469. LWS_Send(message);
  5470. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5471. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5472. {
  5473. result = PASS;
  5474. DEBUG_INFO("DataTransfer mapItem pass\n");
  5475. }
  5476. return result;
  5477. }
  5478. int sendUnplugByDataTransferRequest(int gun_index)
  5479. {
  5480. mtrace();
  5481. char message[10752]={0};
  5482. char guid[37]={0};
  5483. char tempdata[65]={0};
  5484. int result = FAIL;
  5485. random_uuid(guid);
  5486. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5487. (gun_index+1),
  5488. MESSAGE_TYPE_CALL,
  5489. guid,
  5490. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5491. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5492. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5493. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5494. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5495. {
  5496. result = PASS;
  5497. DEBUG_INFO("DataTransfer mapItem pass\n");
  5498. }
  5499. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5500. return result;
  5501. }
  5502. int sendOcmfByDataTransferRequest(int gun_index)
  5503. {
  5504. mtrace();
  5505. json_object *DataTransfer = json_object_new_object();
  5506. json_object *data = json_object_new_object();
  5507. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5508. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ID_OCMF");
  5509. json_object_object_add(data, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  5510. json_object_object_add(data, "dataString", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].DataString));
  5511. json_object_object_add(data, "publicKey", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].PublicKey));
  5512. json_object_object_add(DataTransfer, "data", data);
  5513. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5514. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5515. char message[3000]={0};
  5516. char guid[37]={0};
  5517. char tempdata[65]={0};
  5518. int result = FAIL;
  5519. random_uuid(guid);
  5520. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",%s]",
  5521. (gun_index+1),
  5522. MESSAGE_TYPE_CALL,
  5523. guid,
  5524. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5525. json_object_put(DataTransfer);
  5526. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5527. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5528. {
  5529. result = PASS;
  5530. DEBUG_INFO("DataTransfer mapItem pass\n");
  5531. }
  5532. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5533. return result;
  5534. }
  5535. int sendDiagnosticsStatusNotificationRequest(char *status)
  5536. {
  5537. mtrace();
  5538. int result = FAIL;
  5539. char message[110]={0};
  5540. char guid[37]={0};
  5541. char tempdata[65]={0};
  5542. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5543. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5544. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5545. random_uuid(guid);
  5546. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5547. LWS_SendNow(message);
  5548. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5549. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5550. {
  5551. result = PASS;
  5552. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5553. }
  5554. //#ifdef SystemLogMessage
  5555. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5556. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5557. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5558. //#endif
  5559. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5560. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5561. //record status
  5562. if(strcmp(status,"Idle")==0)
  5563. {
  5564. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5565. }
  5566. else if(strcmp(status,"Uploaded")==0)
  5567. {
  5568. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5569. }
  5570. else if(strcmp(status,"UploadFailed")==0)
  5571. {
  5572. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5573. }
  5574. else if(strcmp(status,"Uploading")==0)
  5575. {
  5576. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5577. }
  5578. return result;
  5579. }
  5580. int sendFirmwareStatusNotificationRequest(char *status)
  5581. {
  5582. mtrace();
  5583. int result = FAIL;
  5584. char message[110]={0};
  5585. char guid[37]={0};
  5586. char tempdata[65]={0};
  5587. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5588. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5589. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5590. random_uuid(guid);
  5591. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5592. LWS_SendNow(message);
  5593. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5594. 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*/)
  5595. {
  5596. result = PASS;
  5597. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  5598. }
  5599. //#ifdef SystemLogMessage
  5600. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  5601. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5602. //#endif
  5603. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5604. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  5605. //record status
  5606. if(strcmp(status,"Downloaded")==0)
  5607. {
  5608. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  5609. }
  5610. else if(strcmp(status,"DownloadFailed")==0)
  5611. {
  5612. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  5613. }
  5614. else if(strcmp(status,"Downloading")==0)
  5615. {
  5616. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  5617. }
  5618. else if(strcmp(status,"Idle")==0)
  5619. {
  5620. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  5621. }
  5622. else if(strcmp(status,"InstallationFailed")==0)
  5623. {
  5624. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  5625. }
  5626. else if(strcmp(status,"Installing")==0)
  5627. {
  5628. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  5629. }
  5630. else if(strcmp(status,"Installed")==0)
  5631. {
  5632. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  5633. }
  5634. return result;
  5635. }
  5636. int sendHeartbeatRequest(int gun_index)
  5637. {
  5638. mtrace();
  5639. int result = FAIL;
  5640. char message[80]={0};
  5641. char guid[37]={0};
  5642. char tempdata[65]={0};
  5643. random_uuid(guid);
  5644. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  5645. , MESSAGE_TYPE_CALL
  5646. , guid );
  5647. LWS_Send(message);
  5648. sprintf(tempdata, "Heartbeat,%d", 0);
  5649. 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*/)
  5650. {
  5651. result = PASS;
  5652. }
  5653. return result;
  5654. }
  5655. int sendStartTransactionRequest(int gun_index)
  5656. {
  5657. mtrace();
  5658. int result = FAIL;
  5659. char message[250]={0};
  5660. char guid[37]={0};
  5661. struct timeval tmnow;
  5662. struct tm *tm;
  5663. char buf[28];//, usec_buf[6];
  5664. char tempdata[65]={0};
  5665. int tempIndex = 0;
  5666. DEBUG_INFO("sendStartTransactionRequest...\n");
  5667. gettimeofday(&tmnow, NULL);
  5668. time_t t;
  5669. t = time(NULL);
  5670. /*UTC time and date*/
  5671. tm = gmtime(&t);
  5672. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5673. #if 0 // remove temporally
  5674. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5675. strcat(buf,".");
  5676. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5677. strcat(buf,usec_buf);
  5678. #endif
  5679. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  5680. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  5681. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5682. // clear StartTransaction Response
  5683. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  5684. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  5685. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  5686. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  5687. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5688. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5689. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5690. {
  5691. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5692. {
  5693. tempIndex = ((gun_index==2) ? 1: 0);
  5694. }
  5695. else
  5696. {
  5697. tempIndex = gun_index;
  5698. }
  5699. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5700. {
  5701. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5702. {
  5703. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5704. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  5705. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5706. }
  5707. }
  5708. }
  5709. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5710. {
  5711. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5712. {
  5713. tempIndex = ((gun_index==2) ? 1: 0);
  5714. }
  5715. else
  5716. {
  5717. tempIndex = gun_index;
  5718. }
  5719. for (int index = 0; index < CCS_QUANTITY; index++)
  5720. {
  5721. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5722. {
  5723. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5724. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  5725. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5726. }
  5727. }
  5728. }
  5729. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5730. {
  5731. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5732. {
  5733. tempIndex = ((gun_index==2) ? 1: 0);
  5734. }
  5735. else
  5736. {
  5737. tempIndex = gun_index;
  5738. }
  5739. for (int index = 0; index < GB_QUANTITY; index++)
  5740. {
  5741. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5742. {
  5743. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5744. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  5745. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5746. }
  5747. }
  5748. }
  5749. else if(gunType[gun_index] == GUN_TYPE_DO)
  5750. {
  5751. tempIndex = gun_index;
  5752. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5753. {
  5754. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5755. {
  5756. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5757. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  5758. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5759. }
  5760. }
  5761. }
  5762. else
  5763. {
  5764. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5765. {
  5766. tempIndex = 2;
  5767. }
  5768. else
  5769. {
  5770. tempIndex = gun_index;
  5771. }
  5772. for (int index = 0; index < AC_QUANTITY; index++)
  5773. {
  5774. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5775. {
  5776. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5777. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  5778. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5779. }
  5780. }
  5781. }
  5782. random_uuid(guid);
  5783. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  5784. {
  5785. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  5786. , gun_index +1
  5787. , MESSAGE_TYPE_CALL
  5788. , guid
  5789. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5790. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5791. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5792. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5793. }
  5794. else
  5795. {
  5796. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  5797. , gun_index +1
  5798. , MESSAGE_TYPE_CALL
  5799. , guid
  5800. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  5801. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  5802. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  5803. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  5804. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  5805. }
  5806. #if 1
  5807. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  5808. 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*/)
  5809. {
  5810. result = PASS;
  5811. }
  5812. #endif
  5813. strcpy(queuedata, message);
  5814. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5815. OCPP_insert_transaction_msg(YES, queuedata);
  5816. return result;
  5817. }
  5818. int sendStatusNotificationRequest(int gun_index)
  5819. {
  5820. mtrace();
  5821. int result = FAIL;
  5822. char message[600]={0};
  5823. char guid[37];
  5824. int currentStatus = 0;
  5825. struct timeval tmnow;
  5826. struct tm *tm;
  5827. char buf[28];//, usec_buf[6];
  5828. char tempdata[65]={0};
  5829. int tempIndex = 0;
  5830. uint8_t isStateChanged = TRUE;
  5831. uint8_t isContentIllegal = TRUE;
  5832. DEBUG_INFO("sendStatusNotificationRequest...\n");
  5833. gettimeofday(&tmnow, NULL);
  5834. time_t t;
  5835. t = time(NULL);
  5836. /*UTC time and date*/
  5837. tm = gmtime(&t);
  5838. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5839. #if 0 // remove temporally
  5840. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  5841. strcat(buf,".");
  5842. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  5843. strcat(buf,usec_buf);
  5844. #endif
  5845. //printf("%s",buf);
  5846. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5847. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5848. // it's option
  5849. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  5850. /*
  5851. enum _SYSTEM_STATUS
  5852. {
  5853. S_BOOTING = 0,
  5854. S_IDLE, = 1
  5855. S_AUTHORIZING, =2
  5856. S_REASSIGN_CHECK, =3
  5857. S_REASSIGN, =4
  5858. S_PRECHARGE, =5
  5859. S_PREPARING_FOR_EV, =6
  5860. S_PREPARING_FOR_EVSE, =7
  5861. S_CHARGING, =8
  5862. S_TERMINATING, =9
  5863. S_COMPLETE, =10
  5864. S_ALARM, =11
  5865. S_FAULT =12
  5866. }
  5867. */
  5868. //check Transaction active
  5869. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5870. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5871. {
  5872. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5873. {
  5874. tempIndex = ((gun_index==2) ? 1: 0);
  5875. }
  5876. else
  5877. {
  5878. tempIndex = gun_index;
  5879. }
  5880. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5881. {
  5882. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5883. {
  5884. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5885. {
  5886. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5887. {
  5888. currentStatus = Preparing; //OCPP Status: Preparing
  5889. }
  5890. else
  5891. {
  5892. currentStatus = Available; //OCPP Status: Available
  5893. }
  5894. }
  5895. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5896. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5897. ) //S_PRECHARGE
  5898. {
  5899. currentStatus = Preparing; //OCPP Status: Preparing
  5900. }
  5901. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5902. {
  5903. currentStatus = Charging; //OCPP Status: Charging
  5904. }
  5905. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5906. {
  5907. currentStatus = Finishing; //OCPP Status: Finishing
  5908. }
  5909. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5910. {
  5911. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5912. }
  5913. 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
  5914. {
  5915. currentStatus = Unavailable; //OCPP Status: Unavailable
  5916. }
  5917. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5918. {
  5919. currentStatus = Faulted; //OCPP Status: Faulted
  5920. }
  5921. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5922. {
  5923. currentStatus = Reserved; //OCPP Status: Reserved
  5924. }
  5925. } //end of the same index
  5926. }//end of for CHAdeMO_QUANTITY
  5927. }
  5928. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5929. {
  5930. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5931. {
  5932. tempIndex = ((gun_index==2) ? 1: 0);
  5933. }
  5934. else
  5935. {
  5936. tempIndex = gun_index;
  5937. }
  5938. for (int index = 0; index < CCS_QUANTITY; index++)
  5939. {
  5940. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5941. {
  5942. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5943. {
  5944. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5945. {
  5946. currentStatus = Preparing; //OCPP Status: Preparing
  5947. }
  5948. else
  5949. {
  5950. currentStatus = Available; //OCPP Status: Available
  5951. }
  5952. }
  5953. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5954. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5955. ) //S_PRECHARGE
  5956. {
  5957. currentStatus = Preparing; //OCPP Status: Preparing
  5958. }
  5959. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5960. {
  5961. currentStatus = Charging; //OCPP Status: Charging
  5962. }
  5963. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5964. {
  5965. currentStatus = Finishing; //OCPP Status: Finishing
  5966. }
  5967. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5968. {
  5969. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5970. }
  5971. 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
  5972. {
  5973. currentStatus = Unavailable; //OCPP Status : Unavailable
  5974. }
  5975. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5976. {
  5977. currentStatus = Faulted; //OCPP Status: Faulted
  5978. }
  5979. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5980. {
  5981. currentStatus = Reserved; //OCPP Status: Reserved
  5982. }
  5983. } //end of the same index
  5984. } // end of for CCS_QUANTITY
  5985. }
  5986. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5987. {
  5988. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5989. {
  5990. tempIndex = ((gun_index==2) ? 1: 0);
  5991. }
  5992. else
  5993. {
  5994. tempIndex = gun_index;
  5995. }
  5996. for (int index = 0; index < GB_QUANTITY; index++)
  5997. {
  5998. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5999. {
  6000. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6001. {
  6002. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6003. {
  6004. currentStatus = Preparing; //OCPP Status: Preparing
  6005. }
  6006. else
  6007. {
  6008. currentStatus = Available; //OCPP Status: Available
  6009. }
  6010. }
  6011. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6012. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6013. ) //S_PRECHARGE
  6014. {
  6015. currentStatus = Preparing; //OCPP Status: Preparing
  6016. }
  6017. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6018. {
  6019. currentStatus = Charging; //OCPP Status: Charging
  6020. }
  6021. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6022. {
  6023. currentStatus = Finishing; //OCPP Status: Finishing
  6024. }
  6025. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6026. {
  6027. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6028. }
  6029. 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
  6030. {
  6031. currentStatus = Unavailable; //OCPP Status: Unavailable
  6032. }
  6033. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6034. {
  6035. currentStatus = Faulted; //OCPP Status: Faulted
  6036. }
  6037. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6038. {
  6039. currentStatus = Reserved; //OCPP Status: Reserved
  6040. }
  6041. } //end of the same index
  6042. } // end of for GB_QUANTITY
  6043. }
  6044. else if(gunType[gun_index] == GUN_TYPE_DO)
  6045. {
  6046. tempIndex = gun_index;
  6047. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6048. {
  6049. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6050. {
  6051. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6052. {
  6053. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6054. {
  6055. currentStatus = Preparing; //OCPP Status: Preparing
  6056. }
  6057. else
  6058. {
  6059. currentStatus = Available; //OCPP Status: Available
  6060. }
  6061. }
  6062. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6063. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6064. ) //S_PRECHARGE
  6065. {
  6066. currentStatus = Preparing; //OCPP Status: Preparing
  6067. }
  6068. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6069. {
  6070. currentStatus = Charging; //OCPP Status: Charging
  6071. }
  6072. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6073. {
  6074. currentStatus = Finishing; //OCPP Status: Finishing
  6075. }
  6076. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6077. {
  6078. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6079. }
  6080. 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
  6081. {
  6082. currentStatus = Unavailable; //OCPP Status: Unavailable
  6083. }
  6084. 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
  6085. {
  6086. currentStatus = Faulted; //OCPP Status: Faulted
  6087. }
  6088. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6089. {
  6090. currentStatus = Reserved; //OCPP Status: Reserved
  6091. }
  6092. } //end of the same index
  6093. }
  6094. }
  6095. else
  6096. {
  6097. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6098. {
  6099. tempIndex = 2;
  6100. }
  6101. else
  6102. {
  6103. tempIndex = gun_index;
  6104. }
  6105. for (int index = 0; index < AC_QUANTITY; index++)
  6106. {
  6107. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6108. {
  6109. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  6110. {
  6111. 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))
  6112. {
  6113. currentStatus = Preparing; //OCPP Status: Preparing
  6114. }
  6115. else
  6116. {
  6117. currentStatus = Available; //OCPP Status: Available
  6118. }
  6119. }
  6120. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  6121. {
  6122. currentStatus = Preparing; //OCPP Status: Preparing
  6123. }
  6124. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  6125. {
  6126. currentStatus = Charging; //OCPP Status: Charging
  6127. }
  6128. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  6129. {
  6130. currentStatus = Finishing; //OCPP Status: Finishing
  6131. }
  6132. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6133. {
  6134. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  6135. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6136. else
  6137. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  6138. }
  6139. 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
  6140. {
  6141. currentStatus = Unavailable; //OCPP Status: Unavailable
  6142. }
  6143. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6144. {
  6145. currentStatus = Faulted; //OCPP Status: Faulted
  6146. }
  6147. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6148. {
  6149. currentStatus = Reserved; //OCPP Status: Reserved
  6150. }
  6151. }//end of the same index
  6152. }//end of for AC_QUANTITY
  6153. }
  6154. //it's option
  6155. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  6156. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  6157. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  6158. {
  6159. isStateChanged = FALSE;
  6160. }
  6161. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6162. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  6163. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6164. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  6165. isContentIllegal = TRUE;
  6166. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  6167. {
  6168. if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  6169. {
  6170. isContentIllegal = FALSE;
  6171. break;
  6172. }
  6173. }
  6174. if(isContentIllegal)
  6175. {
  6176. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  6177. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  6178. }
  6179. random_uuid(guid);
  6180. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6181. , MESSAGE_TYPE_CALL
  6182. , guid
  6183. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  6184. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  6185. , ShmOCPP16Data->StatusNotification[gun_index].Info
  6186. , ShmOCPP16Data->StatusNotification[gun_index].Status
  6187. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  6188. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  6189. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  6190. if((server_sign == TRUE) && isStateChanged)
  6191. {
  6192. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6193. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6194. LWS_Send(message);
  6195. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  6196. 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*/)
  6197. {
  6198. //DEBUG_ERROR("statusNotification mapitem pass");
  6199. result = PASS;
  6200. }
  6201. }
  6202. else
  6203. {
  6204. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6205. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6206. result = PASS;
  6207. }
  6208. return result;
  6209. }
  6210. int sendStopTransactionRequest(int gun_index)
  6211. {
  6212. mtrace();
  6213. int result = FAIL;
  6214. //char message[1500]={0};
  6215. char guid[37]={0};
  6216. char tempdata[65]={0};
  6217. int tempIndex = 0;
  6218. char TempStopTransaction[256];
  6219. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  6220. //int idx_sample=0;
  6221. DEBUG_INFO("sendStopTransactionRequest \n");
  6222. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6223. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  6224. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  6225. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6226. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6227. {
  6228. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6229. {
  6230. tempIndex = ((gun_index==2) ? 1: 0);
  6231. }
  6232. else
  6233. {
  6234. tempIndex = gun_index;
  6235. }
  6236. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6237. {
  6238. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6239. {
  6240. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6241. }
  6242. }// END OF CHAdeMO_QUANTITY
  6243. }
  6244. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6245. {
  6246. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6247. {
  6248. tempIndex = ((gun_index==2) ? 1: 0);
  6249. }
  6250. else
  6251. {
  6252. tempIndex = gun_index;
  6253. }
  6254. for (int index = 0; index < CCS_QUANTITY; index++)
  6255. {
  6256. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6257. {
  6258. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6259. }
  6260. }// END OF CCS_QUANTITY
  6261. }
  6262. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6263. {
  6264. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6265. {
  6266. tempIndex = ((gun_index==2) ? 1: 0);
  6267. }
  6268. else
  6269. {
  6270. tempIndex = gun_index;
  6271. }
  6272. for (int index = 0; index < GB_QUANTITY; index++)
  6273. {
  6274. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6275. {
  6276. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6277. }
  6278. }// END OF GB_QUANTITY
  6279. }
  6280. else if(gunType[gun_index] == GUN_TYPE_DO)
  6281. {
  6282. tempIndex = gun_index;
  6283. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6284. {
  6285. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6286. {
  6287. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6288. }
  6289. }// END OF GB_QUANTITY
  6290. }
  6291. else
  6292. {
  6293. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6294. {
  6295. tempIndex = 2;
  6296. }
  6297. else
  6298. {
  6299. tempIndex = gun_index;
  6300. }
  6301. for (int index = 0; index < AC_QUANTITY; index++)
  6302. {
  6303. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6304. {
  6305. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6306. }
  6307. }// END OF AC_QUANTITY
  6308. }
  6309. //====================================== Stop Transaction Time =====================================================
  6310. struct timeval tmnow;
  6311. struct tm *tm;
  6312. char buf[28];//, usec_buf[6];
  6313. gettimeofday(&tmnow, NULL);
  6314. time_t t;
  6315. t = time(NULL);
  6316. /*UTC time and date*/
  6317. tm = gmtime(&t);
  6318. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6319. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  6320. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  6321. random_uuid(guid);
  6322. /***********************************transactionData******************************************************/
  6323. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  6324. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  6325. //=================================
  6326. // Transaction_Begin
  6327. //=================================
  6328. //=================================
  6329. // Transaction_End
  6330. //=================================
  6331. // ================================= Current.Import L1 ===============================================
  6332. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6333. {
  6334. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  6335. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6336. {
  6337. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6338. {
  6339. tempIndex = ((gun_index==2) ? 1: 0);
  6340. }
  6341. else
  6342. {
  6343. tempIndex = gun_index;
  6344. }
  6345. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6346. {
  6347. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6348. {
  6349. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6350. }
  6351. }// End of for CHAdeMO_QUANTITY
  6352. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6353. }
  6354. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6355. {
  6356. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6357. {
  6358. tempIndex = ((gun_index==2) ? 1: 0);
  6359. }
  6360. else
  6361. {
  6362. tempIndex = gun_index;
  6363. }
  6364. for (int index = 0; index < CCS_QUANTITY; index++)
  6365. {
  6366. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6367. {
  6368. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6369. }
  6370. }// End of for CCS_QUANTITY
  6371. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6372. }
  6373. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6374. {
  6375. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6376. {
  6377. tempIndex = ((gun_index==2) ? 1: 0);
  6378. }
  6379. else
  6380. {
  6381. tempIndex = gun_index;
  6382. }
  6383. for (int index = 0; index < GB_QUANTITY; index++)
  6384. {
  6385. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6386. {
  6387. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6388. }
  6389. }// End of for GB_QUANTITY
  6390. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6391. }
  6392. else if(gunType[gun_index] == GUN_TYPE_DO)
  6393. {
  6394. tempIndex = gun_index;
  6395. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6396. {
  6397. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6398. {
  6399. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  6400. }
  6401. }
  6402. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  6403. }
  6404. else
  6405. {
  6406. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6407. {
  6408. tempIndex = 2;
  6409. }
  6410. else
  6411. {
  6412. tempIndex = gun_index;
  6413. }
  6414. for (int index = 0; index < AC_QUANTITY; index++)
  6415. {
  6416. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6417. {
  6418. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  6419. }
  6420. }// End of for AC_QUANTITY
  6421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  6422. }
  6423. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6424. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  6425. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  6426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  6427. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6428. }
  6429. // ================================= Energy.Active.Import.Interval ==============================================
  6430. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  6431. {
  6432. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6433. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6434. {
  6435. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6436. {
  6437. tempIndex = ((gun_index==2) ? 1: 0);
  6438. }
  6439. else
  6440. {
  6441. tempIndex = gun_index;
  6442. }
  6443. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6444. {
  6445. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6446. {
  6447. 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
  6448. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6449. }
  6450. }// END OF CHAdeMO_QUANTITY
  6451. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6452. }
  6453. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6454. {
  6455. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6456. {
  6457. tempIndex = ((gun_index==2) ? 1: 0);
  6458. }
  6459. else
  6460. {
  6461. tempIndex = gun_index;
  6462. }
  6463. for (int index = 0; index < CCS_QUANTITY; index++)
  6464. {
  6465. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6466. {
  6467. 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
  6468. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6469. }
  6470. }// END OF CCS_QUANTITY
  6471. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6472. }
  6473. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6474. {
  6475. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6476. {
  6477. tempIndex = ((gun_index==2) ? 1: 0);
  6478. }
  6479. else
  6480. {
  6481. tempIndex = gun_index;
  6482. }
  6483. for (int index = 0; index < GB_QUANTITY; index++)
  6484. {
  6485. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6486. {
  6487. 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
  6488. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6489. }
  6490. }// END OF GB_QUANTITY
  6491. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6492. }
  6493. else if(gunType[gun_index] == GUN_TYPE_DO)
  6494. {
  6495. tempIndex = gun_index;
  6496. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6497. {
  6498. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6499. {
  6500. 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
  6501. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6502. }
  6503. }
  6504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  6505. }
  6506. else
  6507. {
  6508. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6509. {
  6510. tempIndex = 2;
  6511. }
  6512. else
  6513. {
  6514. tempIndex = gun_index;
  6515. }
  6516. for (int index = 0; index < AC_QUANTITY; index++)
  6517. {
  6518. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6519. {
  6520. 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
  6521. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6522. }
  6523. }// END OF AC_QUANTITY
  6524. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  6525. }
  6526. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6527. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  6528. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  6529. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  6530. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6531. }
  6532. //=================================== Power.Active.Import ==================================================
  6533. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  6534. {
  6535. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6536. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6537. {
  6538. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6539. {
  6540. tempIndex = ((gun_index==2) ? 1: 0);
  6541. }
  6542. else
  6543. {
  6544. tempIndex = gun_index;
  6545. }
  6546. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6547. {
  6548. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6549. {
  6550. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6551. }
  6552. } // End for CHAdeMO_QUANTITY
  6553. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6554. }
  6555. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6556. {
  6557. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6558. {
  6559. tempIndex = ((gun_index==2) ? 1: 0);
  6560. }
  6561. else
  6562. {
  6563. tempIndex = gun_index;
  6564. }
  6565. for (int index = 0; index < CCS_QUANTITY; index++)
  6566. {
  6567. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6568. {
  6569. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6570. }
  6571. } // END for CCS_QUANTITY
  6572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6573. }
  6574. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6575. {
  6576. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6577. {
  6578. tempIndex = ((gun_index==2) ? 1: 0);
  6579. }
  6580. else
  6581. {
  6582. tempIndex = gun_index;
  6583. }
  6584. for (int index = 0; index < GB_QUANTITY; index++)
  6585. {
  6586. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6587. {
  6588. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6589. }
  6590. }// END for GB_QUANTITY
  6591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6592. }
  6593. else if(gunType[gun_index] == GUN_TYPE_DO)
  6594. {
  6595. tempIndex = gun_index;
  6596. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6597. {
  6598. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6599. {
  6600. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6601. }
  6602. }
  6603. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  6604. }
  6605. else
  6606. {
  6607. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6608. {
  6609. tempIndex = 2;
  6610. }
  6611. else
  6612. {
  6613. tempIndex = gun_index;
  6614. }
  6615. for (int index = 0; index < AC_QUANTITY; index++)
  6616. {
  6617. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6618. {
  6619. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  6620. }
  6621. } // END for AC_QUANTITY
  6622. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  6623. }
  6624. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6625. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  6626. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  6627. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  6628. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  6629. }
  6630. //============================ Voltage L1 ====================================
  6631. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6632. {
  6633. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6634. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6635. {
  6636. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6637. {
  6638. tempIndex = ((gun_index==2) ? 1: 0);
  6639. }
  6640. else
  6641. {
  6642. tempIndex = gun_index;
  6643. }
  6644. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6645. {
  6646. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6647. {
  6648. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6649. }
  6650. } // END OF FOR CHAdeMO_QUANTITY
  6651. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6652. }
  6653. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6654. {
  6655. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6656. {
  6657. tempIndex = ((gun_index==2) ? 1: 0);
  6658. }
  6659. else
  6660. {
  6661. tempIndex = gun_index;
  6662. }
  6663. for (int index = 0; index < CCS_QUANTITY; index++)
  6664. {
  6665. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6666. {
  6667. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6668. }
  6669. } // END OF FOR CCS_QUANTITY
  6670. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6671. }
  6672. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6673. {
  6674. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6675. {
  6676. tempIndex = ((gun_index==2) ? 1: 0);
  6677. }
  6678. else
  6679. {
  6680. tempIndex = gun_index;
  6681. }
  6682. for (int index = 0; index < GB_QUANTITY; index++)
  6683. {
  6684. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6685. {
  6686. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6687. }
  6688. } // END OF FOR GB_QUANTITY
  6689. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6690. }
  6691. else if(gunType[gun_index] == GUN_TYPE_DO)
  6692. {
  6693. tempIndex = gun_index;
  6694. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6695. {
  6696. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6697. {
  6698. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  6699. }
  6700. }
  6701. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  6702. }
  6703. else
  6704. {
  6705. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6706. {
  6707. tempIndex = 2;
  6708. }
  6709. else
  6710. {
  6711. tempIndex = gun_index;
  6712. }
  6713. for (int index = 0; index < AC_QUANTITY; index++)
  6714. {
  6715. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6716. {
  6717. 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
  6718. }
  6719. } // END OF FOR AC_QUANTITY
  6720. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  6721. }
  6722. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  6724. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  6725. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  6726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6727. }
  6728. //====================== End SoC ================================
  6729. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6730. {
  6731. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6732. 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))
  6733. {
  6734. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6735. {
  6736. tempIndex = ((gun_index==2) ? 1: 0);
  6737. }
  6738. else
  6739. {
  6740. tempIndex = gun_index;
  6741. }
  6742. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6743. {
  6744. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6745. {
  6746. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6747. {
  6748. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  6749. }
  6750. }
  6751. }
  6752. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6753. {
  6754. for (int index = 0; index < CCS_QUANTITY; index++)
  6755. {
  6756. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6757. {
  6758. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  6759. }
  6760. }
  6761. }
  6762. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6763. {
  6764. for (int index = 0; index < GB_QUANTITY; index++)
  6765. {
  6766. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6767. {
  6768. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  6769. }
  6770. }
  6771. }
  6772. else if(gunType[gun_index] == GUN_TYPE_DO)
  6773. {
  6774. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6775. {
  6776. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6777. {
  6778. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  6779. }
  6780. }
  6781. }
  6782. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6783. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  6784. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6785. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  6786. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  6787. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6788. } // END FOR DC CASE
  6789. }
  6790. // ================================= Current.Import L2 ===============================================
  6791. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6792. {
  6793. // AC 3 phse L2 current
  6794. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6795. {
  6796. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6797. {
  6798. tempIndex = 2;
  6799. }
  6800. else
  6801. {
  6802. tempIndex = gun_index;
  6803. }
  6804. for (int index = 0; index < AC_QUANTITY; index++)
  6805. {
  6806. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6807. {
  6808. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  6809. }
  6810. }// End of for AC_QUANTITY
  6811. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  6812. }
  6813. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6814. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  6815. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  6816. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  6817. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6818. }
  6819. // ================================= Current.Import L3 ===============================================
  6820. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  6821. {
  6822. // AC 3 phse L3 current
  6823. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6824. {
  6825. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6826. {
  6827. tempIndex = 2;
  6828. }
  6829. else
  6830. {
  6831. tempIndex = gun_index;
  6832. }
  6833. for (int index = 0; index < AC_QUANTITY; index++)
  6834. {
  6835. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6836. {
  6837. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  6838. }
  6839. }// End of for AC_QUANTITY
  6840. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  6841. }
  6842. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6843. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6844. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6845. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6846. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6847. }
  6848. //============================ Voltage L2 ====================================
  6849. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6850. {
  6851. // AC 3 phse L2 voltage
  6852. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6853. {
  6854. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6855. {
  6856. tempIndex = 2;
  6857. }
  6858. else
  6859. {
  6860. tempIndex = gun_index;
  6861. }
  6862. for (int index = 0; index < AC_QUANTITY; index++)
  6863. {
  6864. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6865. {
  6866. 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
  6867. }
  6868. } // END OF FOR AC_QUANTITY
  6869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6870. }
  6871. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6872. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6873. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6876. }
  6877. //============================ Voltage L3 ====================================
  6878. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6879. {
  6880. // AC 3 phse L3 voltage
  6881. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6882. {
  6883. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6884. {
  6885. tempIndex = 2;
  6886. }
  6887. else
  6888. {
  6889. tempIndex = gun_index;
  6890. }
  6891. for (int index = 0; index < AC_QUANTITY; index++)
  6892. {
  6893. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6894. {
  6895. 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
  6896. }
  6897. } // END OF FOR AC_QUANTITY
  6898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6899. }
  6900. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6901. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6902. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6903. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6904. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6905. }
  6906. //====================== Start SoC ================================
  6907. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6908. {
  6909. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6910. 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))
  6911. {
  6912. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6913. {
  6914. tempIndex = ((gun_index==2) ? 1: 0);
  6915. }
  6916. else
  6917. {
  6918. tempIndex = gun_index;
  6919. }
  6920. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6921. {
  6922. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6923. {
  6924. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6925. {
  6926. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6927. }
  6928. }
  6929. }
  6930. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6931. {
  6932. for (int index = 0; index < CCS_QUANTITY; index++)
  6933. {
  6934. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6935. {
  6936. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6937. }
  6938. }
  6939. }
  6940. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6941. {
  6942. for (int index = 0; index < GB_QUANTITY; index++)
  6943. {
  6944. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6945. {
  6946. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6947. }
  6948. }
  6949. }
  6950. else if(gunType[gun_index] == GUN_TYPE_DO)
  6951. {
  6952. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6953. {
  6954. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6955. {
  6956. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6957. }
  6958. }
  6959. }
  6960. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6961. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6963. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6966. } // END FOR DC CASE
  6967. }
  6968. //================================================ Message create ====================================================
  6969. json_object *StopTransaction = json_object_new_object();
  6970. json_object *transactionDatas = json_object_new_array();
  6971. json_object *sampledValues = json_object_new_array();
  6972. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6973. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6974. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6975. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6976. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6977. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6978. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6979. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  6980. {
  6981. json_object *transactionData = json_object_new_object();
  6982. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6983. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6984. {
  6985. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6986. {
  6987. json_object *sampledValue = json_object_new_object();
  6988. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6989. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6990. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6991. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6992. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6993. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6994. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6995. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6996. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6997. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6998. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6999. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  7000. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  7001. json_object_array_add(sampledValues, sampledValue);
  7002. }
  7003. }
  7004. json_object_object_add(transactionData, "sampledValue", sampledValues);
  7005. json_object_array_add(transactionDatas, transactionData);
  7006. }
  7007. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  7008. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  7009. ,MESSAGE_TYPE_CALL
  7010. ,guid
  7011. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  7012. json_object_put(StopTransaction);
  7013. #if 1 // for TempStopTransaction
  7014. //Delete TempStopTransaction
  7015. if((access(TempStopTransaction,F_OK))!=-1)
  7016. {
  7017. remove(TempStopTransaction); // remove file "TempStopTransaction"
  7018. }
  7019. #endif
  7020. #if 1
  7021. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  7022. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  7023. {
  7024. result = PASS;
  7025. //DEBUG_INFO("StopTransaction mapitem pass\n");
  7026. }
  7027. #endif
  7028. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  7029. OCPP_insert_transaction_msg(NO, queuedata);
  7030. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  7031. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  7032. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  7033. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  7034. {
  7035. //SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  7036. }
  7037. //for test
  7038. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  7039. return result;
  7040. }
  7041. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  7042. {
  7043. mtrace();
  7044. int result = FAIL;
  7045. char guid[37]={0};
  7046. char tempdata[65]={0};
  7047. int tempIndex = 0;
  7048. DEBUG_INFO("sendMeterValuesRequest ...\n");
  7049. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  7050. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  7051. //set value
  7052. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  7053. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  7054. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  7055. -1);
  7056. random_uuid(guid);
  7057. //UTC Date time
  7058. struct timeval tmnow;
  7059. struct tm *tm;
  7060. char buf[28];//, usec_buf[6];
  7061. gettimeofday(&tmnow, NULL);
  7062. time_t t;
  7063. t = time(NULL);
  7064. /*UTC time and date*/
  7065. tm = gmtime(&t);
  7066. if(dataType == ReadingContext_Sample_Clock)
  7067. {
  7068. struct tm *tmTarget;
  7069. struct timeb tbTarget;
  7070. tbTarget.time = mktime(tm);
  7071. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  7072. tmTarget = gmtime(&tbTarget.time);
  7073. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  7074. }
  7075. else
  7076. {
  7077. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  7078. }
  7079. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  7080. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  7081. //********************************(1)Current.Import L1************************************************/
  7082. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7083. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7084. (dataType == ReadingContext_Trigger))
  7085. {
  7086. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7087. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7088. {
  7089. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7090. {
  7091. tempIndex = ((gun_index==2) ? 1: 0);
  7092. }
  7093. else
  7094. {
  7095. tempIndex = gun_index;
  7096. }
  7097. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7098. {
  7099. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7100. {
  7101. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  7102. }
  7103. }
  7104. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  7105. }
  7106. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7107. {
  7108. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7109. {
  7110. tempIndex = ((gun_index==2) ? 1: 0);
  7111. }
  7112. else
  7113. {
  7114. tempIndex = gun_index;
  7115. }
  7116. for (int index = 0; index < CCS_QUANTITY; index++)
  7117. {
  7118. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7119. {
  7120. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  7121. }
  7122. }
  7123. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  7124. }
  7125. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7126. {
  7127. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7128. {
  7129. tempIndex = ((gun_index==2) ? 1: 0);
  7130. }
  7131. else
  7132. {
  7133. tempIndex = gun_index;
  7134. }
  7135. for (int index = 0; index < GB_QUANTITY; index++)
  7136. {
  7137. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7138. {
  7139. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  7140. }
  7141. }
  7142. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  7143. }
  7144. else if(gunType[gun_index] == GUN_TYPE_DO)
  7145. {
  7146. tempIndex = gun_index;
  7147. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7148. {
  7149. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7150. {
  7151. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  7152. }
  7153. }
  7154. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  7155. }
  7156. else
  7157. {
  7158. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7159. {
  7160. tempIndex = 2;
  7161. }
  7162. else
  7163. {
  7164. tempIndex = gun_index;
  7165. }
  7166. for (int index = 0; index < AC_QUANTITY; index++)
  7167. {
  7168. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7169. {
  7170. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  7171. }
  7172. }
  7173. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  7174. }
  7175. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  7176. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  7177. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  7178. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  7179. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7180. }
  7181. //********************************(2)Energy.Active.Import.Register ************************************************/
  7182. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  7183. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  7184. (dataType == ReadingContext_Trigger))
  7185. {
  7186. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7187. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7188. {
  7189. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7190. {
  7191. tempIndex = ((gun_index==2) ? 1: 0);
  7192. }
  7193. else
  7194. {
  7195. tempIndex = gun_index;
  7196. }
  7197. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7198. {
  7199. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7200. {
  7201. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  7202. }
  7203. }
  7204. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7205. }
  7206. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7207. {
  7208. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7209. {
  7210. tempIndex = ((gun_index==2) ? 1: 0);
  7211. }
  7212. else
  7213. {
  7214. tempIndex = gun_index;
  7215. }
  7216. for (int index = 0; index < CCS_QUANTITY; index++)
  7217. {
  7218. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7219. {
  7220. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  7221. }
  7222. }
  7223. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7224. }
  7225. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7226. {
  7227. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7228. {
  7229. tempIndex = ((gun_index==2) ? 1: 0);
  7230. }
  7231. else
  7232. {
  7233. tempIndex = gun_index;
  7234. }
  7235. for (int index = 0; index < GB_QUANTITY; index++)
  7236. {
  7237. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7238. {
  7239. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  7240. }
  7241. }
  7242. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7243. }
  7244. else if(gunType[gun_index] == GUN_TYPE_DO)
  7245. {
  7246. tempIndex = gun_index;
  7247. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7248. {
  7249. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7250. {
  7251. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  7252. }
  7253. }
  7254. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7255. }
  7256. else
  7257. {
  7258. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7259. {
  7260. tempIndex = 2;
  7261. }
  7262. else
  7263. {
  7264. tempIndex = gun_index;
  7265. }
  7266. for (int index = 0; index < AC_QUANTITY; index++)
  7267. {
  7268. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7269. {
  7270. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  7271. }
  7272. }
  7273. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  7274. }
  7275. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  7276. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  7277. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  7278. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  7279. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7280. }
  7281. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  7282. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7283. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7284. (dataType == ReadingContext_Trigger))
  7285. {
  7286. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7287. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7288. {
  7289. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7290. {
  7291. tempIndex = ((gun_index==2) ? 1: 0);
  7292. }
  7293. else
  7294. {
  7295. tempIndex = gun_index;
  7296. }
  7297. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7298. {
  7299. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7300. {
  7301. if(dataType == ReadingContext_Sample_Clock)
  7302. {
  7303. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7304. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7305. }
  7306. else if(dataType == ReadingContext_Sample_Periodic)
  7307. {
  7308. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7309. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7310. }
  7311. else
  7312. {
  7313. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7314. }
  7315. }
  7316. } // END OF FOR CHAdeMO_QUANTITY
  7317. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7318. }
  7319. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7320. {
  7321. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7322. {
  7323. tempIndex = ((gun_index==2) ? 1: 0);
  7324. }
  7325. else
  7326. {
  7327. tempIndex = gun_index;
  7328. }
  7329. for (int index = 0; index < CCS_QUANTITY; index++)
  7330. {
  7331. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7332. {
  7333. if(dataType == ReadingContext_Sample_Clock)
  7334. {
  7335. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7336. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7337. }
  7338. else if(dataType == ReadingContext_Sample_Periodic)
  7339. {
  7340. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7341. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7342. }
  7343. else
  7344. {
  7345. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7346. }
  7347. }
  7348. } // END OF CCS_QUANTITY
  7349. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7350. }
  7351. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7352. {
  7353. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7354. {
  7355. tempIndex = ((gun_index==2) ? 1: 0);
  7356. }
  7357. else
  7358. {
  7359. tempIndex = gun_index;
  7360. }
  7361. for (int index = 0; index < GB_QUANTITY; index++)
  7362. {
  7363. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7364. {
  7365. if(dataType == ReadingContext_Sample_Clock)
  7366. {
  7367. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7368. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7369. }
  7370. else if(dataType == ReadingContext_Sample_Periodic)
  7371. {
  7372. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7373. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7374. }
  7375. else
  7376. {
  7377. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7378. }
  7379. }
  7380. } // END OF GB_QUANTITY
  7381. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7382. }
  7383. else if(gunType[gun_index] == GUN_TYPE_DO)
  7384. {
  7385. tempIndex = gun_index;
  7386. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7387. {
  7388. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7389. {
  7390. if(dataType == ReadingContext_Sample_Clock)
  7391. {
  7392. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7393. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7394. }
  7395. else if(dataType == ReadingContext_Sample_Periodic)
  7396. {
  7397. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7398. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7399. }
  7400. else
  7401. {
  7402. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7403. }
  7404. }
  7405. }
  7406. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7407. }
  7408. else
  7409. {
  7410. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7411. {
  7412. tempIndex = 2;
  7413. }
  7414. else
  7415. {
  7416. tempIndex = gun_index;
  7417. }
  7418. for (int index = 0; index < AC_QUANTITY; index++)
  7419. {
  7420. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7421. {
  7422. if(dataType == ReadingContext_Sample_Clock)
  7423. {
  7424. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7425. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7426. }
  7427. else if(dataType == ReadingContext_Sample_Periodic)
  7428. {
  7429. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7430. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7431. }
  7432. else
  7433. {
  7434. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7435. }
  7436. }
  7437. }
  7438. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7439. }
  7440. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7441. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7442. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7443. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7444. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7445. }
  7446. //********************************(4)Power.Active.Import************************************************/
  7447. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7448. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7449. (dataType == ReadingContext_Trigger))
  7450. {
  7451. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7452. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7453. {
  7454. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7455. {
  7456. tempIndex = ((gun_index==2) ? 1: 0);
  7457. }
  7458. else
  7459. {
  7460. tempIndex = gun_index;
  7461. }
  7462. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7463. {
  7464. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7465. {
  7466. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7467. }
  7468. } // END OF FOR
  7469. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7470. }
  7471. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7472. {
  7473. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7474. {
  7475. tempIndex = ((gun_index==2) ? 1: 0);
  7476. }
  7477. else
  7478. {
  7479. tempIndex = gun_index;
  7480. }
  7481. for (int index = 0; index < CCS_QUANTITY; index++)
  7482. {
  7483. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7484. {
  7485. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7486. }
  7487. }
  7488. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7489. }
  7490. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7491. {
  7492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7493. {
  7494. tempIndex = ((gun_index==2) ? 1: 0);
  7495. }
  7496. else
  7497. {
  7498. tempIndex = gun_index;
  7499. }
  7500. for (int index = 0; index < GB_QUANTITY; index++)
  7501. {
  7502. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7503. {
  7504. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7505. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7506. }
  7507. }
  7508. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7509. }
  7510. else if(gunType[gun_index] == GUN_TYPE_DO)
  7511. {
  7512. tempIndex = gun_index;
  7513. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7514. {
  7515. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7516. {
  7517. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7518. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7519. }
  7520. }
  7521. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7522. }
  7523. else
  7524. {
  7525. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7526. {
  7527. tempIndex = 2;
  7528. }
  7529. else
  7530. {
  7531. tempIndex = gun_index;
  7532. }
  7533. for (int index = 0; index < AC_QUANTITY; index++)
  7534. {
  7535. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7536. {
  7537. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7538. }
  7539. }
  7540. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7541. }
  7542. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7543. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7544. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7545. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7546. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7547. }
  7548. //***********************************************(5)VOLTAGE L1******************************************************/
  7549. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7550. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7551. (dataType == ReadingContext_Trigger))
  7552. {
  7553. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7554. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7555. {
  7556. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7557. {
  7558. tempIndex = ((gun_index==2) ? 1: 0);
  7559. }
  7560. else
  7561. {
  7562. tempIndex = gun_index;
  7563. }
  7564. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7565. {
  7566. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7567. {
  7568. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7569. }
  7570. }
  7571. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7572. }
  7573. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7574. {
  7575. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7576. {
  7577. tempIndex = ((gun_index==2) ? 1: 0);
  7578. }
  7579. else
  7580. {
  7581. tempIndex = gun_index;
  7582. }
  7583. for (int index = 0; index < CCS_QUANTITY; index++)
  7584. {
  7585. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7586. {
  7587. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7588. }
  7589. }
  7590. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7591. }
  7592. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7593. {
  7594. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7595. {
  7596. tempIndex = ((gun_index==2) ? 1: 0);
  7597. }
  7598. else
  7599. {
  7600. tempIndex = gun_index;
  7601. }
  7602. for (int index = 0; index < GB_QUANTITY; index++)
  7603. {
  7604. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7605. {
  7606. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7607. }
  7608. }
  7609. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7610. }
  7611. else if(gunType[gun_index] == GUN_TYPE_DO)
  7612. {
  7613. tempIndex = gun_index;
  7614. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7615. {
  7616. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7617. {
  7618. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7619. }
  7620. }
  7621. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7622. }
  7623. else
  7624. {
  7625. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7626. {
  7627. tempIndex = 2;
  7628. }
  7629. else
  7630. {
  7631. tempIndex = gun_index;
  7632. }
  7633. for (int index = 0; index < AC_QUANTITY; index++)
  7634. {
  7635. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7636. {
  7637. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7638. }
  7639. }
  7640. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7641. }
  7642. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7643. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7644. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7645. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7646. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7647. }
  7648. //***********************************************(6)SOC******************************************************/
  7649. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7650. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7651. (dataType == ReadingContext_Trigger))
  7652. {
  7653. 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))
  7654. {
  7655. //idx_sample=5;
  7656. //sampledValue = NULL;
  7657. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7658. {
  7659. tempIndex = ((gun_index==2) ? 1: 0);
  7660. }
  7661. else
  7662. {
  7663. tempIndex = gun_index;
  7664. }
  7665. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7666. {
  7667. //tempIndex = ((gun_index==2) ? 1: 0);
  7668. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7669. {
  7670. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7671. {
  7672. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7673. }
  7674. }
  7675. }
  7676. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7677. {
  7678. //tempIndex = ((gun_index==2) ? 1: 0);
  7679. for (int index = 0; index < CCS_QUANTITY; index++)
  7680. {
  7681. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7682. {
  7683. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7684. }
  7685. }
  7686. }
  7687. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7688. {
  7689. //tempIndex = ((gun_index==2) ? 1: 0);
  7690. for (int index = 0; index < GB_QUANTITY; index++)
  7691. {
  7692. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7693. {
  7694. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7695. }
  7696. }
  7697. }
  7698. else if(gunType[gun_index] == GUN_TYPE_DO)
  7699. {
  7700. //tempIndex = ((gun_index==2) ? 1: 0);
  7701. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7702. {
  7703. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7704. {
  7705. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7706. }
  7707. }
  7708. }
  7709. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7710. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7711. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7712. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7713. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7714. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7715. }
  7716. }
  7717. //********************************(7)Current.Import L2************************************************/
  7718. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7719. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7720. (dataType == ReadingContext_Trigger))
  7721. {
  7722. // Only for AC 3 phase
  7723. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7724. {
  7725. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7726. {
  7727. tempIndex = 2;
  7728. }
  7729. else
  7730. {
  7731. tempIndex = gun_index;
  7732. }
  7733. for (int index = 0; index < AC_QUANTITY; index++)
  7734. {
  7735. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7736. {
  7737. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7738. }
  7739. }
  7740. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7741. }
  7742. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7743. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7744. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7745. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7746. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7747. }
  7748. //********************************(8)Current.Import L3************************************************/
  7749. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7750. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7751. (dataType == ReadingContext_Trigger))
  7752. {
  7753. // Only for AC 3 phase
  7754. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7755. {
  7756. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7757. {
  7758. tempIndex = 2;
  7759. }
  7760. else
  7761. {
  7762. tempIndex = gun_index;
  7763. }
  7764. for (int index = 0; index < AC_QUANTITY; index++)
  7765. {
  7766. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7767. {
  7768. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7769. }
  7770. }
  7771. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7772. }
  7773. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7774. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7775. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7776. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7777. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7778. }
  7779. //***********************************************(9)VOLTAGE L2******************************************************/
  7780. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7781. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7782. (dataType == ReadingContext_Trigger))
  7783. {
  7784. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7785. {
  7786. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7787. {
  7788. tempIndex = 2;
  7789. }
  7790. else
  7791. {
  7792. tempIndex = gun_index;
  7793. }
  7794. for (int index = 0; index < AC_QUANTITY; index++)
  7795. {
  7796. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7797. {
  7798. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7799. }
  7800. }
  7801. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7802. }
  7803. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7804. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7805. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7806. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7807. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7808. }
  7809. //***********************************************(10)VOLTAGE L3******************************************************/
  7810. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7811. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7812. (dataType == ReadingContext_Trigger))
  7813. {
  7814. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7815. {
  7816. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7817. {
  7818. tempIndex = 2;
  7819. }
  7820. else
  7821. {
  7822. tempIndex = gun_index;
  7823. }
  7824. for (int index = 0; index < AC_QUANTITY; index++)
  7825. {
  7826. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7827. {
  7828. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7829. }
  7830. }
  7831. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7832. }
  7833. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7834. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7835. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7836. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7837. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7838. }
  7839. //***********************************************(11)Current.Offered******************************************************/
  7840. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7841. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7842. (dataType == ReadingContext_Trigger))
  7843. {
  7844. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7845. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  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 < CHAdeMO_QUANTITY; index++)
  7856. {
  7857. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7858. {
  7859. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7860. }
  7861. } // END OF FOR CHAdeMO_QUANTITY
  7862. }
  7863. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7864. {
  7865. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7866. {
  7867. tempIndex = ((gun_index==2) ? 1: 0);
  7868. }
  7869. else
  7870. {
  7871. tempIndex = gun_index;
  7872. }
  7873. for (int index = 0; index < CCS_QUANTITY; index++)
  7874. {
  7875. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7876. {
  7877. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7878. }
  7879. } // END OF CCS_QUANTITY
  7880. }
  7881. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7882. {
  7883. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7884. {
  7885. tempIndex = ((gun_index==2) ? 1: 0);
  7886. }
  7887. else
  7888. {
  7889. tempIndex = gun_index;
  7890. }
  7891. for (int index = 0; index < GB_QUANTITY; index++)
  7892. {
  7893. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7894. {
  7895. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7896. }
  7897. } // END OF GB_QUANTITY
  7898. }
  7899. else if(gunType[gun_index] == GUN_TYPE_DO)
  7900. {
  7901. tempIndex = gun_index;
  7902. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7903. {
  7904. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7905. {
  7906. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7907. }
  7908. }
  7909. }
  7910. else
  7911. {
  7912. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7913. {
  7914. tempIndex = 2;
  7915. }
  7916. else
  7917. {
  7918. tempIndex = gun_index;
  7919. }
  7920. for (int index = 0; index < AC_QUANTITY; index++)
  7921. {
  7922. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7923. {
  7924. uint16_t currentOffer;
  7925. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7926. {
  7927. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7928. }
  7929. else
  7930. {
  7931. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7932. }
  7933. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7934. }
  7935. }
  7936. }
  7937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7939. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7940. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7941. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7942. }
  7943. //***********************************************(12)Power.Offered******************************************************/
  7944. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7945. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7946. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7947. {
  7948. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7949. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7950. {
  7951. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7952. {
  7953. tempIndex = ((gun_index==2) ? 1: 0);
  7954. }
  7955. else
  7956. {
  7957. tempIndex = gun_index;
  7958. }
  7959. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7960. {
  7961. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7962. {
  7963. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7964. }
  7965. } // END OF FOR CHAdeMO_QUANTITY
  7966. }
  7967. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7968. {
  7969. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7970. {
  7971. tempIndex = ((gun_index==2) ? 1: 0);
  7972. }
  7973. else
  7974. {
  7975. tempIndex = gun_index;
  7976. }
  7977. for (int index = 0; index < CCS_QUANTITY; index++)
  7978. {
  7979. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7980. {
  7981. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7982. }
  7983. } // END OF CCS_QUANTITY
  7984. }
  7985. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7986. {
  7987. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7988. {
  7989. tempIndex = ((gun_index==2) ? 1: 0);
  7990. }
  7991. else
  7992. {
  7993. tempIndex = gun_index;
  7994. }
  7995. for (int index = 0; index < GB_QUANTITY; index++)
  7996. {
  7997. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7998. {
  7999. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  8000. }
  8001. } // END OF GB_QUANTITY
  8002. }
  8003. else if(gunType[gun_index] == GUN_TYPE_DO)
  8004. {
  8005. tempIndex = gun_index;
  8006. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8007. {
  8008. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8009. {
  8010. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  8011. }
  8012. }
  8013. }
  8014. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  8015. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  8016. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  8017. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  8018. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  8019. }
  8020. // Message create ====================================================================================================
  8021. if(TRUE)
  8022. {
  8023. json_object *MeterValueReq = json_object_new_object();
  8024. json_object *MeterValues = json_object_new_array();
  8025. json_object *sampledValues = json_object_new_array();
  8026. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  8027. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  8028. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  8029. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  8030. {
  8031. json_object *MeterValue = json_object_new_object();
  8032. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  8033. {
  8034. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  8035. {
  8036. json_object *sampledValue = json_object_new_object();
  8037. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  8038. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  8039. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  8040. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  8041. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  8042. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  8043. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  8044. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  8045. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  8046. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  8047. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  8048. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  8049. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  8050. json_object_array_add(sampledValues, sampledValue);
  8051. }
  8052. }
  8053. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  8054. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  8055. json_object_array_add(MeterValues, MeterValue);
  8056. }
  8057. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  8058. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  8059. ,gun_index + 1
  8060. ,MESSAGE_TYPE_CALL
  8061. ,guid
  8062. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  8063. json_object_put(MeterValueReq);
  8064. }
  8065. // Put request guid to hash map
  8066. sprintf(tempdata, "MeterValues,%d", (gun_index));
  8067. 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*/)
  8068. {
  8069. result = PASS;
  8070. //DEBUG_INFO("MeterValues mapitem pass\n");
  8071. }
  8072. if((dataType != ReadingContext_Trigger) &&
  8073. (dataType != ReadingContext_Sample_Clock) &&
  8074. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  8075. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  8076. else
  8077. {
  8078. if(FirstHeartBeat)
  8079. LWS_Send(queuedata +2);
  8080. }
  8081. return result;
  8082. }
  8083. int sendLogStatusNotificationRequest(char *status)
  8084. {
  8085. mtrace();
  8086. int result = PASS;
  8087. char message[4096]={0};
  8088. char guid[37]={0};
  8089. char tempdata[128]={0};
  8090. json_object *LogStatusNotification = json_object_new_object();
  8091. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  8092. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  8093. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  8094. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  8095. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  8096. random_uuid(guid);
  8097. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  8098. json_object_put(LogStatusNotification);
  8099. LWS_Send(message);
  8100. sprintf(tempdata, "LogStatusNotification,%d", 0);
  8101. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8102. {
  8103. result = PASS;
  8104. }
  8105. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  8106. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  8107. return result;
  8108. }
  8109. int sendSecurityEventNotificationRequest()
  8110. {
  8111. mtrace();
  8112. int result = PASS;
  8113. char message[4096]={0};
  8114. char guid[37]={0};
  8115. char tempdata[128]={0};
  8116. json_object *SecurityEventNotification = json_object_new_object();
  8117. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  8118. //Stop Transaction Time
  8119. struct timeval tmnow;
  8120. struct tm *tm;
  8121. gettimeofday(&tmnow, NULL);
  8122. time_t t;
  8123. t = time(NULL);
  8124. /*UTC time and date*/
  8125. tm = gmtime(&t);
  8126. strftime((char *)ShmOCPP16Data->SecurityEventNotification.timestamp, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.timestamp), "%Y-%m-%dT%H:%M:%SZ", tm);
  8127. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  8128. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  8129. if(strlen((char*)ShmOCPP16Data->SecurityEventNotification.techInfo) > 0)
  8130. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  8131. random_uuid(guid);
  8132. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  8133. json_object_put(SecurityEventNotification);
  8134. LWS_Send(message);
  8135. sprintf(tempdata, "SecurityEventNotification,0");
  8136. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8137. {
  8138. result = PASS;
  8139. }
  8140. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  8141. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  8142. return result;
  8143. }
  8144. int sendSignCertificateRequest()
  8145. {
  8146. mtrace();
  8147. int result = PASS;
  8148. char message[4096]={0};
  8149. char guid[37]={0};
  8150. char tempdata[128]={0};
  8151. json_object *SignCertificate = json_object_new_object();
  8152. DEBUG_INFO("sendSignCertificateRequest...\n");
  8153. // Read csr file content
  8154. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  8155. FILE *fp=fopen(CSR_CP,"r");
  8156. char *line = NULL;
  8157. size_t len = 0;
  8158. while(getline(&line, &len, fp) != -1)
  8159. {
  8160. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  8161. {
  8162. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  8163. }
  8164. }
  8165. fclose(fp);
  8166. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  8167. random_uuid(guid);
  8168. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  8169. json_object_put(SignCertificate);
  8170. LWS_Send(message);
  8171. sprintf(tempdata, "SignCertificate,0");
  8172. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8173. {
  8174. result = PASS;
  8175. }
  8176. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  8177. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  8178. return result;
  8179. }
  8180. int sendSignedFirmwareStatusNotificationRequest(char *status)
  8181. {
  8182. mtrace();
  8183. int result = PASS;
  8184. char message[4096]={0};
  8185. char guid[37]={0};
  8186. char tempdata[128]={0};
  8187. json_object *SignedFirmwareStatusNotification = json_object_new_object();
  8188. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  8189. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  8190. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  8191. json_object_object_add(SignedFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  8192. json_object_object_add(SignedFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  8193. random_uuid(guid);
  8194. sprintf(message,"[%d,\"%s\",\"SignedFirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(SignedFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  8195. json_object_put(SignedFirmwareStatusNotification);
  8196. LWS_Send(message);
  8197. sprintf(tempdata, "SignedFirmwareStatusNotification,%d", 0);
  8198. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8199. {
  8200. result = PASS;
  8201. }
  8202. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  8203. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  8204. return result;
  8205. }
  8206. //==========================================
  8207. // send confirm routine
  8208. //==========================================
  8209. int sendCancelReservationConfirmation(char *uuid,char *payload)
  8210. {
  8211. mtrace();
  8212. int result = FAIL;
  8213. char message[100]={0};
  8214. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  8215. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8216. LWS_Send(message);
  8217. result = TRUE;
  8218. return result;
  8219. }
  8220. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  8221. {
  8222. mtrace();
  8223. int result = FAIL;
  8224. char message[100]={0};
  8225. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  8226. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8227. LWS_Send(message);
  8228. result = TRUE;
  8229. return result;
  8230. }
  8231. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  8232. {
  8233. mtrace();
  8234. int result = FAIL;
  8235. char message[100]={0};
  8236. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  8237. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8238. LWS_Send(message);
  8239. result = TRUE;
  8240. return result;
  8241. }
  8242. int sendClearCacheConfirmation(char *uuid,char *payload)
  8243. {
  8244. mtrace();
  8245. int result = FAIL;
  8246. char message[500]={0};
  8247. DEBUG_INFO("sendClearCacheConfirmation...\n");
  8248. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8249. LWS_Send(message);
  8250. return result;
  8251. }
  8252. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  8253. {
  8254. mtrace();
  8255. int result = FAIL;
  8256. char message[500]={0};
  8257. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  8258. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8259. LWS_Send(message);
  8260. return result;
  8261. }
  8262. int sendDataTransferConfirmation(char *uuid,char *payload)
  8263. {
  8264. mtrace();
  8265. char statusStr[20]={0};
  8266. char dataStr[10]={0};
  8267. char sstr[20]={0};
  8268. int c = 0;
  8269. char *loc;
  8270. int result = FAIL;
  8271. DEBUG_INFO("sendDataTransferConfirmation...\n");
  8272. /**********************status**************************/
  8273. loc = strstr(payload, "status");
  8274. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8275. c = 0;
  8276. while (loc[3+strlen("status")+c] != '\"')
  8277. {
  8278. sstr[c] = loc[3+strlen("status")+c];
  8279. c++;
  8280. }
  8281. sstr[c] = '\0';
  8282. strcpy(statusStr, sstr);
  8283. /**********************data**************************/
  8284. loc = strstr(payload, "data");
  8285. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8286. c = 0;
  8287. while (loc[3+strlen("data")+c] != '\"')
  8288. {
  8289. sstr[c] = loc[3+strlen("data")+c];
  8290. c++;
  8291. }
  8292. sstr[c] = '\0';
  8293. strcpy(dataStr, sstr);
  8294. return result;
  8295. }
  8296. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  8297. {
  8298. mtrace();
  8299. int result = FAIL;
  8300. char message[1000]={0};
  8301. int CompositeScheduleIndex = 0;
  8302. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  8303. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  8304. if(nPeriod == 0)
  8305. {
  8306. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  8307. {
  8308. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  8309. ,MESSAGE_TYPE_CALLRESULT
  8310. ,uuid
  8311. ,payload
  8312. ,connectorIdInt);
  8313. }
  8314. else
  8315. {
  8316. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  8317. ,MESSAGE_TYPE_CALLRESULT
  8318. ,uuid
  8319. ,payload
  8320. ,connectorIdInt
  8321. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8322. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8323. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8324. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  8325. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  8326. }
  8327. }
  8328. else
  8329. {
  8330. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  8331. ,MESSAGE_TYPE_CALLRESULT
  8332. ,uuid
  8333. ,payload
  8334. ,connectorIdInt
  8335. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8336. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8337. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8338. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  8339. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  8340. {
  8341. if (idx_sample == 0)
  8342. {
  8343. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8344. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8345. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8346. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8347. }
  8348. else
  8349. {
  8350. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8351. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8352. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8353. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8354. }
  8355. }
  8356. sprintf(message + strlen(message), "]}}]");
  8357. }
  8358. LWS_Send(message);
  8359. result = TRUE;
  8360. return result;
  8361. }
  8362. int sendGetConfigurationConfirmation(char *uuid)
  8363. {
  8364. mtrace();
  8365. int result = FAIL;
  8366. int MaxKeySupported = 0;
  8367. int sentConfigurationNumber= 0;
  8368. int sentunConfigurationNumber= 0;
  8369. char message[1024*10]={0};
  8370. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  8371. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8372. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  8373. ,MESSAGE_TYPE_CALLRESULT
  8374. ,uuid );
  8375. //configuration key
  8376. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  8377. {
  8378. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  8379. {
  8380. if (sentConfigurationNumber == 0)
  8381. {
  8382. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8383. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8384. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8385. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8386. }
  8387. else
  8388. {
  8389. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  8390. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  8391. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  8392. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  8393. }
  8394. sentConfigurationNumber = sentConfigurationNumber + 1;
  8395. }
  8396. }
  8397. sprintf(message + strlen(message), "]");
  8398. if(UnknownKeynum != 0)
  8399. {
  8400. sprintf(message + strlen(message), ",\"unknownKey\":[");
  8401. //unkown key
  8402. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8403. {
  8404. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  8405. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8406. if(sentunConfigurationNumber == 0)
  8407. {
  8408. sprintf(message + strlen(message), "\"%s\""
  8409. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8410. }
  8411. else
  8412. {
  8413. sprintf(message + strlen(message), ",\"%s\""
  8414. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  8415. }
  8416. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8417. }
  8418. sprintf(message + strlen(message), "]");
  8419. }
  8420. sprintf(message + strlen(message), "}]");
  8421. LWS_Send(message);
  8422. return result;
  8423. }
  8424. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8425. {
  8426. mtrace();
  8427. int result = FAIL;
  8428. char message[400]={0};
  8429. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8430. if(strcmp(payload,"")==0)
  8431. {
  8432. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8433. }
  8434. else
  8435. {
  8436. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8437. }
  8438. LWS_Send(message);
  8439. result = TRUE;
  8440. return result;
  8441. }
  8442. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8443. {
  8444. mtrace();
  8445. int result = FAIL;
  8446. char message[80]={0};
  8447. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8448. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8449. LWS_Send(message);
  8450. result = TRUE;
  8451. return result;
  8452. }
  8453. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8454. {
  8455. mtrace();
  8456. int result = FAIL;
  8457. char message[80]={0};
  8458. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8459. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8460. LWS_Send(message);
  8461. result = TRUE;
  8462. return result;
  8463. }
  8464. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8465. {
  8466. mtrace();
  8467. int result = FAIL;
  8468. char message[80]={0};
  8469. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8470. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8471. LWS_Send(message);
  8472. result = TRUE;
  8473. return result;
  8474. }
  8475. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8476. {
  8477. mtrace();
  8478. int result = FAIL;
  8479. char message[80]={0};
  8480. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8481. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8482. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8483. LWS_Send(message);
  8484. result = TRUE;
  8485. return result;
  8486. }
  8487. int sendResetConfirmation(char *uuid,char *payload)
  8488. {
  8489. mtrace();
  8490. int result = FAIL;
  8491. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8492. char message[80]={0};
  8493. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8494. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8495. LWS_Send(message);
  8496. result = TRUE;
  8497. return result;
  8498. }
  8499. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8500. {
  8501. mtrace();
  8502. int result = FAIL;
  8503. char message[500]={0};
  8504. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8505. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8506. LWS_Send(message);
  8507. result = TRUE;
  8508. return result;
  8509. }
  8510. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8511. {
  8512. mtrace();
  8513. int result = FAIL;
  8514. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8515. char message[80]={0};
  8516. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8517. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8518. LWS_Send(message);
  8519. result = TRUE;
  8520. return result;
  8521. }
  8522. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8523. {
  8524. mtrace();
  8525. int result = FAIL;
  8526. char message[80]={0};
  8527. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8528. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8529. LWS_Send(message);
  8530. result = TRUE;
  8531. return result;
  8532. }
  8533. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8534. {
  8535. mtrace();
  8536. int result = FAIL;
  8537. char message[80]={0};
  8538. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8539. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8540. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8541. LWS_Send(message);
  8542. result = TRUE;
  8543. return result;
  8544. }
  8545. int sendUpdateFirmwareConfirmation(char *uuid)
  8546. {
  8547. mtrace();
  8548. int result = FAIL;
  8549. char message[60]={0};
  8550. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8551. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8552. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8553. LWS_Send(message);
  8554. result = TRUE;
  8555. return result;
  8556. }
  8557. int sendCertificateSignedConfirmation(char *uuid)
  8558. {
  8559. mtrace();
  8560. int result = PASS;
  8561. char message[4096]={0};
  8562. json_object *CertificateSigned = json_object_new_object();
  8563. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8564. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8565. sprintf(message,"[%d,\"%s\",%s]"
  8566. ,MESSAGE_TYPE_CALLRESULT
  8567. ,uuid
  8568. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8569. json_object_put(CertificateSigned);
  8570. LWS_Send(message);
  8571. return result;
  8572. }
  8573. int sendDeleteCertificateConfirmation(char *uuid)
  8574. {
  8575. mtrace();
  8576. int result = PASS;
  8577. char message[4096]={0};
  8578. json_object *DeleteCertificate = json_object_new_object();
  8579. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8580. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8581. sprintf(message,"[%d,\"%s\",%s]"
  8582. ,MESSAGE_TYPE_CALLRESULT
  8583. ,uuid
  8584. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8585. json_object_put(DeleteCertificate);
  8586. LWS_Send(message);
  8587. return result;
  8588. }
  8589. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8590. {
  8591. mtrace();
  8592. int result = PASS;
  8593. char message[4096]={0};
  8594. json_object *ExtendedTriggerMessage = json_object_new_object();
  8595. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8596. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8597. sprintf(message,"[%d,\"%s\",%s]"
  8598. ,MESSAGE_TYPE_CALLRESULT
  8599. ,uuid
  8600. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8601. json_object_put(ExtendedTriggerMessage);
  8602. LWS_Send(message);
  8603. return result;
  8604. }
  8605. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8606. {
  8607. mtrace();
  8608. int result = PASS;
  8609. char message[4096]={0};
  8610. json_object *GetInstalledCertificateIds = json_object_new_object();
  8611. json_object *certificateHashDataDatas = json_object_new_array();
  8612. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8613. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8614. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8615. {
  8616. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8617. {
  8618. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm) > 0)
  8619. {
  8620. json_object *certificateHashData = json_object_new_object();
  8621. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8622. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8623. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8624. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8625. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8626. }
  8627. }
  8628. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8629. }
  8630. else
  8631. {
  8632. json_object_put(certificateHashDataDatas);
  8633. }
  8634. sprintf(message,"[%d,\"%s\",%s]"
  8635. ,MESSAGE_TYPE_CALLRESULT
  8636. ,uuid
  8637. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8638. json_object_put(GetInstalledCertificateIds);
  8639. LWS_Send(message);
  8640. return result;
  8641. }
  8642. int sendGetLogConfirmation(char *uuid)
  8643. {
  8644. mtrace();
  8645. int result = PASS;
  8646. char message[4096]={0};
  8647. json_object *GetLog = json_object_new_object();
  8648. DEBUG_INFO("sendGetLogConfirmation...\n");
  8649. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8650. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8651. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8652. sprintf(message,"[%d,\"%s\",%s]"
  8653. ,MESSAGE_TYPE_CALLRESULT
  8654. ,uuid
  8655. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8656. json_object_put(GetLog);
  8657. LWS_Send(message);
  8658. return result;
  8659. }
  8660. int sendInstallCertificateConfirmation(char *uuid)
  8661. {
  8662. mtrace();
  8663. int result = PASS;
  8664. char message[4096]={0};
  8665. json_object *InstallCertificate = json_object_new_object();
  8666. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8667. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8668. sprintf(message,"[%d,\"%s\",%s]"
  8669. ,MESSAGE_TYPE_CALLRESULT
  8670. ,uuid
  8671. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8672. json_object_put(InstallCertificate);
  8673. LWS_Send(message);
  8674. return result;
  8675. }
  8676. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8677. {
  8678. mtrace();
  8679. int result = PASS;
  8680. char message[4096]={0};
  8681. json_object *SignedUpdateFirmware = json_object_new_object();
  8682. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8683. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8684. sprintf(message,"[%d,\"%s\",%s]"
  8685. ,MESSAGE_TYPE_CALLRESULT
  8686. ,uuid
  8687. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8688. json_object_put(SignedUpdateFirmware);
  8689. LWS_Send(message);
  8690. return result;
  8691. }
  8692. int sendUnknownConfirmation(char *uuid)
  8693. {
  8694. mtrace();
  8695. int result = PASS;
  8696. char message[256]={0};
  8697. DEBUG_INFO("sendUnknownConfirmation...\n");
  8698. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8699. LWS_Send(message);
  8700. return result;
  8701. }
  8702. //==========================================
  8703. // Handle server request routine Start
  8704. //==========================================
  8705. int handleCancelReservationRequest(char *uuid, char *payload)
  8706. {
  8707. mtrace();
  8708. int result = FAIL;
  8709. int gunNO = 0;
  8710. int reservationIdInt = -1;
  8711. char comfirmstr[20];
  8712. DEBUG_INFO("handleCancelReservationRequest...\n");
  8713. json_object *CancelReservation;
  8714. CancelReservation = json_tokener_parse(payload);
  8715. if(!is_error(CancelReservation))
  8716. {
  8717. // Required data
  8718. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8719. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8720. }
  8721. json_object_put(CancelReservation);
  8722. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8723. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8724. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8725. if(reservationIdInt != -1)
  8726. {
  8727. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8728. //check Transaction active
  8729. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8730. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8731. {
  8732. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8733. {
  8734. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8735. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8736. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8737. {
  8738. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8739. }
  8740. else
  8741. {
  8742. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8743. }
  8744. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8745. goto end;
  8746. }
  8747. }
  8748. for (int index = 0; index < CCS_QUANTITY; index++)
  8749. {
  8750. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8751. {
  8752. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8753. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8754. if(gunType[2] == GUN_TYPE_CCS)
  8755. {
  8756. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8757. }
  8758. else
  8759. {
  8760. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8761. }
  8762. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8763. goto end;
  8764. }
  8765. }
  8766. for (int index = 0; index < GB_QUANTITY; index++)
  8767. {
  8768. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8769. {
  8770. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8771. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8772. if(gunType[2] == GUN_TYPE_GBT)
  8773. {
  8774. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8775. }
  8776. else
  8777. {
  8778. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8779. }
  8780. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8781. goto end;
  8782. }
  8783. }
  8784. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8785. {
  8786. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8787. {
  8788. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8789. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8790. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8791. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8792. goto end;
  8793. }
  8794. }
  8795. for (int index = 0; index < AC_QUANTITY; index++)
  8796. {
  8797. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8798. {
  8799. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8800. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8801. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8802. {
  8803. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8804. }
  8805. else
  8806. {
  8807. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8808. }
  8809. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8810. goto end;
  8811. }
  8812. }
  8813. }
  8814. //The reservationId does NOT match the reservationId
  8815. sendCancelReservationConfirmation(uuid, comfirmstr);
  8816. end:
  8817. // Fill in ocpp packet uuid
  8818. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8819. return result;
  8820. }
  8821. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8822. {
  8823. mtrace();
  8824. int result = FAIL;
  8825. int gunIndex = -1;
  8826. char typeStr[16]={0};
  8827. char comfirmstr[20];
  8828. int specificId = FALSE;
  8829. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8830. json_object *ChangeAvailability;
  8831. ChangeAvailability = json_tokener_parse(payload);
  8832. if(!is_error(ChangeAvailability))
  8833. {
  8834. // Required data
  8835. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8836. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8837. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8838. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8839. }
  8840. json_object_put(ChangeAvailability);
  8841. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8842. {
  8843. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8844. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8845. }
  8846. else if(gunIndex == 0)
  8847. {
  8848. for(int i=0; i < gunTotalNumber; i++)
  8849. {
  8850. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8851. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8852. }
  8853. }
  8854. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8855. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8856. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8857. {
  8858. specificId = TRUE;
  8859. }
  8860. if(specificId == FALSE)
  8861. goto end;
  8862. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8863. {
  8864. //----------------------gunIndex is 0 ------------------------------------------------//
  8865. if(gunIndex == 0)
  8866. {
  8867. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8868. {
  8869. for(int i=0; i < gunTotalNumber; i++)
  8870. {
  8871. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8872. {
  8873. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8874. {
  8875. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8876. {
  8877. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8878. goto end;
  8879. }
  8880. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8881. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8882. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8883. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8884. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8885. {
  8886. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8887. goto end;
  8888. }
  8889. }
  8890. }//END FOR CHAdeMO_QUANTITY
  8891. for (int index = 0; index < CCS_QUANTITY; index++)
  8892. {
  8893. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8894. {
  8895. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8896. {
  8897. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8898. goto end;
  8899. }
  8900. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8901. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8902. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8903. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8904. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8905. {
  8906. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8907. goto end;
  8908. }
  8909. }
  8910. }//END FOR CCS_QUANTITY
  8911. for (int index = 0; index < GB_QUANTITY; index++)
  8912. {
  8913. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8914. {
  8915. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8916. {
  8917. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8918. goto end;
  8919. }
  8920. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8921. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8922. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8923. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8924. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8925. {
  8926. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8927. goto end;
  8928. }
  8929. }
  8930. }// END FOR GB_QUANTITY
  8931. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8932. {
  8933. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8934. {
  8935. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8936. {
  8937. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8938. goto end;
  8939. }
  8940. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8941. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8942. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8943. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8944. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8945. {
  8946. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8947. goto end;
  8948. }
  8949. }
  8950. }// END FOR GENERAL_GUN_QUANTITY
  8951. for (int index = 0; index < AC_QUANTITY; index++)
  8952. {
  8953. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8954. {
  8955. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8956. {
  8957. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8958. goto end;
  8959. }
  8960. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8961. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8962. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8963. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8964. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8965. {
  8966. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8967. goto end;
  8968. }
  8969. }
  8970. }//END FOR AC_QUANTITY
  8971. }// END FOR gunTotalNumber
  8972. }
  8973. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8974. {
  8975. for(int i=0; i < gunTotalNumber; i++)
  8976. {
  8977. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8978. {
  8979. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8980. goto end;
  8981. }
  8982. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8983. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8984. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8985. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8986. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8987. {
  8988. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8989. goto end;
  8990. }
  8991. }
  8992. }
  8993. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8994. goto end;
  8995. }
  8996. //----------------------gunIndex is not 0 ------------------------------------------------//
  8997. //check Transaction active
  8998. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8999. {
  9000. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  9001. {
  9002. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  9003. {
  9004. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9005. goto end;
  9006. }
  9007. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9008. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9009. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9010. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9011. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9012. {
  9013. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9014. goto end;
  9015. }
  9016. else
  9017. {
  9018. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  9019. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9020. goto end;
  9021. }
  9022. }
  9023. }//END FOR CHAdeMO_QUANTITY
  9024. for (int index = 0; index < CCS_QUANTITY; index++)
  9025. {
  9026. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  9027. {
  9028. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  9029. {
  9030. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9031. goto end;
  9032. }
  9033. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9034. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9035. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9036. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9037. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9038. {
  9039. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9040. goto end;
  9041. }
  9042. else
  9043. {
  9044. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  9045. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9046. goto end;
  9047. }
  9048. }
  9049. }//END FOR CCS_QUANTITY
  9050. for (int index = 0; index < GB_QUANTITY; index++)
  9051. {
  9052. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  9053. {
  9054. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  9055. {
  9056. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9057. goto end;
  9058. }
  9059. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9060. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9061. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9062. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9063. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9064. {
  9065. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9066. goto end;
  9067. }
  9068. else
  9069. {
  9070. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  9071. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9072. goto end;
  9073. }
  9074. }
  9075. }// END FOR GB_QUANTITY
  9076. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9077. {
  9078. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  9079. {
  9080. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  9081. {
  9082. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9083. goto end;
  9084. }
  9085. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  9086. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  9087. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9088. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  9089. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9090. {
  9091. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9092. goto end;
  9093. }
  9094. else
  9095. {
  9096. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  9097. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9098. goto end;
  9099. }
  9100. }
  9101. }// END FOR GENERAL_GUN_QUANTITY
  9102. for (int index = 0; index < AC_QUANTITY; index++)
  9103. {
  9104. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  9105. {
  9106. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  9107. {
  9108. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9109. goto end;
  9110. }
  9111. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9112. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9113. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9114. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9115. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9116. {
  9117. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  9118. goto end;
  9119. }
  9120. else
  9121. {
  9122. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  9123. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9124. goto end;
  9125. }
  9126. }
  9127. }//END FOR AC_QUANTITY
  9128. }//END FOR AvailabilityTypeStr[Inoperative]
  9129. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  9130. {
  9131. //----------------------gunIndex is 0 ------------------------------------------------//
  9132. if(gunIndex == 0)
  9133. {
  9134. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9135. {
  9136. for(int i=0; i < gunTotalNumber; i++)
  9137. {
  9138. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9139. {
  9140. 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
  9141. {
  9142. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9143. goto end;
  9144. }
  9145. }//END FOR CHAdeMO_QUANTITY
  9146. for (int index = 0; index < CCS_QUANTITY; index++)
  9147. {
  9148. 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
  9149. {
  9150. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9151. goto end;
  9152. }
  9153. }//END FOR CCS_QUANTITY
  9154. for (int index = 0; index < GB_QUANTITY; index++)
  9155. {
  9156. 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
  9157. {
  9158. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9159. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9160. goto end;
  9161. }
  9162. }// END FOR GB_QUANTITY
  9163. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9164. {
  9165. 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
  9166. {
  9167. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9168. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9169. goto end;
  9170. }
  9171. }// END FOR GENERAL_GUN_QUANTITY
  9172. for (int index = 0; index < AC_QUANTITY; index++)
  9173. {
  9174. 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
  9175. {
  9176. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9177. goto end;
  9178. }
  9179. }//END FOR CHAdeMO_QUANTITY
  9180. }// END FOR gunTotalNumber
  9181. }
  9182. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  9183. {
  9184. for(int i=0; i < gunTotalNumber; i++)
  9185. {
  9186. for (int index = 0; index < AC_QUANTITY; index++)
  9187. {
  9188. 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
  9189. {
  9190. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  9191. goto end;
  9192. }
  9193. }//END FOR CHAdeMO_QUANTITY
  9194. } // END FOR gunTotalNumber
  9195. }
  9196. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9197. goto end;
  9198. }
  9199. //----------------------gunIndex is not 0 ------------------------------------------------//
  9200. //check Transaction active
  9201. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9202. {
  9203. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9204. {
  9205. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9206. goto end;
  9207. }
  9208. }//END FOR CHAdeMO_QUANTITY
  9209. for (int index = 0; index < CCS_QUANTITY; index++)
  9210. {
  9211. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9212. {
  9213. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9214. goto end;
  9215. }
  9216. }//END FOR CCS_QUANTITY
  9217. for (int index = 0; index < GB_QUANTITY; index++)
  9218. {
  9219. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9220. {
  9221. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9222. goto end;
  9223. }
  9224. }// END FOR GB_QUANTITY
  9225. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9226. {
  9227. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9228. {
  9229. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9230. goto end;
  9231. }
  9232. }// END FOR GENERAL_GUN_QUANTITY
  9233. for (int index = 0; index < AC_QUANTITY; index++)
  9234. {
  9235. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9236. {
  9237. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9238. goto end;
  9239. }
  9240. }//END FOR AC_QUANTITY
  9241. }//END FOR AvailabilityTypeStr[Operative]
  9242. end:
  9243. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9244. {
  9245. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  9246. }
  9247. else
  9248. {
  9249. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  9250. }
  9251. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9252. {
  9253. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9254. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9255. }
  9256. else if(gunIndex == 0)
  9257. {
  9258. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9259. {
  9260. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  9261. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  9262. }
  9263. }
  9264. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  9265. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9266. return result;
  9267. }
  9268. int handleChangeConfigurationRequest(char *uuid, char *payload)
  9269. {
  9270. mtrace();
  9271. int valueInvalid = NO;
  9272. int result = FAIL;
  9273. char keystr[40]={0};
  9274. char valuestr[501]={0}; //value should be limited in 500 bytes
  9275. char comfirmstr[20]={0};
  9276. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  9277. json_object *ChangeConfiguration;
  9278. ChangeConfiguration = json_tokener_parse(payload);
  9279. if(!is_error(ChangeConfiguration))
  9280. {
  9281. // Required data
  9282. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  9283. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  9284. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  9285. {
  9286. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  9287. }
  9288. else
  9289. {
  9290. valueInvalid = YES;
  9291. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  9292. }
  9293. }
  9294. json_object_put(ChangeConfiguration);
  9295. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  9296. {
  9297. DEBUG_ERROR("Payload is null or value is invalid.\n");
  9298. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9299. }
  9300. else
  9301. {
  9302. int status = setKeyValue(keystr, valuestr);
  9303. switch(status)
  9304. {
  9305. case ConfigurationStatus_Accepted:
  9306. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  9307. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  9308. StoreConfigurationTable();
  9309. break;
  9310. case RebootRequired:
  9311. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  9312. StoreConfigurationTable();
  9313. break;
  9314. case NotSupported:
  9315. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  9316. break;
  9317. case ConfigurationStatus_Rejected:
  9318. default:
  9319. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9320. break;
  9321. }
  9322. }
  9323. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  9324. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  9325. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9326. {
  9327. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9328. SetOcppConnStatus(FALSE);
  9329. }
  9330. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9331. {
  9332. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9333. }
  9334. return result;
  9335. }
  9336. int handleClearCacheRequest(char *uuid, char *payload)
  9337. {
  9338. mtrace();
  9339. int result = FAIL;
  9340. char comfirmstr[20];
  9341. char rmFileCmd[100]={0};
  9342. struct stat stats;
  9343. DEBUG_INFO("handleClearCacheRequest...\n");
  9344. stat("/Storage/OCPP", &stats);
  9345. // Check for directory existence
  9346. if (S_ISDIR(stats.st_mode) == 1)
  9347. {}
  9348. else
  9349. {
  9350. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  9351. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  9352. system(rmFileCmd);
  9353. }
  9354. if(OCPP_cleanLocalCache())
  9355. {
  9356. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  9357. }
  9358. else
  9359. {
  9360. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  9361. }
  9362. sendClearCacheConfirmation(uuid, comfirmstr);
  9363. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9364. return result;
  9365. }
  9366. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9367. {
  9368. mtrace();
  9369. int result = FAIL;
  9370. int resultRename;
  9371. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9372. char chargingProfilePurposeStr[26]={0};
  9373. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9374. char tempchargingProfilePurposeStr[26]={0};
  9375. char str[100]={0};
  9376. char fname[200]={0};
  9377. char comfirmstr[20]={0};
  9378. char word[1600]={0};
  9379. int clearflag = FALSE;
  9380. int chargingProfileIdIsNULL = FALSE;
  9381. int connectorIsNULL = FALSE;
  9382. int chargingProfilePurposeIsNULL = FALSE;
  9383. int stackLevelIsNULL = FALSE;
  9384. //int GotoEnd = FALSE;
  9385. FILE *fptr1, *fptr2;
  9386. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9387. int n_chargingProfile=0;
  9388. int isEmptyFile = FALSE;
  9389. char sLineWord[1600]={0};
  9390. char chargingProfiles[10][100]={0};
  9391. int ChargeProfileCount = 0;
  9392. int ch;
  9393. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9394. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9395. json_object *ClearChargingProfile;
  9396. ClearChargingProfile = json_tokener_parse(payload);
  9397. if(!is_error(ClearChargingProfile))
  9398. {
  9399. // Optional data
  9400. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9401. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9402. else
  9403. chargingProfileIdIsNULL = TRUE;
  9404. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9405. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9406. else
  9407. connectorIsNULL = TRUE;
  9408. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9409. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9410. else
  9411. chargingProfilePurposeIsNULL = TRUE;
  9412. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9413. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9414. else
  9415. stackLevelIsNULL = TRUE;
  9416. }
  9417. json_object_put(ClearChargingProfile);
  9418. if(connectorIsNULL == FALSE)
  9419. {
  9420. switch(connectorIdInt)
  9421. {
  9422. case 0:
  9423. if(chargingProfilePurposeIsNULL == TRUE)
  9424. {
  9425. int l = 0;
  9426. strcpy(fname, ChargePointMaxProfile_JSON);
  9427. if((access(fname,F_OK))!=-1)
  9428. {
  9429. strcpy(chargingProfiles[l], fname);
  9430. l = l + 1;
  9431. }
  9432. strcpy(fname, TxDefaultProfile_0_JSON);
  9433. if((access(fname,F_OK))!=-1)
  9434. {
  9435. strcpy(chargingProfiles[l], fname);
  9436. l = l + 1;
  9437. }
  9438. ChargeProfileCount = l;
  9439. }
  9440. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  9441. {
  9442. strcpy(fname, ChargePointMaxProfile_JSON);
  9443. if((access(fname,F_OK))!=-1)
  9444. {
  9445. strcpy(chargingProfiles[0], fname);
  9446. ChargeProfileCount = 1;
  9447. }
  9448. }
  9449. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9450. {
  9451. strcpy(fname, TxDefaultProfile_0_JSON);
  9452. if((access(fname,F_OK))!=-1)
  9453. {
  9454. strcpy(chargingProfiles[0], fname);
  9455. ChargeProfileCount = 1;
  9456. }
  9457. }
  9458. break;
  9459. default:
  9460. if(chargingProfilePurposeIsNULL == TRUE)
  9461. {
  9462. int m = 0;
  9463. memset(fname, 0, ARRAY_SIZE(fname));
  9464. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9465. if((access(fname,F_OK))!=-1)
  9466. {
  9467. strcpy(chargingProfiles[m], fname);
  9468. m = m + 1;
  9469. }
  9470. memset(fname, 0, ARRAY_SIZE(fname));
  9471. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9472. if((access(fname,F_OK))!=-1)
  9473. {
  9474. strcpy(chargingProfiles[m], fname);
  9475. m = m + 1;
  9476. }
  9477. ChargeProfileCount = m;
  9478. }
  9479. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9480. {
  9481. //strcpy(fname, TxDefaultProfile_1_JSON);
  9482. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9483. if((access(fname,F_OK))!=-1)
  9484. {
  9485. strcpy(chargingProfiles[0], fname);
  9486. ChargeProfileCount = 1;
  9487. }
  9488. }
  9489. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9490. {
  9491. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9492. if((access(fname,F_OK))!=-1)
  9493. {
  9494. strcpy(chargingProfiles[0], fname);
  9495. ChargeProfileCount = 1;
  9496. }
  9497. //strcpy(fname, TxProfile_1_JSON);
  9498. }
  9499. //strcpy(fname, ChargePointMaxProfile_JSON );
  9500. break;
  9501. }
  9502. }
  9503. else // Check all Charging Profiles
  9504. {
  9505. int i = 0;
  9506. char fnametemp[200]={0};
  9507. ChargeProfileCount = 0;
  9508. //Check ChargePointMaxProfile.json exit
  9509. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9510. {
  9511. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9512. i = i + 1;
  9513. }
  9514. //Check TxDefaultProfile_0.json exit
  9515. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9516. {
  9517. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9518. i = i + 1;
  9519. }
  9520. //Check TxDefaultProfile_%d.json
  9521. for(int j=1; j <= gunTotalNumber; j++)
  9522. {
  9523. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9524. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9525. if((access(fnametemp,F_OK))!=-1)
  9526. {
  9527. strcpy(chargingProfiles[i], fnametemp);
  9528. i = i + 1;
  9529. }
  9530. }
  9531. //Check TxProfile_%d.json
  9532. for(int j=1; j <= gunTotalNumber; j++)
  9533. {
  9534. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9535. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9536. if((access(fnametemp,F_OK))!=-1)
  9537. {
  9538. strcpy(chargingProfiles[i], fnametemp);
  9539. i = i + 1;
  9540. }
  9541. }
  9542. ChargeProfileCount = i;
  9543. }// End connectorIsNULL is TRUE
  9544. if(ChargeProfileCount == 0)
  9545. {
  9546. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9547. goto end;
  9548. }
  9549. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9550. {
  9551. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9552. goto end;
  9553. }
  9554. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9555. {
  9556. memset(str, 0, ARRAY_SIZE(str));
  9557. // clear temp file
  9558. sprintf(str,"rm -f %s",temp);
  9559. system(str);
  9560. for(int k=0; k < ChargeProfileCount; k++)
  9561. {
  9562. memset(str, 0, ARRAY_SIZE(str));
  9563. //clear file in C
  9564. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9565. system(str);
  9566. }
  9567. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9568. goto end;
  9569. }
  9570. else if(connectorIsNULL == TRUE)
  9571. {
  9572. for(int k=0; k < ChargeProfileCount; k++)
  9573. {
  9574. fptr1 = fopen(chargingProfiles[k], "r");
  9575. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9576. //Check Charging Profile Count
  9577. while(fscanf(fptr1, "%s", word) != EOF)
  9578. {
  9579. //DEBUG_INFO("word=%s\n",word);
  9580. if(strstr(word, "chargingProfileId")!= NULL)
  9581. {
  9582. //DEBUG_INFO("test chargingProfileId \n");
  9583. n_chargingProfile = n_chargingProfile + 1;
  9584. //DEBUG_INFO("chargingProfileId Found\n");
  9585. }
  9586. }
  9587. rewind(fptr1);
  9588. //search Charging Profile Element
  9589. //int i= 0;
  9590. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9591. {
  9592. json_object *tmpProfilee;
  9593. tmpProfilee = json_tokener_parse(sLineWord);
  9594. if(!is_error(tmpProfilee))
  9595. {
  9596. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9597. {
  9598. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9599. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9600. }
  9601. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9602. {
  9603. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9604. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9605. }
  9606. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9607. {
  9608. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9609. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9610. }
  9611. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9612. {
  9613. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9614. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9615. }
  9616. }
  9617. json_object_put(tmpProfilee);
  9618. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9619. {
  9620. //------- not write to fptr2-------//
  9621. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9622. //clearflag = TRUE;
  9623. }
  9624. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9625. {
  9626. //------- not write to fptr2-------//
  9627. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9628. }
  9629. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9630. {
  9631. //------- not write to fptr2-------//
  9632. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9633. }
  9634. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9635. {
  9636. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9637. }
  9638. else
  9639. {
  9640. fprintf(fptr2, sLineWord);//writing data into file
  9641. }
  9642. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9643. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9644. if(clearflag == TRUE)
  9645. {
  9646. fclose(fptr1);
  9647. fclose(fptr2);
  9648. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9649. system(str);
  9650. // clear temp file
  9651. sprintf(str,"rm -f %s",temp);
  9652. system(str);
  9653. }
  9654. else
  9655. {
  9656. fclose(fptr1);
  9657. fclose(fptr2);
  9658. memset(str, 0, ARRAY_SIZE(str));
  9659. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9660. system(str);
  9661. resultRename = rename(temp, chargingProfiles[k]);
  9662. if(resultRename == 0)
  9663. {
  9664. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9665. }
  9666. else
  9667. {
  9668. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9669. }
  9670. if(comfirmstr[0]== 0)
  9671. {
  9672. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9673. }
  9674. //Check chargingProfile is empty file
  9675. /*------ Read the file ----------------*/
  9676. fptr1=fopen(chargingProfiles[k],"r");
  9677. ch=fgetc(fptr1);
  9678. rewind(fptr1);
  9679. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9680. if(ch!=EOF)
  9681. {
  9682. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9683. {
  9684. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9685. if(sLineWord[0]=='\0')
  9686. {
  9687. isEmptyFile = TRUE;
  9688. break;
  9689. }
  9690. else
  9691. {
  9692. isEmptyFile = FALSE;
  9693. break;
  9694. }
  9695. }
  9696. }
  9697. else
  9698. isEmptyFile = TRUE;
  9699. fclose(fptr1);
  9700. if(isEmptyFile == TRUE)
  9701. {
  9702. memset(str, 0, ARRAY_SIZE(str));
  9703. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9704. system(str);
  9705. }
  9706. }
  9707. }// End of while(int k=0; k < ChargePointCount; k++)
  9708. }
  9709. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9710. {
  9711. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9712. for(int k=0; k < ChargeProfileCount; k++)
  9713. {
  9714. fptr1 = fopen(chargingProfiles[k], "r");
  9715. fptr2 = fopen(temp, "w+");
  9716. //Check Charging Profile Count
  9717. while(fscanf(fptr1, "%s", word) != EOF)
  9718. {
  9719. //DEBUG_INFO("word=%s\n",word);
  9720. if(strstr(word, "chargingProfileId")!= NULL)
  9721. {
  9722. n_chargingProfile = n_chargingProfile + 1;
  9723. }
  9724. }
  9725. rewind(fptr1);
  9726. //search Charging Profile Element
  9727. //int i= 0;
  9728. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9729. {
  9730. json_object *tmpProfilee;
  9731. tmpProfilee = json_tokener_parse(sLineWord);
  9732. if(!is_error(tmpProfilee))
  9733. {
  9734. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9735. {
  9736. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9737. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9738. }
  9739. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9740. {
  9741. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9742. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9743. }
  9744. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9745. {
  9746. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9747. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9748. }
  9749. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9750. {
  9751. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9752. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9753. }
  9754. }
  9755. json_object_put(tmpProfilee);
  9756. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9757. {
  9758. //------- not write to fptr2-------//
  9759. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9760. //clearflag = TRUE;
  9761. }
  9762. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9763. {
  9764. //------- not write to fptr2-------//
  9765. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9766. }
  9767. else if(stackLevelIsNULL == TRUE)
  9768. {
  9769. //Clear Whole File
  9770. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9771. clearflag = TRUE;
  9772. break;
  9773. }
  9774. else
  9775. {
  9776. fprintf(fptr2, sLineWord);//writing data into file
  9777. }
  9778. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9779. }
  9780. if(clearflag == TRUE)
  9781. {
  9782. fclose(fptr1);
  9783. fclose(fptr2);
  9784. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9785. system(str);
  9786. // clear temp file
  9787. sprintf(str,"rm -f %s",temp);
  9788. system(str);
  9789. }
  9790. else
  9791. {
  9792. fclose(fptr1);
  9793. fclose(fptr2);
  9794. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9795. system(str);
  9796. resultRename = rename(temp, chargingProfiles[k]);
  9797. if(resultRename == 0)
  9798. {
  9799. DEBUG_INFO("File ChargingProfile renamed successfully");
  9800. }
  9801. else
  9802. {
  9803. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9804. }
  9805. if(comfirmstr[0]== 0)
  9806. {
  9807. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9808. }
  9809. //Check chargingProfile is empty file
  9810. /*------ Read the file ----------------*/
  9811. fptr1=fopen(chargingProfiles[k],"r");
  9812. ch=fgetc(fptr1);
  9813. rewind(fptr1);
  9814. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9815. if(ch!=EOF)
  9816. {
  9817. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9818. {
  9819. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9820. if(sLineWord[0]=='\0')
  9821. {
  9822. isEmptyFile = TRUE;
  9823. break;
  9824. }
  9825. else
  9826. {
  9827. isEmptyFile = FALSE;
  9828. break;
  9829. }
  9830. }
  9831. }
  9832. else
  9833. isEmptyFile = TRUE;
  9834. fclose(fptr1);
  9835. if(isEmptyFile == TRUE)
  9836. {
  9837. memset(str, 0, ARRAY_SIZE(str));
  9838. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9839. system(str);
  9840. }
  9841. /*------- End of reading ---------------*/
  9842. }
  9843. } // while(int k=0; k < ChargeProfileCount; k++)
  9844. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9845. end:
  9846. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9847. {
  9848. if(connectorIdInt == 0)
  9849. {
  9850. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9851. {
  9852. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9853. }
  9854. }
  9855. else
  9856. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9857. }
  9858. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9859. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9860. return result;
  9861. }
  9862. void createFirmwareVersionByDataTransfer(void)
  9863. {
  9864. json_object *FirmwareDataTransfer = json_object_new_object();
  9865. // AC & DC model
  9866. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9867. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9868. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9869. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9870. // DC model
  9871. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9872. {
  9873. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9874. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9875. (gunType[3] != GUN_TYPE_UNKNOWN))
  9876. {
  9877. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9878. }
  9879. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9880. {
  9881. // DS DM DW
  9882. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9883. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9884. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9885. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9886. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9887. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9888. }
  9889. else
  9890. {
  9891. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9892. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9893. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9894. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9895. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9896. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9897. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9898. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9899. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9900. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9901. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9902. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9903. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9904. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9905. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9906. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9907. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9908. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9909. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9910. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9911. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9912. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9913. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9914. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9915. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9916. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9917. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9918. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9919. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9920. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9921. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9922. }
  9923. }
  9924. // 4G model
  9925. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9926. {
  9927. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9928. }
  9929. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9930. json_object_put(FirmwareDataTransfer);
  9931. }
  9932. int handleDataTransferRequest(char *uuid, char *payload)
  9933. {
  9934. mtrace();
  9935. json_object *response = json_object_new_object();
  9936. int result = FAIL;
  9937. char tempvendorId[255]={0};
  9938. char tempmessageId[50]={0};
  9939. char tempdata[10240]={0};
  9940. char message[20480]={0};
  9941. DEBUG_INFO("handleDataTransferRequest...\n");
  9942. if((uuid != NULL) && (payload != NULL))
  9943. {
  9944. json_object *DataTransfer;
  9945. DataTransfer = json_tokener_parse(payload);
  9946. if(!is_error(DataTransfer))
  9947. {
  9948. // Required data
  9949. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9950. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9951. // Optional data
  9952. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9953. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9954. if(json_object_object_get(DataTransfer, "data") != NULL)
  9955. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9956. result = PASS;
  9957. }
  9958. json_object_put(DataTransfer);
  9959. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9960. {
  9961. // Send all moudle firmware version on EVSE
  9962. createFirmwareVersionByDataTransfer();
  9963. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9964. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9965. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9966. json_object_put(response);
  9967. }
  9968. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9969. {
  9970. system("/usr/bin/run_tmate_restart.sh &");
  9971. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9972. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9973. json_object_put(response);
  9974. }
  9975. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9976. {
  9977. json_object *data;
  9978. data = json_tokener_parse(tempdata);
  9979. if(!is_error(data))
  9980. {
  9981. 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))
  9982. {
  9983. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9984. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9985. if(json_object_object_get(data, "SOC") != NULL)
  9986. {
  9987. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9988. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9989. }
  9990. if(json_object_object_get(data, "Energy") != NULL)
  9991. {
  9992. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9993. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9994. }
  9995. if(json_object_object_get(data, "Duration") != NULL)
  9996. {
  9997. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9998. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9999. }
  10000. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10001. }
  10002. else
  10003. {
  10004. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10005. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  10006. }
  10007. }
  10008. else
  10009. {
  10010. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10011. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10012. }
  10013. json_object_put(data);
  10014. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10015. json_object_put(response);
  10016. }
  10017. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  10018. {
  10019. json_object *data;
  10020. data = json_tokener_parse(tempdata);
  10021. if(!is_error(data))
  10022. {
  10023. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  10024. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  10025. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  10026. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  10027. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  10028. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  10029. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  10030. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  10031. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  10032. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  10033. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10034. }
  10035. else
  10036. {
  10037. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10038. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10039. }
  10040. json_object_put(data);
  10041. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10042. json_object_put(response);
  10043. }
  10044. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  10045. {
  10046. json_object *data;
  10047. data = json_tokener_parse(tempdata);
  10048. if(!is_error(data))
  10049. {
  10050. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  10051. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10052. if(json_object_object_get(data, "idToken") != NULL)
  10053. {
  10054. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  10055. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  10056. }
  10057. else
  10058. {
  10059. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10060. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  10061. }
  10062. if(json_object_object_get(data, "price") != NULL) //v1.0
  10063. {
  10064. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  10065. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  10066. }
  10067. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  10068. {
  10069. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10070. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10071. }
  10072. else
  10073. {
  10074. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10075. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  10076. }
  10077. }
  10078. else
  10079. {
  10080. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10081. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10082. }
  10083. json_object_put(data);
  10084. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10085. json_object_put(response);
  10086. }
  10087. else if(strstr(tempmessageId, "RunningCost") != NULL)
  10088. {
  10089. json_object *data;
  10090. data = json_tokener_parse(tempdata);
  10091. if(!is_error(data))
  10092. {
  10093. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10094. if(json_object_object_get(data, "txId") != NULL)
  10095. {
  10096. // California pricing V1.0
  10097. DEBUG_INFO("California pricing V1.0\n");
  10098. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  10099. sprintf((char*)dmsVersion, "1.0");
  10100. for(int idx = 0;idx<gunTotalNumber;idx++)
  10101. {
  10102. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10103. {
  10104. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  10105. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  10106. if(json_object_object_get(data, "description") != NULL)
  10107. {
  10108. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  10109. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  10110. }
  10111. else
  10112. {
  10113. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10114. json_object_object_add(response, "data", json_object_new_string("description not found."));
  10115. }
  10116. }
  10117. }
  10118. }
  10119. else if(json_object_object_get(data, "transactionId") != NULL)
  10120. {
  10121. // California pricing V2.0
  10122. DEBUG_INFO("California pricing V2.0\n");
  10123. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  10124. sprintf((char*)dmsVersion, "2.0");
  10125. for(int idx=0;idx<gunTotalNumber;idx++)
  10126. {
  10127. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  10128. {
  10129. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10130. if(json_object_object_get(data, "timestamp") != NULL)
  10131. {
  10132. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  10133. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  10134. }
  10135. else
  10136. {
  10137. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10138. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  10139. }
  10140. if(json_object_object_get(data, "meterValue") != NULL)
  10141. {
  10142. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  10143. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  10144. }
  10145. else
  10146. {
  10147. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10148. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  10149. }
  10150. if(json_object_object_get(data, "cost") != NULL)
  10151. {
  10152. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  10153. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10154. }
  10155. else
  10156. {
  10157. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10158. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10159. }
  10160. if(json_object_object_get(data, "state") != NULL)
  10161. {
  10162. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  10163. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  10164. }
  10165. else
  10166. {
  10167. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10168. json_object_object_add(response, "data", json_object_new_string("state not found."));
  10169. }
  10170. if(json_object_object_get(data, "chargingPrice") != NULL)
  10171. {
  10172. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  10173. {
  10174. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  10175. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  10176. }
  10177. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  10178. {
  10179. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  10180. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  10181. }
  10182. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  10183. {
  10184. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  10185. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  10186. }
  10187. }
  10188. else
  10189. {
  10190. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10191. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  10192. }
  10193. if(json_object_object_get(data, "idlePrice") != NULL)
  10194. {
  10195. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  10196. {
  10197. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  10198. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  10199. }
  10200. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  10201. {
  10202. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  10203. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  10204. }
  10205. }
  10206. if(json_object_object_get(data, "nextPeriod") != NULL)
  10207. {
  10208. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  10209. {
  10210. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  10211. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  10212. }
  10213. else
  10214. {
  10215. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10216. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  10217. }
  10218. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  10219. {
  10220. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  10221. {
  10222. 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")));
  10223. 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"));
  10224. }
  10225. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  10226. {
  10227. 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")));
  10228. 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"));
  10229. }
  10230. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  10231. {
  10232. 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")));
  10233. 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"));
  10234. }
  10235. }
  10236. else
  10237. {
  10238. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10239. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  10240. }
  10241. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  10242. {
  10243. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  10244. {
  10245. 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")));
  10246. 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"));
  10247. }
  10248. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  10249. {
  10250. 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")));
  10251. 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"));
  10252. }
  10253. }
  10254. }
  10255. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  10256. {
  10257. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  10258. {
  10259. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10260. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10261. }
  10262. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  10263. {
  10264. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  10265. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  10266. }
  10267. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  10268. {
  10269. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  10270. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  10271. }
  10272. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  10273. {
  10274. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10275. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10276. }
  10277. }
  10278. }
  10279. }
  10280. }
  10281. else
  10282. {
  10283. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10284. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10285. }
  10286. }
  10287. else
  10288. {
  10289. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10290. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10291. }
  10292. json_object_put(data);
  10293. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10294. json_object_put(response);
  10295. }
  10296. else if(strstr(tempmessageId, "FinalCost") != NULL)
  10297. {
  10298. json_object *data;
  10299. data = json_tokener_parse(tempdata);
  10300. if(!is_error(data))
  10301. {
  10302. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10303. if(json_object_object_get(data, "txId") != NULL)
  10304. {
  10305. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  10306. for(int idx = 0;idx<gunTotalNumber;idx++)
  10307. {
  10308. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10309. {
  10310. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10311. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  10312. if(json_object_object_get(data, "description") != NULL)
  10313. {
  10314. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  10315. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  10316. }
  10317. else
  10318. {
  10319. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10320. json_object_object_add(response, "data", json_object_new_string("description not found."));
  10321. }
  10322. }
  10323. }
  10324. }
  10325. else if(json_object_object_get(data, "transactionId") != NULL)
  10326. {
  10327. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  10328. for(int idx = 0;idx<gunTotalNumber;idx++)
  10329. {
  10330. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  10331. {
  10332. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10333. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10334. if(json_object_object_get(data, "cost") != NULL)
  10335. {
  10336. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  10337. ShmOCPP16Data->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10338. }
  10339. else
  10340. {
  10341. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10342. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10343. }
  10344. if(json_object_object_get(data, "priceText") != NULL)
  10345. {
  10346. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10347. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10348. }
  10349. else
  10350. {
  10351. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10352. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  10353. }
  10354. if(json_object_object_get(data, "qrCodeText") != NULL)
  10355. {
  10356. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10357. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10358. }
  10359. }
  10360. }
  10361. }
  10362. else
  10363. {
  10364. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10365. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10366. }
  10367. }
  10368. else
  10369. {
  10370. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10371. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10372. }
  10373. json_object_put(data);
  10374. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10375. json_object_put(response);
  10376. }
  10377. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  10378. {
  10379. json_object *data;
  10380. data = json_tokener_parse(tempdata);
  10381. if(!is_error(data))
  10382. {
  10383. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10384. if(json_object_object_get(data, "Content_Type") != NULL)
  10385. {
  10386. 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))
  10387. {
  10388. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10389. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10390. {
  10391. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10392. }
  10393. }
  10394. else
  10395. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10396. }
  10397. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10398. }
  10399. else
  10400. {
  10401. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10402. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10403. }
  10404. json_object_put(data);
  10405. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10406. json_object_put(response);
  10407. }
  10408. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  10409. {
  10410. json_object *data;
  10411. data = json_tokener_parse(tempdata);
  10412. if(!is_error(data))
  10413. {
  10414. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10415. if(json_object_object_get(data, "ConnectorId") != NULL)
  10416. {
  10417. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  10418. }
  10419. if(json_object_object_get(data, "SerialNo") != NULL)
  10420. {
  10421. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  10422. }
  10423. if(json_object_object_get(data, "Page_Index") != NULL)
  10424. {
  10425. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10426. }
  10427. if(json_object_object_get(data, "Duration") != NULL)
  10428. {
  10429. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10430. }
  10431. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  10432. }
  10433. else
  10434. {
  10435. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10436. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10437. }
  10438. json_object_put(data);
  10439. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10440. json_object_put(response);
  10441. }
  10442. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  10443. {
  10444. json_object *data;
  10445. data = json_tokener_parse(tempdata);
  10446. if(!is_error(data))
  10447. {
  10448. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10449. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10450. {
  10451. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10452. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10453. else
  10454. {
  10455. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10456. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10457. }
  10458. }
  10459. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10460. {
  10461. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10462. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10463. else
  10464. {
  10465. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10466. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10467. }
  10468. }
  10469. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  10470. {
  10471. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  10472. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  10473. else
  10474. {
  10475. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10476. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10477. }
  10478. }
  10479. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  10480. {
  10481. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  10482. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  10483. else
  10484. {
  10485. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10486. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10487. }
  10488. }
  10489. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10490. {
  10491. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10492. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10493. else
  10494. {
  10495. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10496. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10497. }
  10498. }
  10499. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10500. {
  10501. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10502. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10503. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10504. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10505. else
  10506. {
  10507. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10508. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10509. }
  10510. }
  10511. if(json_object_object_get(data, "isAuthentication") != NULL)
  10512. {
  10513. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10514. {
  10515. case 0:
  10516. case 1:
  10517. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10518. break;
  10519. default:
  10520. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10521. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10522. break;
  10523. }
  10524. }
  10525. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10526. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10527. }
  10528. else
  10529. {
  10530. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10531. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10532. }
  10533. json_object_put(data);
  10534. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10535. json_object_put(response);
  10536. }
  10537. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10538. {
  10539. json_object *data;
  10540. data = json_tokener_parse(tempdata);
  10541. if(!is_error(data))
  10542. {
  10543. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10544. {
  10545. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10546. {
  10547. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10548. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10549. }
  10550. else
  10551. {
  10552. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10553. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10554. }
  10555. }
  10556. else
  10557. {
  10558. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10559. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10560. }
  10561. }
  10562. else
  10563. {
  10564. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10565. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10566. }
  10567. json_object_put(data);
  10568. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10569. json_object_put(response);
  10570. }
  10571. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10572. {
  10573. json_object *data;
  10574. data = json_tokener_parse(tempdata);
  10575. if(!is_error(data))
  10576. {
  10577. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10578. if(json_object_object_get(data, "stationName") != NULL)
  10579. {
  10580. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10581. }
  10582. else
  10583. {
  10584. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10585. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10586. }
  10587. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10588. {
  10589. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10590. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10591. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10592. }
  10593. }
  10594. else
  10595. {
  10596. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10597. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10598. }
  10599. json_object_put(data);
  10600. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10601. json_object_put(response);
  10602. }
  10603. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10604. {
  10605. json_object *data;
  10606. data = json_tokener_parse(tempdata);
  10607. if(!is_error(data))
  10608. {
  10609. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10610. if(json_object_object_get(data, "weatherId") != NULL)
  10611. {
  10612. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10613. }
  10614. else
  10615. {
  10616. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10617. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10618. }
  10619. if(json_object_object_get(data, "Temperature") != NULL)
  10620. {
  10621. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10622. }
  10623. else
  10624. {
  10625. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10626. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10627. }
  10628. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10629. {
  10630. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10631. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10632. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10633. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10634. );
  10635. }
  10636. }
  10637. else
  10638. {
  10639. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10640. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10641. }
  10642. json_object_put(data);
  10643. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10644. json_object_put(response);
  10645. }
  10646. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10647. {
  10648. json_object *data;
  10649. data = json_tokener_parse(tempdata);
  10650. if(!is_error(data))
  10651. {
  10652. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10653. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10654. {
  10655. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10656. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  10657. }
  10658. else
  10659. {
  10660. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10661. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  10662. }
  10663. }
  10664. else
  10665. {
  10666. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10667. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10668. }
  10669. json_object_put(data);
  10670. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10671. json_object_put(response);
  10672. }
  10673. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10674. {
  10675. json_object *data;
  10676. data = json_tokener_parse(tempdata);
  10677. if(!is_error(data))
  10678. {
  10679. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10680. {
  10681. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10682. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10683. if(gun_index < gunTotalNumber)
  10684. {
  10685. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10686. {
  10687. json_object *responsedata = json_object_new_object();
  10688. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10689. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10690. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10691. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10692. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10693. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10694. }
  10695. else
  10696. {
  10697. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10698. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10699. }
  10700. }
  10701. else
  10702. {
  10703. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10704. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10705. }
  10706. }
  10707. else
  10708. {
  10709. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10710. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10711. }
  10712. }
  10713. else
  10714. {
  10715. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10716. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10717. }
  10718. json_object_put(data);
  10719. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10720. json_object_put(response);
  10721. }
  10722. // Support ISO-15118 related message
  10723. else if(strstr(tempmessageId, "TriggerMessage") != NULL)
  10724. {
  10725. char cmdBuf[1024]={0};
  10726. 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);
  10727. system(cmdBuf);
  10728. ShmOCPP16Data->v2g_extend.SignCertificateReq = 1;
  10729. json_object *responsedata = json_object_new_object();
  10730. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10731. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10732. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10733. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10734. json_object_put(response);
  10735. }
  10736. else if(strstr(tempmessageId, "CertificateSigned") != NULL)
  10737. {
  10738. json_object *data;
  10739. data = json_tokener_parse(tempdata);
  10740. if(!is_error(data))
  10741. {
  10742. FILE *fp = fopen(CERTIFICATE_V2G, "w");
  10743. fprintf(fp, "%s", json_object_get_string(json_object_object_get(data, "certificateChain")));
  10744. fclose(fp);
  10745. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10746. json_object *responsedata = json_object_new_object();
  10747. if(certVerify(PRIVATE_KEY_V2G, CERTIFICATE_V2G) == PASS)
  10748. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10749. else
  10750. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10751. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10752. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10753. }
  10754. else
  10755. {
  10756. json_object *responsedata = json_object_new_object();
  10757. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10758. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10759. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10760. }
  10761. json_object_put(data);
  10762. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10763. json_object_put(response);
  10764. }
  10765. else if(strstr(tempmessageId, "DeleteCertificate") != NULL)
  10766. {
  10767. json_object *data;
  10768. data = json_tokener_parse(tempdata);
  10769. DEBUG_INFO("DeleteCertificate processing...\n");
  10770. if(!is_error(data))
  10771. {
  10772. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm") != NULL)
  10773. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm")));
  10774. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash") != NULL)
  10775. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash")));
  10776. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash") != NULL)
  10777. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash")));
  10778. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber") != NULL)
  10779. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber")));
  10780. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm);
  10781. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash);
  10782. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash);
  10783. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber);
  10784. char temp[256] = {0};
  10785. char compareData[256] = {0};
  10786. int isMatch = TRUE;
  10787. // Check certV2G
  10788. if(access(CERTIFICATE_V2G,F_OK) != -1)
  10789. {
  10790. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_SerialNumber, compareData);
  10791. if(strcmp(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber) != 0)
  10792. isMatch = FALSE;
  10793. if(isMatch == TRUE)
  10794. {
  10795. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerNameHash, compareData);
  10796. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  10797. isMatch = FALSE;
  10798. }
  10799. if(isMatch == TRUE)
  10800. {
  10801. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerKeyHash, compareData);
  10802. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  10803. isMatch = FALSE;
  10804. }
  10805. if(isMatch == TRUE)
  10806. {
  10807. sprintf(temp, "rm -f %s", CERTIFICATE_V2G);
  10808. system(temp);
  10809. json_object *responsedata = json_object_new_object();
  10810. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10811. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10812. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10813. }
  10814. else
  10815. {
  10816. json_object *responsedata = json_object_new_object();
  10817. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10818. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10819. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10820. }
  10821. }
  10822. else
  10823. {
  10824. json_object *responsedata = json_object_new_object();
  10825. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10826. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10827. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10828. }
  10829. }
  10830. else
  10831. {
  10832. json_object *responsedata = json_object_new_object();
  10833. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10834. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10835. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10836. }
  10837. json_object_put(data);
  10838. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10839. json_object_put(response);
  10840. }
  10841. else if(strstr(tempmessageId, "GetInstalledCertificateIds") != NULL)
  10842. {
  10843. json_object *data;
  10844. data = json_tokener_parse(tempdata);
  10845. if(!is_error(data))
  10846. {
  10847. /*
  10848. * TODO:
  10849. * 1. Query certificate to response
  10850. */
  10851. json_object *responsedata = json_object_new_object();
  10852. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10853. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10854. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10855. }
  10856. else
  10857. {
  10858. json_object *responsedata = json_object_new_object();
  10859. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10860. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10861. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10862. }
  10863. json_object_put(data);
  10864. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10865. json_object_put(response);
  10866. }
  10867. else if(strstr(tempmessageId, "InstallCertificate") != NULL)
  10868. {
  10869. json_object *data;
  10870. data = json_tokener_parse(tempdata);
  10871. if(!is_error(data))
  10872. {
  10873. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  10874. if(json_object_object_get(data, "certificateType") != NULL)
  10875. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(data, "certificateType")));
  10876. if(json_object_object_get(data, "certificate") != NULL)
  10877. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(data, "certificate")));
  10878. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType);
  10879. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10880. char temp[1024];
  10881. FILE *fp = fopen(tempCert, "w");
  10882. fprintf(fp, "%s", ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10883. fclose(fp);
  10884. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  10885. char strExpDate[30];
  10886. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  10887. fp = popen(temp, "r");
  10888. if(fp)
  10889. {
  10890. while(fgets(temp, sizeof(temp), fp) != NULL)
  10891. {
  10892. if(strstr(temp, "notAfter=") != NULL)
  10893. {
  10894. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  10895. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  10896. break;
  10897. }
  10898. }
  10899. }
  10900. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  10901. struct tm tmExpDate;
  10902. struct timeb tbExpDate;
  10903. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  10904. tbExpDate.time = mktime(&tmExpDate);
  10905. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  10906. {
  10907. DEBUG_INFO("The enddate is already expired...\n");
  10908. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Rejected");
  10909. }
  10910. else
  10911. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted");
  10912. if(strcmp((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted") == 0)
  10913. {
  10914. if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "V2GRootCertificate") != NULL)
  10915. {
  10916. if(access(ROOTCA_V2G,F_OK) != -1)
  10917. {
  10918. DEBUG_INFO("Existed V2GRootCertificate is found. Replacing...\n");
  10919. rename(ROOTCA_V2G, "/Storage/OCPP/rootCaV2g_fallback.pem");
  10920. rename(tempCert, ROOTCA_V2G);
  10921. }
  10922. else
  10923. {
  10924. DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
  10925. rename(tempCert, ROOTCA_V2G);
  10926. }
  10927. json_object *responsedata = json_object_new_object();
  10928. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10929. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10930. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10931. }
  10932. else if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "MORootCertificate") != NULL)
  10933. {
  10934. if(access(ROOTCA_MO,F_OK) != -1)
  10935. {
  10936. DEBUG_INFO("Existed MORootCertificate is found. Replacing...\n");
  10937. rename(ROOTCA_MO, "/Storage/OCPP/rootCaMo_fallback.pem");
  10938. rename(tempCert, ROOTCA_MO);
  10939. }
  10940. else
  10941. {
  10942. DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
  10943. rename(tempCert, ROOTCA_MO);
  10944. }
  10945. json_object *responsedata = json_object_new_object();
  10946. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10947. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10948. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10949. }
  10950. else
  10951. {
  10952. json_object *responsedata = json_object_new_object();
  10953. json_object_object_add(responsedata, "status", json_object_new_string("Failed"));
  10954. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10955. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10956. }
  10957. }
  10958. else
  10959. {
  10960. json_object *responsedata = json_object_new_object();
  10961. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10962. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10963. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10964. }
  10965. }
  10966. else
  10967. {
  10968. json_object *responsedata = json_object_new_object();
  10969. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10970. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10971. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10972. }
  10973. json_object_put(data);
  10974. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10975. json_object_put(response);
  10976. }
  10977. else
  10978. {
  10979. // Can not find valid message id
  10980. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10981. }
  10982. }
  10983. else
  10984. {
  10985. // Payload is null
  10986. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10987. }
  10988. LWS_Send(message);
  10989. return result;
  10990. }
  10991. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10992. {
  10993. mtrace();
  10994. int result = FAIL;
  10995. int connectorIdInt, durationInt;
  10996. char chargingRateUnitStr[4]={0};
  10997. char comfirmstr[20];
  10998. int confirmPeriods = 0;
  10999. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  11000. json_object *GetCompositeSchedule;
  11001. GetCompositeSchedule = json_tokener_parse(payload);
  11002. if(!is_error(GetCompositeSchedule))
  11003. {
  11004. // Required data
  11005. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  11006. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  11007. else
  11008. connectorIdInt = -1;
  11009. if(json_object_object_get(GetCompositeSchedule, "duration"))
  11010. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  11011. else
  11012. durationInt = 86400;
  11013. // Optional data
  11014. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  11015. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  11016. }
  11017. json_object_put(GetCompositeSchedule);
  11018. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  11019. if((connectorIdInt == 0) ||
  11020. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  11021. {
  11022. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  11023. struct StructChargingProfile tmpProfile[1];
  11024. if(strstr(chargingRateUnitStr, "W") != NULL)
  11025. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  11026. else
  11027. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  11028. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  11029. {
  11030. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  11031. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  11032. }
  11033. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  11034. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  11035. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  11036. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  11037. {
  11038. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  11039. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  11040. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  11041. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  11042. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  11043. {
  11044. confirmPeriods = idx;
  11045. break;
  11046. }
  11047. }
  11048. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  11049. {
  11050. confirmPeriods += 1;
  11051. }
  11052. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  11053. }
  11054. else
  11055. {
  11056. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  11057. }
  11058. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  11059. return result;
  11060. }
  11061. int handleGetConfigurationRequest(char *uuid, char *payload)
  11062. {
  11063. mtrace();
  11064. int result = FAIL;
  11065. int MaxKeySupported = 0;
  11066. int n_keys = 0;
  11067. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  11068. DEBUG_INFO("handleGetConfigurationRequest...\n");
  11069. json_object *GetConfiguration;
  11070. GetConfiguration = json_tokener_parse(payload);
  11071. if(!is_error(GetConfiguration))
  11072. {
  11073. // Optional data
  11074. if(json_object_object_get(GetConfiguration, "key") != NULL)
  11075. {
  11076. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  11077. {
  11078. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  11079. n_keys = idx + 1;
  11080. }
  11081. }
  11082. }
  11083. json_object_put(GetConfiguration);
  11084. UnknownKeynum = 0;
  11085. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  11086. MaxKeySupported = GetConfigurationMaxKeysNUM;
  11087. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  11088. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  11089. if(n_keys != 0)
  11090. {
  11091. for(int i=0;i<n_keys;i++)
  11092. {
  11093. getKeyValue(requestKey[i]);
  11094. }
  11095. }
  11096. else
  11097. {
  11098. DEBUG_INFO("There is no key in Message, get all configuration\n");
  11099. getKeyValue("");
  11100. }
  11101. processUnkownKey();
  11102. sendGetConfigurationConfirmation(uuid);
  11103. return result;
  11104. }
  11105. static char fnamePlusPath[100]={0};
  11106. static char fnamePWithNoPath[60]={0};
  11107. void checkUploadLog(void)
  11108. {
  11109. FILE *fp;
  11110. /* Open the command for reading. */
  11111. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  11112. if (fp == NULL) {
  11113. DEBUG_WARN("Failed to run command\n" );
  11114. exit(1);
  11115. }
  11116. int ftppathlen = 0;
  11117. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  11118. int i = 0;
  11119. /* Read the output a line at a time - output it. */
  11120. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  11121. if(i==0)
  11122. {
  11123. ftppathlen = strlen(fnamePlusPath);
  11124. DEBUG_INFO("%s\n", fnamePlusPath);
  11125. fnamePlusPath[ftppathlen]='\0';
  11126. break;
  11127. }
  11128. i= i+1;
  11129. }
  11130. /* close */
  11131. pclose(fp);
  11132. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  11133. {
  11134. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  11135. {
  11136. fnamePlusPath[k]='\0';
  11137. }
  11138. }
  11139. i=1;
  11140. //char fname[60]={0};
  11141. while(i < ftppathlen)
  11142. {
  11143. int len=ftppathlen-i;
  11144. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  11145. {
  11146. DEBUG_INFO("compare '/' all right\n");
  11147. break;
  11148. }
  11149. i=i+1;
  11150. }
  11151. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  11152. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  11153. fnamePWithNoPath[i+1] = '\0';
  11154. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  11155. {
  11156. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  11157. {
  11158. fnamePWithNoPath[j]='\0';
  11159. }
  11160. }
  11161. FILE* fp1 = fopen(fnamePlusPath, "r");
  11162. if (fp1)
  11163. {
  11164. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  11165. // file exists
  11166. fclose(fp1);
  11167. }
  11168. else
  11169. {
  11170. // file doesn't exist
  11171. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  11172. }
  11173. }
  11174. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  11175. {
  11176. mtrace();
  11177. int result = FAIL;
  11178. time_t CurrentTime;
  11179. struct tm *tm;
  11180. pthread_t th_Status;
  11181. CurrentTime = time(NULL);
  11182. tm = localtime(&CurrentTime);
  11183. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  11184. 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);
  11185. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11186. if(!interLock.isGetDiagnosticGoing)
  11187. {
  11188. interLock.isGetDiagnosticGoing = 1;
  11189. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, payload);
  11190. sleep(1);
  11191. }
  11192. else
  11193. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  11194. return result;
  11195. }
  11196. void* GetDiagnosticsProcess(void* data)
  11197. {
  11198. pthread_detach(pthread_self());
  11199. mtrace();
  11200. int retriesInt=0, retryIntervalInt=0;
  11201. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  11202. 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};
  11203. int port=0;
  11204. int isSuccess = FALSE;
  11205. char cmdBuf[2048];
  11206. struct tm *tmNow;
  11207. time_t CurrentTime;
  11208. struct tm tmStart;
  11209. struct tm tmStop;
  11210. CurrentTime = time(NULL);
  11211. tmNow=localtime(&CurrentTime);
  11212. uint16_t targetYear, targetMonth;
  11213. json_object *GetDiagnostics;
  11214. DEBUG_INFO("GetDiagnosticsProcess...\n");
  11215. GetDiagnostics = json_tokener_parse(data);
  11216. if(!is_error(GetDiagnostics))
  11217. {
  11218. // Required data
  11219. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  11220. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  11221. // Optional data
  11222. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  11223. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  11224. else
  11225. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  11226. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  11227. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  11228. else
  11229. retryIntervalInt = 30;
  11230. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  11231. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  11232. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  11233. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  11234. }
  11235. json_object_put(GetDiagnostics);
  11236. // Pack log to compress file
  11237. 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) &&
  11238. (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))
  11239. {
  11240. // Pack system log
  11241. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11242. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  11243. targetYear = tmStart.tm_year;
  11244. targetMonth = tmStart.tm_mon;
  11245. do
  11246. {
  11247. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11248. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  11249. if(targetMonth+1>=13)
  11250. {
  11251. targetYear += 1;
  11252. targetMonth = 1;
  11253. }
  11254. else
  11255. {
  11256. targetMonth += 1;
  11257. }
  11258. }while((targetYear < (tmNow->tm_year+1900)) ||
  11259. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11260. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  11261. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  11262. system(cmdBuf);
  11263. // Pack charging & event log
  11264. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11265. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  11266. targetYear = tmStart.tm_year;
  11267. targetMonth = tmStart.tm_mon;
  11268. do
  11269. {
  11270. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11271. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  11272. if(targetMonth+1>=13)
  11273. {
  11274. targetYear += 1;
  11275. targetMonth = 1;
  11276. }
  11277. else
  11278. {
  11279. targetMonth += 1;
  11280. }
  11281. }while((targetYear < (tmNow->tm_year+1900)) ||
  11282. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11283. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  11284. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  11285. system(cmdBuf);
  11286. // Combine log file
  11287. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  11288. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  11289. }
  11290. else
  11291. {
  11292. system("exec /root/logPackTools 'log' 6");
  11293. }
  11294. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11295. system(cmdBuf);
  11296. checkUploadLog();
  11297. //****************location*******************/
  11298. if(strcmp(locationstr,"")==0)
  11299. {
  11300. DEBUG_INFO("location is <Empty>!\n");
  11301. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11302. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11303. goto end;
  11304. }
  11305. memset(protocol, 0, ARRAY_SIZE(protocol));
  11306. memset(user, 0, ARRAY_SIZE(user) );
  11307. memset(password, 0, ARRAY_SIZE(password));
  11308. memset(host, 0, ARRAY_SIZE(host));
  11309. memset(path, 0, ARRAY_SIZE(path));
  11310. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11311. memset(host1, 0, ARRAY_SIZE(host1));
  11312. memset(path1, 0, ARRAY_SIZE(path1));
  11313. /*location: ftp://user:password@host:port/path*/
  11314. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  11315. if((access(fnamePlusPath,F_OK))!=-1)
  11316. {
  11317. DEBUG_INFO("fnamePlusPath exist.\n");
  11318. }
  11319. else
  11320. {
  11321. DEBUG_INFO("fnamePlusPath not exist!\n");
  11322. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11323. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11324. goto end;
  11325. }
  11326. if(strchr(locationstr,'@')==NULL)
  11327. {
  11328. sscanf(locationstr,
  11329. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11330. protocol, host, &port, path);
  11331. strcpy(user,"anonymous");
  11332. strcpy(password,"");
  11333. }
  11334. else
  11335. {
  11336. //DEBUG_INFO("pch=%s\n", pch);
  11337. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11338. protocol, user, password, host, &port, path);
  11339. }
  11340. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  11341. {
  11342. DEBUG_INFO("protocol is not ftp/http ! \n");
  11343. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11344. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11345. goto end;
  11346. }
  11347. if(strncmp(locationstr,"http", 4) == 0)
  11348. {
  11349. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11350. sprintf(ftppath,"/%s", path);
  11351. do
  11352. {
  11353. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11354. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11355. sleep(3);
  11356. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  11357. if(!isSuccess)
  11358. {
  11359. DEBUG_INFO("Diagnostics fail.\n");
  11360. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11361. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11362. sleep(retryIntervalInt);
  11363. }
  11364. else
  11365. {
  11366. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11367. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11368. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11369. }
  11370. retriesInt--;
  11371. }while((isSuccess == 0)&&(retriesInt >= 0));
  11372. }
  11373. else
  11374. {
  11375. sscanf(host,"%[^/]%s",host1, path1);
  11376. if(strlen(path) > 0)
  11377. sprintf(ftppath,"/%s", path);
  11378. else
  11379. sprintf(ftppath,"/%s", path1);
  11380. int ftppathlen=strlen(ftppath);
  11381. int i=1;
  11382. char filenametemp[50];
  11383. while(i < ftppathlen)
  11384. {
  11385. int len=ftppathlen-i;
  11386. if(ftppath[len]== 47) // '/' ascll code: 47
  11387. {
  11388. DEBUG_INFO("find '/' all right\n");
  11389. break;
  11390. }
  11391. i=i+1;
  11392. }
  11393. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11394. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11395. filenametemp[i+1] = 0;
  11396. if(port == 0)
  11397. port = 21;
  11398. do
  11399. {
  11400. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11401. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11402. sleep(3);
  11403. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  11404. if(!isSuccess)
  11405. {
  11406. DEBUG_INFO("Diagnostics fail.\n");
  11407. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11408. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11409. sleep(retryIntervalInt);
  11410. }
  11411. else
  11412. {
  11413. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11414. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11415. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11416. }
  11417. retriesInt--;
  11418. }while((!isSuccess)&&(retriesInt >= 0));
  11419. }
  11420. end:
  11421. system("rm -f /mnt/*");
  11422. sleep(5);
  11423. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11424. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11425. interLock.isGetDiagnosticGoing = 0;
  11426. pthread_exit(NULL);
  11427. }
  11428. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  11429. {
  11430. mtrace();
  11431. int result = FAIL;
  11432. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  11433. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  11434. {
  11435. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  11436. locallistVersion = -1;
  11437. }
  11438. else
  11439. {
  11440. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  11441. locallistVersion = 0;
  11442. OCPP_getListVerion();
  11443. }
  11444. //from db.OCPP_getListVerion
  11445. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  11446. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  11447. sendGetLocalListVersionConfirmation(uuid,"");
  11448. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  11449. return result;
  11450. }
  11451. int handleRemoteStartRequest(char *uuid, char *payload)
  11452. {
  11453. mtrace();
  11454. int result = PASS;
  11455. int connectorIdInt=-1;
  11456. int tempIndex = 0;
  11457. char comfirmstr[20]={0};
  11458. char cmdBuf[512];
  11459. json_object *RemoteStartTransaction;
  11460. FILE *fp;
  11461. DEBUG_INFO("handleRemoteStartRequest ...\n");
  11462. if(server_pending == TRUE)
  11463. {
  11464. result = FAIL;
  11465. }
  11466. RemoteStartTransaction = json_tokener_parse(payload);
  11467. if(!is_error(RemoteStartTransaction))
  11468. {
  11469. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  11470. {
  11471. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  11472. }
  11473. else
  11474. {
  11475. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11476. {
  11477. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  11478. {
  11479. connectorIdInt = (gun_index+1);
  11480. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  11481. break;
  11482. }
  11483. }
  11484. }
  11485. if(connectorIdInt == 0)
  11486. {
  11487. DEBUG_WARN("Connector id shall not equal 0.\n");
  11488. result = FAIL;
  11489. }
  11490. else if(json_object_object_get(RemoteStartTransaction, "idTag") == NULL)
  11491. {
  11492. DEBUG_WARN("idTag should not be NULL.\n");
  11493. result = FAIL;
  11494. }
  11495. else if(connectorIdInt == -1)
  11496. {
  11497. DEBUG_INFO("Connector id does not specific.\n");
  11498. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11499. {
  11500. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11501. // Required data
  11502. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11503. // Optional data
  11504. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11505. {
  11506. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11507. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11508. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11509. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11510. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11511. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11512. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11513. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11514. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11515. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11516. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11517. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11518. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11519. {
  11520. 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")));
  11521. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11522. 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"));
  11523. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11524. 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"));
  11525. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11526. 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")));
  11527. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11528. {
  11529. 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++)
  11530. {
  11531. 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"));
  11532. 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"));
  11533. 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)
  11534. 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"));
  11535. }
  11536. }
  11537. }
  11538. }
  11539. else
  11540. {
  11541. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11542. }
  11543. }
  11544. }
  11545. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11546. {
  11547. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11548. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11549. // Required data
  11550. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11551. // Optional data
  11552. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11553. {
  11554. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11555. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11556. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11557. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11558. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11559. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11560. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11561. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11562. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11563. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11564. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11565. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11566. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11567. {
  11568. 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")));
  11569. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11570. 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"));
  11571. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11572. 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"));
  11573. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11574. 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")));
  11575. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11576. {
  11577. 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++)
  11578. {
  11579. 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"));
  11580. 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"));
  11581. 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)
  11582. 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"));
  11583. }
  11584. }
  11585. }
  11586. }
  11587. else
  11588. {
  11589. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11590. }
  11591. }
  11592. else
  11593. {
  11594. DEBUG_WARN("Connector id is over maximun value.\n");
  11595. result = FAIL;
  11596. }
  11597. }
  11598. if(result == PASS)
  11599. {
  11600. if(connectorIdInt > 0)
  11601. {
  11602. //check Transaction active
  11603. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11604. {
  11605. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11606. {
  11607. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11608. }
  11609. else
  11610. {
  11611. tempIndex = connectorIdInt -1;
  11612. }
  11613. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11614. {
  11615. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11616. {
  11617. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11618. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11619. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11620. {
  11621. //Reserved
  11622. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11623. }
  11624. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11625. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11626. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11627. {
  11628. //Reserved
  11629. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11630. {
  11631. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11632. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11633. goto end;
  11634. }
  11635. }
  11636. else
  11637. {
  11638. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11639. {
  11640. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11641. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11642. goto end;
  11643. }
  11644. }//END FOR ELSE
  11645. }
  11646. }// END FOR CHAdeMO_QUANTITY
  11647. }
  11648. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11649. {
  11650. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11651. {
  11652. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11653. }
  11654. else
  11655. {
  11656. tempIndex = connectorIdInt -1;
  11657. }
  11658. for (int index = 0; index < CCS_QUANTITY; index++)
  11659. {
  11660. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11661. {
  11662. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11663. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11664. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11665. {
  11666. //Reserved
  11667. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11668. }
  11669. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11670. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11671. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11672. {
  11673. //Reserved
  11674. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11675. {
  11676. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11677. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11678. goto end;
  11679. }
  11680. }
  11681. else
  11682. {
  11683. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11684. {
  11685. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11686. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11687. goto end;
  11688. }
  11689. }// END FOR ELSE
  11690. }
  11691. }// END FOR CCS_QUANTITY
  11692. }
  11693. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11694. {
  11695. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11696. {
  11697. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11698. }
  11699. else
  11700. {
  11701. tempIndex = connectorIdInt -1;
  11702. }
  11703. for (int index = 0; index < GB_QUANTITY; index++)
  11704. {
  11705. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11706. {
  11707. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11708. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11709. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11710. {
  11711. //Reserved
  11712. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11713. }
  11714. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11715. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11716. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11717. {
  11718. //Reserved
  11719. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11720. {
  11721. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11722. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11723. goto end;
  11724. }
  11725. }
  11726. else
  11727. {
  11728. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11729. {
  11730. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11731. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11732. goto end;
  11733. }
  11734. }// END FOR ELSE
  11735. }
  11736. } // END FOR GB_QUANTITY
  11737. }
  11738. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11739. {
  11740. tempIndex = connectorIdInt -1;
  11741. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11742. {
  11743. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11744. {
  11745. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11746. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11747. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11748. {
  11749. //Reserved
  11750. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11751. }
  11752. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11753. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11754. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11755. {
  11756. //Reserved
  11757. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11758. {
  11759. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11760. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11761. goto end;
  11762. }
  11763. }
  11764. else
  11765. {
  11766. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11767. {
  11768. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11769. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11770. goto end;
  11771. }
  11772. }// END FOR ELSE
  11773. }
  11774. } // END FOR GB_QUANTITY
  11775. }
  11776. else
  11777. {
  11778. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11779. {
  11780. tempIndex = 2;
  11781. }
  11782. else
  11783. {
  11784. tempIndex = connectorIdInt -1;
  11785. }
  11786. for (int index = 0; index < AC_QUANTITY; index++)
  11787. {
  11788. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11789. {
  11790. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11791. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11792. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11793. {
  11794. //Reserved
  11795. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11796. }
  11797. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11798. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11799. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11800. {
  11801. //Reserved
  11802. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11803. {
  11804. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11805. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11806. goto end;
  11807. }
  11808. }
  11809. else
  11810. {
  11811. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11812. {
  11813. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11814. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11815. goto end;
  11816. }
  11817. }//END FOR ELSE
  11818. }
  11819. }// END FOR AC_QUANTITY
  11820. }
  11821. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11822. {
  11823. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11824. {
  11825. // Save profile to file
  11826. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11827. system(cmdBuf);
  11828. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11829. fp = fopen(cmdBuf, "w");
  11830. 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));
  11831. fclose(fp);
  11832. }
  11833. else
  11834. {
  11835. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11836. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11837. goto end;
  11838. }
  11839. }
  11840. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11841. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11842. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11843. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11844. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11845. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11846. }
  11847. else
  11848. {
  11849. uint8_t isHasIdleConnector = FALSE;
  11850. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11851. {
  11852. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11853. {
  11854. isHasIdleConnector = TRUE;
  11855. break;
  11856. }
  11857. }
  11858. if((isHasIdleConnector == TRUE) && !ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11859. {
  11860. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11861. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11862. {
  11863. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11864. {
  11865. // Save profile to file
  11866. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11867. system(cmdBuf);
  11868. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11869. fp = fopen(cmdBuf, "w");
  11870. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11871. fclose(fp);
  11872. refreshStartTimer(&clientTime.RemoteStartWait);
  11873. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11874. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11875. }
  11876. else
  11877. {
  11878. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11879. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11880. }
  11881. }
  11882. else
  11883. {
  11884. refreshStartTimer(&clientTime.RemoteStartWait);
  11885. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11886. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11887. }
  11888. }
  11889. else
  11890. {
  11891. DEBUG_INFO("There is not any connector is idle.\n");
  11892. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11893. }
  11894. }
  11895. }
  11896. else
  11897. {
  11898. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11899. }
  11900. end:
  11901. json_object_put(RemoteStartTransaction);
  11902. sendRemoteStartConfirmation(uuid, comfirmstr);
  11903. return result;
  11904. }
  11905. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11906. {
  11907. mtrace();
  11908. int result = FAIL;
  11909. int match = FALSE;
  11910. int GunNO = 0;
  11911. int tempIndex = 0;
  11912. int transactionIdInt=0;
  11913. int transactionIdIsNULL= TRUE;
  11914. char comfirmstr[20];
  11915. json_object *RemoteStopTransaction;
  11916. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11917. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11918. if(server_pending == TRUE)
  11919. {
  11920. return 0;
  11921. }
  11922. RemoteStopTransaction = json_tokener_parse(payload);
  11923. if(!is_error(RemoteStopTransaction))
  11924. {
  11925. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11926. {
  11927. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11928. transactionIdIsNULL = FALSE;
  11929. }
  11930. }
  11931. json_object_put(RemoteStopTransaction);
  11932. if(transactionIdIsNULL == FALSE)
  11933. {
  11934. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11935. {
  11936. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11937. {
  11938. //check Transaction active
  11939. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11940. {
  11941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11942. {
  11943. tempIndex = ((gun_index==2) ? 1: 0);
  11944. }
  11945. else
  11946. {
  11947. tempIndex = gun_index;
  11948. }
  11949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11950. {
  11951. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11952. {
  11953. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11954. {
  11955. match = TRUE;
  11956. GunNO = gun_index;
  11957. }
  11958. }
  11959. }// END FOR CHAdeMO_QUANTITY
  11960. }
  11961. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11962. {
  11963. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11964. {
  11965. tempIndex = ((gun_index==2) ? 1: 0);
  11966. }
  11967. else
  11968. {
  11969. tempIndex = gun_index;
  11970. }
  11971. for (int index = 0; index < CCS_QUANTITY; index++)
  11972. {
  11973. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11974. {
  11975. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11976. {
  11977. match = TRUE;
  11978. GunNO = gun_index;
  11979. }
  11980. }
  11981. }// END FOR CCS_QUANTITY
  11982. }
  11983. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11984. {
  11985. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11986. {
  11987. tempIndex = ((gun_index==2) ? 1: 0);
  11988. }
  11989. else
  11990. {
  11991. tempIndex = gun_index;
  11992. }
  11993. for (int index = 0; index < GB_QUANTITY; index++)
  11994. {
  11995. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11996. {
  11997. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11998. {
  11999. match = TRUE;
  12000. GunNO = gun_index;
  12001. }
  12002. }
  12003. }// END FOR GB_QUANTITY
  12004. }
  12005. else if(gunType[gun_index] == GUN_TYPE_DO)
  12006. {
  12007. tempIndex = gun_index;
  12008. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12009. {
  12010. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12011. {
  12012. 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
  12013. {
  12014. match = TRUE;
  12015. GunNO = gun_index;
  12016. }
  12017. }
  12018. }// END FOR GB_QUANTITY
  12019. }
  12020. else
  12021. {
  12022. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12023. {
  12024. tempIndex = 2;
  12025. }
  12026. else
  12027. {
  12028. tempIndex = gun_index;
  12029. }
  12030. for (int index = 0; index < AC_QUANTITY; index++)
  12031. {
  12032. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12033. {
  12034. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  12035. {
  12036. match = TRUE;
  12037. GunNO = gun_index;
  12038. }
  12039. }
  12040. }// END FOR CHAdeMO_QUANTITY
  12041. } // END FOR AC ELSE
  12042. }// CHECK IF ResponseTransactionId == transactionIdInt
  12043. }//END FOR
  12044. if( match == TRUE)
  12045. {
  12046. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  12047. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  12048. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  12049. }
  12050. else
  12051. {
  12052. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12053. }
  12054. }
  12055. else
  12056. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  12057. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  12058. return result;
  12059. }
  12060. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  12061. {
  12062. mtrace();
  12063. int result = FAIL;
  12064. int connectorIdInt=0, reservationIdInt=0;
  12065. int tempIndex = 0;
  12066. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  12067. char comfirmstr[20]={0};
  12068. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  12069. int c = 0;
  12070. char *loc;
  12071. //char *ptr;
  12072. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  12073. strcpy(sstrtemp, stringtrimspace(payload));
  12074. //***(1)connectorId ****/
  12075. c=0;
  12076. loc = strstr(sstrtemp, "connectorId");
  12077. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12078. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  12079. {
  12080. sstr[c] = loc[strlen("connectorId")+2+c];
  12081. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12082. c++;
  12083. }
  12084. sstr[c] = '\0';
  12085. connectorIdInt = atoi(sstr);
  12086. //***(2)expiryDate ****/
  12087. loc = strstr(sstrtemp, "expiryDate");
  12088. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12089. c = 0;
  12090. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  12091. {
  12092. sstr[c] = loc[3+strlen("expiryDate")+c];
  12093. c++;
  12094. }
  12095. sstr[c] = '\0';
  12096. strcpy(expiryDatestr, sstr);
  12097. //***(3)idTag ****/
  12098. loc = strstr(sstrtemp, "idTag");
  12099. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12100. c = 0;
  12101. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  12102. {
  12103. sstr[c] = loc[3+strlen("idTag")+c];
  12104. c++;
  12105. }
  12106. sstr[c] = '\0';
  12107. strcpy(idTagstr, sstr);
  12108. //***(4)parentIdTag ****/
  12109. loc = strstr(sstrtemp, "parentIdTag");
  12110. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12111. c = 0;
  12112. if(loc == NULL)
  12113. {
  12114. strcpy(parentIdTagstr, "");
  12115. }
  12116. else
  12117. {
  12118. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  12119. {
  12120. sstr[c] = loc[3+strlen("parentIdTag")+c];
  12121. c++;
  12122. }
  12123. sstr[c] = '\0';
  12124. strcpy(parentIdTagstr, sstr);
  12125. }
  12126. //***(5)reservationId ****/
  12127. c=0;
  12128. loc = strstr(sstrtemp, "reservationId");
  12129. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12130. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  12131. {
  12132. sstr[c] = loc[strlen("reservationId")+2+c];
  12133. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12134. c++;
  12135. }
  12136. sstr[c] = '\0';
  12137. reservationIdInt = atoi(sstr);
  12138. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12139. /*
  12140. enum SYSTEM_STATUS
  12141. {
  12142. SYS_MODE_BOOTING = 0,
  12143. SYS_MODE_IDLE = 1,
  12144. SYS_MODE_AUTHORIZING = 2,
  12145. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  12146. SYS_MODE_REASSIGN = 4,
  12147. SYS_MODE_PREPARING = 5,
  12148. SYS_MODE_PREPARE_FOR_EV = 6,
  12149. SYS_MODE_PREPARE_FOR_EVSE = 7,
  12150. SYS_MODE_CHARGING = 8,
  12151. SYS_MODE_TERMINATING = 9,
  12152. SYS_MODE_COMPLETE = 10,
  12153. SYS_MODE_ALARM = 11,
  12154. SYS_MODE_FAULT = 12,
  12155. SYS_MODE_RESERVATION = 13,
  12156. SYS_MODE_BOOKING = 14,
  12157. SYS_MODE_MAINTAIN = 15,
  12158. SYS_MODE_DEBUG = 16,
  12159. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  12160. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  12161. SYS_MODE_UPDATE = 19
  12162. };
  12163. */
  12164. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  12165. {
  12166. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12167. goto end;
  12168. }
  12169. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  12170. {
  12171. //check Transaction active
  12172. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  12173. {
  12174. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12175. {
  12176. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12177. }
  12178. else
  12179. {
  12180. tempIndex = connectorIdInt -1;
  12181. }
  12182. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12183. {
  12184. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12185. {
  12186. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12187. {
  12188. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12189. {
  12190. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12191. {
  12192. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  12193. {
  12194. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12195. }
  12196. else
  12197. {
  12198. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12199. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12200. }
  12201. }
  12202. 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'))
  12203. {
  12204. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12205. }
  12206. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12207. {
  12208. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12209. }
  12210. else
  12211. {
  12212. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12213. }
  12214. }
  12215. 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
  12216. {
  12217. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12218. }
  12219. }
  12220. else
  12221. {
  12222. //replace reservation
  12223. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12224. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12225. }
  12226. }
  12227. } // END FOR CHAdeMO_QUANTITY
  12228. }
  12229. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  12230. {
  12231. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12232. {
  12233. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12234. }
  12235. else
  12236. {
  12237. tempIndex = connectorIdInt -1;
  12238. }
  12239. for (int index = 0; index < CCS_QUANTITY; index++)
  12240. {
  12241. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12242. {
  12243. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12244. {
  12245. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12246. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12247. {
  12248. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12249. {
  12250. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  12251. {
  12252. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12253. }
  12254. else
  12255. {
  12256. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12257. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12258. }
  12259. }
  12260. 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'))
  12261. {
  12262. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12263. }
  12264. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  12265. {
  12266. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12267. }
  12268. else
  12269. {
  12270. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12271. }
  12272. }
  12273. 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
  12274. {
  12275. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12276. }
  12277. }
  12278. else
  12279. {
  12280. //replace reservation
  12281. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12282. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12283. }
  12284. }
  12285. } // END FOR CCS_QUANTITY
  12286. }
  12287. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  12288. {
  12289. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12290. {
  12291. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12292. }
  12293. else
  12294. {
  12295. tempIndex = connectorIdInt -1;
  12296. }
  12297. for (int index = 0; index < GB_QUANTITY; index++)
  12298. {
  12299. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12300. {
  12301. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12302. {
  12303. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12304. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12305. {
  12306. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12307. {
  12308. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  12309. {
  12310. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12311. }
  12312. else
  12313. {
  12314. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12315. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12316. }
  12317. }
  12318. 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'))
  12319. {
  12320. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12321. }
  12322. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12323. {
  12324. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12325. }
  12326. else
  12327. {
  12328. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12329. }
  12330. }
  12331. 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
  12332. {
  12333. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12334. }
  12335. }
  12336. else
  12337. {
  12338. //replace reservation
  12339. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12340. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12341. }
  12342. }
  12343. }// END FOR GB_QUANTITY
  12344. }
  12345. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  12346. {
  12347. tempIndex = connectorIdInt -1;
  12348. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12349. {
  12350. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12351. {
  12352. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  12353. {
  12354. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12355. 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
  12356. {
  12357. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12358. {
  12359. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  12360. {
  12361. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12362. }
  12363. else
  12364. {
  12365. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12366. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12367. }
  12368. }
  12369. 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'))
  12370. {
  12371. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12372. }
  12373. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12374. {
  12375. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12376. }
  12377. else
  12378. {
  12379. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12380. }
  12381. }
  12382. 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
  12383. {
  12384. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12385. }
  12386. }
  12387. else
  12388. {
  12389. //replace reservation
  12390. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12391. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12392. }
  12393. }
  12394. }// END FOR GB_QUANTITY
  12395. }
  12396. else
  12397. {
  12398. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12399. {
  12400. tempIndex = 2;
  12401. }
  12402. else
  12403. {
  12404. tempIndex = (connectorIdInt -1);
  12405. }
  12406. for (int index = 0; index < AC_QUANTITY; index++)
  12407. {
  12408. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12409. {
  12410. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12411. {
  12412. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12413. {
  12414. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12415. {
  12416. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  12417. {
  12418. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12419. }
  12420. else
  12421. {
  12422. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12423. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12424. }
  12425. }
  12426. 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'))
  12427. {
  12428. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12429. }
  12430. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12431. {
  12432. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12433. }
  12434. else
  12435. {
  12436. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12437. }
  12438. }
  12439. 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
  12440. {
  12441. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12442. }
  12443. }
  12444. else
  12445. {
  12446. //replace reservation
  12447. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12448. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12449. }
  12450. }
  12451. } // END FOR AC_QUANTITY
  12452. }
  12453. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12454. }
  12455. else if(connectorIdInt == 0)
  12456. {
  12457. //check Transaction active
  12458. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12459. {
  12460. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12461. {
  12462. 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'))
  12463. {
  12464. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12465. goto end;
  12466. }
  12467. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12468. {
  12469. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12470. goto end;
  12471. }
  12472. 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
  12473. {
  12474. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12475. goto end;
  12476. }
  12477. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12478. {
  12479. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12480. goto end;
  12481. }
  12482. }
  12483. }// END FOR CHAdeMO_QUANTITY
  12484. for (int index = 0; index < CCS_QUANTITY; index++)
  12485. {
  12486. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12487. {
  12488. 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'))
  12489. {
  12490. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12491. goto end;
  12492. }
  12493. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12494. {
  12495. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12496. goto end;
  12497. }
  12498. 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
  12499. {
  12500. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12501. goto end;
  12502. }
  12503. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12504. {
  12505. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12506. goto end;
  12507. }
  12508. }
  12509. } // END FOR CCS_QUANTITY
  12510. for (int index = 0; index < GB_QUANTITY; index++)
  12511. {
  12512. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12513. {
  12514. 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'))
  12515. {
  12516. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12517. goto end;
  12518. }
  12519. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12520. {
  12521. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12522. goto end;
  12523. }
  12524. 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
  12525. {
  12526. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12527. goto end;
  12528. }
  12529. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12530. {
  12531. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12532. goto end;
  12533. }
  12534. }
  12535. } // END FOR GB_QUANTITY
  12536. for (int index = 0; index < AC_QUANTITY; index++)
  12537. {
  12538. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12539. {
  12540. 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'))
  12541. {
  12542. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12543. goto end;
  12544. }
  12545. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12546. {
  12547. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12548. goto end;
  12549. }
  12550. 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
  12551. {
  12552. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12553. goto end;
  12554. }
  12555. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12556. {
  12557. 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))
  12558. {
  12559. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12560. goto end;
  12561. }
  12562. }
  12563. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12564. {
  12565. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12566. goto end;
  12567. }
  12568. }
  12569. }// END FOR AC_QUANTITY
  12570. //The connectorId is 0
  12571. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12572. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12573. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12574. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12575. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12576. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12577. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12578. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12579. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12580. result = TRUE;
  12581. return result;
  12582. }
  12583. else
  12584. {
  12585. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12586. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12587. }
  12588. if(strcmp(comfirmstr,"Accepted") == 0)
  12589. {
  12590. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12591. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12592. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12593. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12594. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12595. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12596. result = TRUE;
  12597. return result;
  12598. }
  12599. end:
  12600. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12601. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12602. return result;
  12603. }
  12604. int handleResetRequest(char *uuid, char *payload)
  12605. {
  12606. mtrace();
  12607. int result = FAIL;
  12608. char sstr[10]={0},sstrtemp[30]={ 0 };
  12609. char typestr[10]={0};
  12610. char comfirmstr[20]={0};
  12611. int c = 0;
  12612. char *loc;
  12613. DEBUG_INFO("handleResetRequest...\n");
  12614. strcpy(sstrtemp, stringtrimspace(payload));
  12615. loc = strstr(sstrtemp, "type");
  12616. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12617. c = 0;
  12618. while (loc[3+strlen("type")+c] != '\"')
  12619. {
  12620. sstr[c] = loc[3+strlen("type")+c];
  12621. c++;
  12622. }
  12623. sstr[c] = '\0';
  12624. strcpy(typestr,sstr);
  12625. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12626. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12627. {
  12628. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12629. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12630. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12631. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12632. }
  12633. else
  12634. {
  12635. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12636. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12637. result = PASS;
  12638. }
  12639. sendResetConfirmation(uuid, comfirmstr);
  12640. return result;
  12641. }
  12642. int handleSendLocalListRequest(char *uuid, char *payload)
  12643. {
  12644. mtrace();
  12645. int result = FAIL;
  12646. char comfirmstr[20];
  12647. int checkState_Faulted = FALSE;
  12648. json_object *SendLocalList;
  12649. DEBUG_INFO("handleSendLocalListRequest...\n");
  12650. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12651. {
  12652. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12653. goto end;
  12654. }
  12655. //check Charge Point state
  12656. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12657. {
  12658. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12659. {
  12660. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12661. }
  12662. }
  12663. for (int index = 0; index < CCS_QUANTITY; index++)
  12664. {
  12665. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12666. {
  12667. checkState_Faulted = TRUE; //OCPP Status
  12668. }
  12669. }
  12670. for (int index = 0; index < GB_QUANTITY; index++)
  12671. {
  12672. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12673. {
  12674. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12675. }
  12676. }
  12677. //check Charge Point state
  12678. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12679. {
  12680. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12681. {
  12682. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12683. }
  12684. }
  12685. //check Charge Point state
  12686. for (int index = 0; index < AC_QUANTITY; index++)
  12687. {
  12688. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12689. {
  12690. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12691. }
  12692. }
  12693. if(checkState_Faulted == TRUE)
  12694. {
  12695. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12696. goto end;
  12697. }
  12698. // Parsing payload
  12699. SendLocalList = json_tokener_parse(payload);
  12700. if(!is_error(SendLocalList))
  12701. {
  12702. // Required data
  12703. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12704. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12705. // Optional data
  12706. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12707. {
  12708. //Check UpdateType
  12709. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12710. {
  12711. //Local list full update
  12712. DEBUG_INFO("Local list full update.\n");
  12713. locallistVersion = 0;
  12714. OCPP_getListVerion();
  12715. if((ShmOCPP16Data->SendLocalList.ListVersion > 0) && (ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion))
  12716. {
  12717. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12718. goto end;
  12719. }
  12720. OCPP_cleanLocalList();
  12721. }
  12722. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12723. {
  12724. //Local list different update
  12725. DEBUG_INFO("Local list different update.\n");
  12726. locallistVersion = 0;
  12727. OCPP_getListVerion();
  12728. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12729. {
  12730. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12731. goto end;
  12732. }
  12733. }
  12734. else
  12735. {
  12736. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12737. goto end;
  12738. }
  12739. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  12740. {
  12741. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  12742. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12743. goto end;
  12744. }
  12745. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12746. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12747. {
  12748. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  12749. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12750. {
  12751. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  12752. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12753. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
  12754. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12755. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
  12756. }
  12757. // Add to db
  12758. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12759. {
  12760. //Local list full update
  12761. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12762. idx,
  12763. ShmOCPP16Data->SendLocalList.ListVersion,
  12764. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12765. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12766. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12767. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12768. // update list
  12769. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12770. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12771. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12772. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12773. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12774. }
  12775. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12776. {
  12777. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12778. idx,
  12779. ShmOCPP16Data->SendLocalList.ListVersion,
  12780. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12781. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12782. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12783. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12784. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12785. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12786. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12787. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12788. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12789. }
  12790. }
  12791. }
  12792. else
  12793. {
  12794. //Check UpdateType
  12795. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12796. {
  12797. //Local list full update
  12798. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12799. OCPP_cleanLocalList();
  12800. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12801. goto end;
  12802. }
  12803. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12804. {
  12805. //Local list different update
  12806. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12807. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12808. goto end;
  12809. }
  12810. }
  12811. result = PASS;
  12812. }
  12813. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12814. end:
  12815. json_object_put(SendLocalList);
  12816. sendSendLocalListConfirmation(uuid, comfirmstr);
  12817. return result;
  12818. }
  12819. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12820. {
  12821. mtrace();
  12822. int result = FAIL;
  12823. struct StructSetChargingProfile SetProfileReq = {0};
  12824. int tempchargingProfileIdInt;
  12825. int tempstackLevelInt;
  12826. int chargingSchedulePeriodCount = 0;
  12827. char comfirmstr[20]={0};
  12828. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12829. char rmFileCmd[128]={0};
  12830. int profileQuantity = 0;
  12831. int replaceableProfileCnt = 0;
  12832. json_object *SetChargingProfile;
  12833. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12834. SetChargingProfile = json_tokener_parse(payload);
  12835. if(!is_error(SetChargingProfile))
  12836. {
  12837. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12838. {
  12839. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12840. }
  12841. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12842. {
  12843. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12844. {
  12845. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12846. }
  12847. else
  12848. {
  12849. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12850. DEBUG_WARN("Cannot find chargingProfileId field.");
  12851. goto end;
  12852. }
  12853. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12854. {
  12855. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12856. }
  12857. else
  12858. {
  12859. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12860. DEBUG_WARN("Cannot find stackLevel field.");
  12861. goto end;
  12862. }
  12863. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12864. {
  12865. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12866. }
  12867. else
  12868. {
  12869. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12870. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12871. goto end;
  12872. }
  12873. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12874. {
  12875. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12876. }
  12877. else
  12878. {
  12879. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12880. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12881. goto end;
  12882. }
  12883. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12884. {
  12885. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12886. }
  12887. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12888. {
  12889. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12890. }
  12891. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12892. {
  12893. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12894. }
  12895. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12896. {
  12897. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12898. }
  12899. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12900. {
  12901. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12902. {
  12903. 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")));
  12904. }
  12905. else
  12906. {
  12907. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12908. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12909. goto end;
  12910. }
  12911. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12912. {
  12913. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12914. }
  12915. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12916. {
  12917. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12918. }
  12919. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12920. {
  12921. 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")));
  12922. }
  12923. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12924. {
  12925. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12926. if(chargingSchedulePeriodCount <= 10)
  12927. {
  12928. 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++)
  12929. {
  12930. 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)
  12931. {
  12932. 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"));
  12933. }
  12934. else
  12935. {
  12936. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12937. DEBUG_WARN("Cannot find startPeriod field.");
  12938. goto end;
  12939. }
  12940. 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)
  12941. {
  12942. 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"));
  12943. }
  12944. else
  12945. {
  12946. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12947. DEBUG_WARN("Cannot find limit field.");
  12948. goto end;
  12949. }
  12950. 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)
  12951. {
  12952. 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"));
  12953. }
  12954. }
  12955. }
  12956. }
  12957. else
  12958. {
  12959. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12960. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12961. goto end;
  12962. }
  12963. }
  12964. else
  12965. {
  12966. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12967. DEBUG_WARN("Cannot find chargingSchedule field.");
  12968. goto end;
  12969. }
  12970. }
  12971. }
  12972. // Profile periods quantity check
  12973. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12974. {
  12975. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12976. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12977. goto end;
  12978. }
  12979. // Check invalid limit
  12980. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12981. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12982. {
  12983. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12984. {
  12985. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12986. {
  12987. 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)))) ||
  12988. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12989. {
  12990. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12991. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12992. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12993. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12994. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12995. goto end;
  12996. }
  12997. }
  12998. }
  12999. else
  13000. {
  13001. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  13002. {
  13003. 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) ||
  13004. (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)))
  13005. {
  13006. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13007. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  13008. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  13009. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  13010. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  13011. goto end;
  13012. }
  13013. }
  13014. }
  13015. }
  13016. // Profile purpose info check
  13017. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13018. {
  13019. FILE *fp;
  13020. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  13021. if(SetProfileReq.ConnectorId != 0)
  13022. {
  13023. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13024. DEBUG_WARN("Profile connector id is not 0.\n");
  13025. goto end;
  13026. }
  13027. fp = fopen(ChargePointMaxProfile_JSON, "r");
  13028. if (!fp)
  13029. {
  13030. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  13031. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  13032. }
  13033. else
  13034. {
  13035. char *line = NULL;
  13036. size_t len = 0;
  13037. while(getline(&line, &len, fp) != -1)
  13038. {
  13039. json_object *obj = NULL;
  13040. obj = json_tokener_parse(line);
  13041. if(is_error(obj))
  13042. {
  13043. DEBUG_ERROR("Parse txProfile from file error.\n");
  13044. }
  13045. else
  13046. {
  13047. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13048. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13049. {
  13050. profileQuantity += 1;
  13051. }
  13052. else
  13053. replaceableProfileCnt += 1;
  13054. }
  13055. }
  13056. }
  13057. fclose(fp);
  13058. }
  13059. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13060. {
  13061. FILE *fp;
  13062. char filename[128]={0};
  13063. int tmpProfileQuantity;
  13064. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  13065. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13066. {
  13067. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13068. DEBUG_WARN("Profile connector id is over max gun number.\n");
  13069. goto end;
  13070. }
  13071. if(SetProfileReq.ConnectorId == 0)
  13072. {
  13073. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  13074. {
  13075. tmpProfileQuantity = 0;
  13076. memset(filename, 0, ARRAY_SIZE(filename));
  13077. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13078. fp = fopen(filename, "r");
  13079. if (!fp)
  13080. {
  13081. DEBUG_INFO("%s does not create.\n", filename);
  13082. fp = fopen(filename, "w+");
  13083. }
  13084. else
  13085. {
  13086. char *line = NULL;
  13087. size_t len = 0;
  13088. while(getline(&line, &len, fp) != -1)
  13089. {
  13090. json_object *obj = NULL;
  13091. obj = json_tokener_parse(line);
  13092. if(is_error(obj))
  13093. {
  13094. DEBUG_ERROR("Parse txProfile from file error.\n");
  13095. }
  13096. else
  13097. {
  13098. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13099. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13100. {
  13101. tmpProfileQuantity += 1;
  13102. }
  13103. else
  13104. replaceableProfileCnt += 1;
  13105. }
  13106. }
  13107. }
  13108. fclose(fp);
  13109. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  13110. }
  13111. }
  13112. else
  13113. {
  13114. memset(filename, 0, ARRAY_SIZE(filename));
  13115. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13116. fp = fopen(filename, "r");
  13117. if (!fp)
  13118. {
  13119. DEBUG_INFO("%s does not create.\n", filename);
  13120. fp = fopen(filename, "w+");
  13121. }
  13122. else
  13123. {
  13124. char *line = NULL;
  13125. size_t len = 0;
  13126. while(getline(&line, &len, fp) != -1)
  13127. {
  13128. json_object *obj = NULL;
  13129. obj = json_tokener_parse(line);
  13130. if(is_error(obj))
  13131. {
  13132. DEBUG_ERROR("Parse txProfile from file error.\n");
  13133. }
  13134. else
  13135. {
  13136. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13137. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13138. {
  13139. profileQuantity += 1;
  13140. }
  13141. else
  13142. replaceableProfileCnt += 1;
  13143. }
  13144. }
  13145. }
  13146. fclose(fp);
  13147. }
  13148. }
  13149. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  13150. {
  13151. int isMatchTransactiodId= FALSE;
  13152. FILE *fp;
  13153. char filename[128]={0};
  13154. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  13155. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  13156. if(SetProfileReq.ConnectorId == 0)
  13157. {
  13158. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13159. DEBUG_WARN("Profile connector id is 0.\n");
  13160. goto end;
  13161. }
  13162. int tempIndex = 0;
  13163. //check Transaction active
  13164. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  13165. {
  13166. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13167. {
  13168. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13169. }
  13170. else
  13171. {
  13172. tempIndex = SetProfileReq.ConnectorId -1;
  13173. }
  13174. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13175. {
  13176. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13177. {
  13178. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13179. {
  13180. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13181. {
  13182. isMatchTransactiodId = TRUE;
  13183. break;
  13184. }
  13185. }
  13186. }
  13187. }
  13188. }
  13189. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  13190. {
  13191. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13192. {
  13193. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13194. }
  13195. else
  13196. {
  13197. tempIndex = SetProfileReq.ConnectorId -1;
  13198. }
  13199. for (int index = 0; index < CCS_QUANTITY; index++)
  13200. {
  13201. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13202. {
  13203. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  13204. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13205. {
  13206. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13207. {
  13208. isMatchTransactiodId = TRUE;
  13209. break;
  13210. }
  13211. }
  13212. }
  13213. }
  13214. }
  13215. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  13216. {
  13217. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13218. {
  13219. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13220. }
  13221. else
  13222. {
  13223. tempIndex = SetProfileReq.ConnectorId -1;
  13224. }
  13225. for (int index = 0; index < GB_QUANTITY; index++)
  13226. {
  13227. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13228. {
  13229. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13230. {
  13231. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13232. {
  13233. isMatchTransactiodId = TRUE;
  13234. break;
  13235. }
  13236. }
  13237. }
  13238. }
  13239. }
  13240. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  13241. {
  13242. tempIndex = SetProfileReq.ConnectorId -1;
  13243. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13244. {
  13245. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13246. {
  13247. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  13248. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13249. {
  13250. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13251. {
  13252. isMatchTransactiodId = TRUE;
  13253. break;
  13254. }
  13255. }
  13256. }
  13257. }
  13258. }
  13259. else
  13260. {
  13261. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13262. {
  13263. tempIndex = 2;
  13264. }
  13265. else
  13266. {
  13267. tempIndex = (SetProfileReq.ConnectorId -1);
  13268. }
  13269. for (int index = 0; index < AC_QUANTITY; index++)
  13270. {
  13271. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13272. {
  13273. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  13274. {
  13275. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13276. {
  13277. isMatchTransactiodId = TRUE;
  13278. break;
  13279. }
  13280. }
  13281. }
  13282. }
  13283. }
  13284. //check Transaction active
  13285. if(isMatchTransactiodId == FALSE)
  13286. {
  13287. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13288. DEBUG_WARN("Tx profile transaction id is not match.\n");
  13289. goto end;
  13290. }
  13291. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13292. {
  13293. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13294. DEBUG_WARN("Connector id is over max gun number.\n");
  13295. goto end;
  13296. }
  13297. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13298. fp = fopen(filename, "r");
  13299. if (!fp)
  13300. {
  13301. DEBUG_INFO("%s does not create.\n", filename);
  13302. fp = fopen(filename, "w+");
  13303. }
  13304. else
  13305. {
  13306. char *line = NULL;
  13307. size_t len = 0;
  13308. while(getline(&line, &len, fp) != -1)
  13309. {
  13310. json_object *obj = NULL;
  13311. obj = json_tokener_parse(line);
  13312. if(is_error(obj))
  13313. {
  13314. DEBUG_ERROR("Parse txProfile from file error.\n");
  13315. }
  13316. else
  13317. {
  13318. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13319. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13320. {
  13321. profileQuantity += 1;
  13322. }
  13323. else
  13324. replaceableProfileCnt += 1;
  13325. }
  13326. }
  13327. }
  13328. fclose(fp);
  13329. }
  13330. // Check ChargeProfileMaxStackLevel
  13331. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  13332. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  13333. {
  13334. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13335. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13336. goto end;
  13337. }
  13338. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13339. {
  13340. FILE *fp;
  13341. char dataLine[4096]={0};
  13342. char fnametemp[128]={0};
  13343. int tmpProfileQuantity;
  13344. //Check ChargePointMaxProfile.json exit
  13345. profileQuantity = 0;
  13346. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  13347. {
  13348. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  13349. //Check Charging Profile Count
  13350. tmpProfileQuantity = 0;
  13351. while(fscanf(fp, "%s", dataLine) != EOF)
  13352. {
  13353. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13354. {
  13355. profileQuantity += 1;
  13356. tmpProfileQuantity += 1;
  13357. }
  13358. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13359. }
  13360. fclose(fp);
  13361. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  13362. }
  13363. //Check TxDefaultProfile_%d.json
  13364. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13365. {
  13366. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13367. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13368. if((access(fnametemp,F_OK))!=-1)
  13369. {
  13370. fp = fopen(fnametemp, "r");
  13371. //Check Charging Profile Count
  13372. tmpProfileQuantity = 0;
  13373. while(fscanf(fp, "%s", dataLine) != EOF)
  13374. {
  13375. //DEBUG_INFO("word=%s\n",word);
  13376. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13377. {
  13378. profileQuantity += 1;
  13379. tmpProfileQuantity += 1;
  13380. }
  13381. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13382. }
  13383. fclose(fp);
  13384. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13385. }
  13386. }
  13387. //Check TxProfile_%d.json
  13388. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13389. {
  13390. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13391. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  13392. if((access(fnametemp,F_OK))!=-1)
  13393. {
  13394. fp = fopen(fnametemp, "r");
  13395. //Check Charging Profile Count
  13396. tmpProfileQuantity = 0;
  13397. while(fscanf(fp, "%s", dataLine) != EOF)
  13398. {
  13399. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13400. {
  13401. profileQuantity += 1;
  13402. tmpProfileQuantity += 1;
  13403. }
  13404. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13405. }
  13406. fclose(fp);
  13407. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13408. }
  13409. }
  13410. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  13411. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  13412. // To check total Profile quantity
  13413. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  13414. {
  13415. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13416. {
  13417. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13418. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13419. goto end;
  13420. }
  13421. }
  13422. else
  13423. {
  13424. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13425. {
  13426. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13427. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13428. goto end;
  13429. }
  13430. }
  13431. }
  13432. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13433. //**********************************Write to File********************************************************/
  13434. {
  13435. FILE *infile;
  13436. FILE *outfile;
  13437. char dataLine[4096]={0};
  13438. char filename[128]={0};
  13439. int chkChar=0;
  13440. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  13441. {
  13442. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13443. {
  13444. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  13445. }
  13446. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13447. {
  13448. if(SetProfileReq.ConnectorId==0)
  13449. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13450. else
  13451. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13452. }
  13453. else
  13454. {
  13455. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13456. }
  13457. infile = fopen (filename, "r");
  13458. outfile = fopen (tempfile, "w");
  13459. chkChar = fgetc(infile);
  13460. rewind(infile);
  13461. if(chkChar == EOF)
  13462. {
  13463. // Profile is empty
  13464. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13465. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13466. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13467. fclose(infile);
  13468. fclose(outfile);
  13469. sprintf(rmFileCmd,"rm -f %s",filename);
  13470. system(rmFileCmd);
  13471. rename(tempfile, filename);
  13472. }
  13473. else
  13474. {
  13475. // Profile is not empty
  13476. int ChargingProfileAdded = FALSE;
  13477. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  13478. {
  13479. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  13480. json_object *tmpChargingProfile;
  13481. tmpChargingProfile = json_tokener_parse(dataLine);
  13482. if(!is_error(SetChargingProfile))
  13483. {
  13484. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13485. {
  13486. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13487. {
  13488. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13489. }
  13490. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13491. {
  13492. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13493. }
  13494. }
  13495. }
  13496. json_object_put(tmpChargingProfile);
  13497. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  13498. {
  13499. if(ChargingProfileAdded == FALSE)
  13500. {
  13501. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13502. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13503. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13504. ChargingProfileAdded = TRUE;
  13505. }
  13506. }
  13507. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13508. {
  13509. if(ChargingProfileAdded == FALSE)
  13510. {
  13511. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13512. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13513. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13514. ChargingProfileAdded = TRUE;
  13515. }
  13516. }
  13517. else
  13518. {
  13519. fprintf(outfile,"%s\n",dataLine);
  13520. if(ChargingProfileAdded == FALSE)
  13521. {
  13522. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13523. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13524. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13525. ChargingProfileAdded = TRUE;
  13526. }
  13527. }
  13528. } // end of while loop
  13529. fclose(infile);
  13530. fclose(outfile);
  13531. sprintf(rmFileCmd,"rm -f %s",filename);
  13532. system(rmFileCmd);
  13533. rename(tempfile, filename);
  13534. }
  13535. }
  13536. sleep(1);
  13537. result = TRUE;
  13538. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13539. }
  13540. end:
  13541. json_object_put(SetChargingProfile);
  13542. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13543. {
  13544. if(SetProfileReq.ConnectorId == 0)
  13545. {
  13546. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13547. {
  13548. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13549. }
  13550. }
  13551. else
  13552. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13553. }
  13554. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13555. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13556. return result;
  13557. }
  13558. int handleTriggerMessageRequest(char *uuid, char *payload)
  13559. {
  13560. mtrace();
  13561. int result = FAIL;
  13562. int connectorIdIsNULL = FALSE;
  13563. int connectorIdInt =0;
  13564. char sstr[40]={0},sstrtemp[100]={ 0 };
  13565. char requestedMessagestr[40]={0};
  13566. char comfirmstr[20]={0};
  13567. int c = 0;
  13568. char *loc;
  13569. DEBUG_INFO("handleTriggerMessageRequest\n");
  13570. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13571. strcpy(sstrtemp, stringtrimspace(payload));
  13572. c = 0;
  13573. loc = strstr(sstrtemp, "requestedMessage");
  13574. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13575. {
  13576. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13577. c++;
  13578. }
  13579. sstr[c] = '\0';
  13580. strcpy(requestedMessagestr, sstr);
  13581. c = 0;
  13582. loc = strstr(sstrtemp, "connectorId");
  13583. if(loc == NULL)
  13584. {
  13585. connectorIdIsNULL = TRUE;
  13586. }
  13587. else
  13588. {
  13589. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13590. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13591. {
  13592. sstr[c] = loc[strlen("connectorId")+2+c];
  13593. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13594. c++;
  13595. }
  13596. sstr[c] = '\0';
  13597. connectorIdInt = atoi(sstr);
  13598. }
  13599. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13600. {
  13601. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13602. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13603. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13604. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13605. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13606. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13607. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13608. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13609. {
  13610. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13611. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13612. return TRUE;
  13613. }
  13614. else
  13615. {
  13616. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13617. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13618. }
  13619. }
  13620. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13621. {
  13622. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13623. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13624. return TRUE;
  13625. }
  13626. //==========================
  13627. // Trigger message
  13628. //==========================
  13629. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13630. {
  13631. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13632. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13633. {
  13634. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13635. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13636. }
  13637. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13638. }
  13639. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13640. {
  13641. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13642. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13643. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13644. }
  13645. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13646. {
  13647. //sendBootNotificationRequest();
  13648. server_sign = FALSE;
  13649. }
  13650. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13651. {
  13652. refreshStartTimer(&clientTime.Heartbeat);
  13653. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13654. }
  13655. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13656. {
  13657. if(connectorIdIsNULL == FALSE)
  13658. {
  13659. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13660. {
  13661. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13662. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13663. }
  13664. }
  13665. else
  13666. {
  13667. for(int idx=0;idx< gunTotalNumber;idx++)
  13668. {
  13669. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13670. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13671. }
  13672. }
  13673. }
  13674. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13675. {
  13676. if(connectorIdIsNULL == FALSE)
  13677. {
  13678. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13679. {
  13680. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13681. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13682. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13683. }
  13684. }
  13685. else
  13686. {
  13687. for(int idx=0;idx< gunTotalNumber;idx++)
  13688. {
  13689. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13690. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13691. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13692. }
  13693. }
  13694. }
  13695. return result;
  13696. }
  13697. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13698. {
  13699. mtrace();
  13700. int result = FAIL;
  13701. int connectorIdInt =0;
  13702. char comfirmstr[20]={0};
  13703. int tempIndex = 0;
  13704. json_object *UnlockConnector;
  13705. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13706. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13707. UnlockConnector = json_tokener_parse(payload);
  13708. if(!is_error(UnlockConnector))
  13709. {
  13710. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13711. {
  13712. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13713. }
  13714. }
  13715. json_object_put(UnlockConnector);
  13716. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13717. if(gunTotalNumber == 0)
  13718. {
  13719. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13720. goto end;
  13721. }
  13722. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13723. {
  13724. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13725. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13726. goto end;
  13727. }
  13728. else
  13729. {
  13730. //check Transaction active
  13731. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13732. {
  13733. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13734. {
  13735. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13736. }
  13737. else
  13738. {
  13739. tempIndex = connectorIdInt -1;
  13740. }
  13741. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13742. {
  13743. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13744. {
  13745. //stop Transaction
  13746. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13747. }
  13748. }
  13749. }
  13750. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13751. {
  13752. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13753. {
  13754. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13755. }
  13756. else
  13757. {
  13758. tempIndex = connectorIdInt -1;
  13759. }
  13760. for (int index = 0; index < CCS_QUANTITY; index++)
  13761. {
  13762. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13763. {
  13764. //stop Transaction
  13765. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13766. }
  13767. }
  13768. }
  13769. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13770. {
  13771. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13772. {
  13773. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13774. }
  13775. else
  13776. {
  13777. tempIndex = connectorIdInt -1;
  13778. }
  13779. for (int index = 0; index < GB_QUANTITY; index++)
  13780. {
  13781. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13782. {
  13783. //stop Transaction
  13784. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13785. }
  13786. }
  13787. }
  13788. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13789. {
  13790. tempIndex = connectorIdInt -1;
  13791. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13792. {
  13793. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13794. {
  13795. //stop Transaction
  13796. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13797. }
  13798. }
  13799. }
  13800. else
  13801. {
  13802. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13803. {
  13804. tempIndex = 2;
  13805. }
  13806. else
  13807. {
  13808. tempIndex = connectorIdInt-1;
  13809. }
  13810. for (int index = 0; index < AC_QUANTITY; index++)
  13811. {
  13812. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13813. {
  13814. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13815. }
  13816. }
  13817. }
  13818. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13819. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13820. result = TRUE;
  13821. return result;
  13822. }
  13823. end:
  13824. //json_object_put(obj); --- remove temporally
  13825. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13826. return result;
  13827. }
  13828. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13829. {
  13830. mtrace();
  13831. int result = FAIL;
  13832. pthread_t t;
  13833. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13834. sendUpdateFirmwareConfirmation(uuid);
  13835. if(!interLock.isUpdateFirmwareGoing)
  13836. {
  13837. interLock.isUpdateFirmwareGoing = 1;
  13838. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  13839. sleep(1);
  13840. }
  13841. else
  13842. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13843. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13844. return result;
  13845. }
  13846. void *UpdateFirmwareProcess(void *data)
  13847. {
  13848. pthread_detach(pthread_self());
  13849. mtrace();
  13850. int retriesInt =0, retryIntervalInt=0;
  13851. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13852. int port=0;
  13853. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13854. int isSuccess = 0;
  13855. char ftpbuf[1024];
  13856. char temp[1024];
  13857. char * pch;
  13858. json_object *UpdateFirmware;
  13859. UpdateFirmware = json_tokener_parse(data);
  13860. if(!is_error(UpdateFirmware))
  13861. {
  13862. // Required data
  13863. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13864. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13865. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13866. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13867. // Optional data
  13868. if(json_object_object_get(UpdateFirmware, "retries"))
  13869. {
  13870. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13871. }
  13872. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13873. {
  13874. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13875. }
  13876. }
  13877. json_object_put(UpdateFirmware);
  13878. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13879. memset(path, 0, ARRAY_SIZE(path));
  13880. // Wait retrieveData
  13881. if(strlen(retrieveDatestr) > 10)
  13882. {
  13883. do
  13884. {
  13885. sleep(1);
  13886. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13887. }
  13888. // Ready to download
  13889. system("rm -f /mnt/*");
  13890. if(strncmp(locationstr,"http", 4) == 0)
  13891. {
  13892. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13893. sprintf(ftppath,"/%s", path);
  13894. DEBUG_INFO("locationstr: %s\n", locationstr);
  13895. DEBUG_INFO("protocol: %s\n",protocol);
  13896. DEBUG_INFO("host: %s\n",host);
  13897. DEBUG_INFO("path: %s\n",path);
  13898. DEBUG_INFO("ftppath: %s\n",ftppath);
  13899. int ftppathlen=strlen(ftppath);
  13900. int i=1;
  13901. char filenametemp[50];
  13902. while(i < ftppathlen)
  13903. {
  13904. int len=ftppathlen-i;
  13905. if(ftppath[len]== 47) // '/' ascll code: 47
  13906. {
  13907. DEBUG_INFO("compare '/' all right\n");
  13908. break;
  13909. }
  13910. i=i+1;
  13911. }
  13912. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13913. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13914. filenametemp[i+1] = 0;
  13915. do
  13916. {
  13917. sleep(1);
  13918. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13919. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13920. sleep(1);
  13921. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13922. if(!isSuccess)
  13923. {
  13924. sleep(1);
  13925. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13926. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13927. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13928. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13929. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13930. }
  13931. else
  13932. {
  13933. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13934. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13935. }
  13936. retriesInt--;
  13937. }while((isSuccess == 0)&&(retriesInt >= 0));
  13938. }
  13939. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13940. {
  13941. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13942. memset(temp, 0, ARRAY_SIZE(temp));
  13943. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13944. strcpy(ftpbuf, locationstr);
  13945. int ftppathlen=strlen(ftpbuf);
  13946. int i=1;
  13947. char filenametemp[50];
  13948. while(i < ftppathlen)
  13949. {
  13950. int len=ftppathlen-i;
  13951. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13952. {
  13953. DEBUG_INFO(" compare '/' all right\n");
  13954. break;
  13955. }
  13956. i=i+1;
  13957. }
  13958. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13959. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13960. filenametemp[i+1] = 0;
  13961. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13962. pch=strchr(temp,'@');
  13963. if(pch==NULL)
  13964. {
  13965. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13966. protocol, host, &port, path);
  13967. strcpy(user,"anonymous");
  13968. strcpy(password,"");
  13969. }
  13970. else
  13971. {
  13972. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13973. protocol, user, host, &port, path);
  13974. }
  13975. sscanf(host,"%[^/]%s",host1, path1);
  13976. sprintf(ftppath,"%s:/%s", host,path);
  13977. if(port == 0)
  13978. {
  13979. port = 21;
  13980. }
  13981. do
  13982. {
  13983. sleep(1);
  13984. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13985. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13986. sleep(1);
  13987. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13988. if(!isSuccess)
  13989. {
  13990. //BulldogUtil.sleepMs(interval*1000);
  13991. DEBUG_INFO("Update firmware request and download file fail.\n");
  13992. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13993. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13994. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13995. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13996. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13997. }
  13998. else
  13999. {
  14000. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  14001. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14002. }
  14003. retriesInt--;
  14004. }while((!isSuccess)&&(retriesInt >= 0));
  14005. }
  14006. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  14007. {
  14008. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14009. memset(temp, 0, ARRAY_SIZE(temp));
  14010. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14011. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  14012. int ftppathlen=strlen(ftpbuf);
  14013. int i=1;
  14014. char filenametemp[50];
  14015. while(i < ftppathlen)
  14016. {
  14017. int len=ftppathlen-i;
  14018. if(ftpbuf[len]== 47) // '/' ascll code: 47
  14019. {
  14020. DEBUG_INFO(" compare '/' all right\n");
  14021. break;
  14022. }
  14023. i=i+1;
  14024. }
  14025. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14026. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  14027. filenametemp[i+1] = 0;
  14028. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14029. pch=strchr(temp,'@');
  14030. if(pch==NULL)
  14031. {
  14032. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14033. protocol, host, &port, path);
  14034. strcpy(user,"anonymous");
  14035. strcpy(password,"");
  14036. }
  14037. else
  14038. {
  14039. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14040. protocol, user, password, host, &port, path);
  14041. }
  14042. sscanf(host,"%[^/]%s",host1, path1);
  14043. sprintf(ftppath,"%s", path1);
  14044. //DEBUG_INFO("protocol =%s\n",protocol);
  14045. //DEBUG_INFO("user =%s\n",user);
  14046. //DEBUG_INFO("password =%s\n",password);
  14047. //DEBUG_INFO("host1 =%s\n",host1);
  14048. //DEBUG_INFO("port =%d\n",port);
  14049. //DEBUG_INFO("path1 =%s\n",path1);
  14050. //DEBUG_INFO("ftppath=%s\n",ftppath);
  14051. //ftpFile(host, user, password, port, ftppath, fname);
  14052. //download firmware pthred
  14053. if(port == 0)
  14054. {
  14055. port = 21;
  14056. }
  14057. do
  14058. {
  14059. sleep(1);
  14060. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  14061. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14062. sleep(1);
  14063. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  14064. if(!isSuccess)
  14065. {
  14066. //BulldogUtil.sleepMs(interval*1000);
  14067. DEBUG_INFO("Update firmware request and download file fail.\n");
  14068. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  14069. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14070. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  14071. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  14072. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14073. }
  14074. else
  14075. {
  14076. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  14077. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14078. }
  14079. retriesInt--;
  14080. }while((!isSuccess)&&(retriesInt >= 0));
  14081. }
  14082. else
  14083. {
  14084. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  14085. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14086. sleep(1);
  14087. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  14088. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14089. }
  14090. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)
  14091. {
  14092. sleep(3);
  14093. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  14094. }
  14095. interLock.isUpdateFirmwareGoing = 0;
  14096. pthread_exit(NULL);
  14097. }
  14098. int handleCertificateSignedRequest(char *uuid, char *payload)
  14099. {
  14100. mtrace();
  14101. int result = PASS;
  14102. json_object *CertificateSigned;
  14103. DEBUG_INFO("handleCertificateSignedRequest...\n");
  14104. CertificateSigned = json_tokener_parse(payload);
  14105. if(!is_error(CertificateSigned))
  14106. {
  14107. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  14108. }
  14109. json_object_put(CertificateSigned);
  14110. FILE *fp = fopen(CERTIFICATE_CP, "w");
  14111. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  14112. fclose(fp);
  14113. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14114. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  14115. if(certVerify(PRIVATE_KEY_CP, CERTIFICATE_CP) == PASS)
  14116. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  14117. else
  14118. {
  14119. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Rejected");
  14120. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  14121. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14122. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14123. }
  14124. sendCertificateSignedConfirmation(uuid);
  14125. return result;
  14126. }
  14127. int handleDeleteCertificateRequest(char *uuid, char *payload)
  14128. {
  14129. mtrace();
  14130. int result = PASS;
  14131. json_object *DeleteCertificate;
  14132. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  14133. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  14134. DeleteCertificate = json_tokener_parse(payload);
  14135. if(!is_error(DeleteCertificate))
  14136. {
  14137. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  14138. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  14139. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  14140. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  14141. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14142. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  14143. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  14144. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  14145. char temp[256] = {0};
  14146. char compareData[256] = {0};
  14147. int isMatch = TRUE;
  14148. FILE *fp;
  14149. if(access(ROOTCA_CS,F_OK) != -1)
  14150. {
  14151. // Check CentralSystemRootCertificate
  14152. DEBUG_INFO("Checking CentralSystemRootCertificate...\n");
  14153. parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, compareData);
  14154. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14155. isMatch = FALSE;
  14156. if(isMatch == TRUE)
  14157. {
  14158. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, compareData);
  14159. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14160. isMatch = FALSE;
  14161. }
  14162. if(isMatch == TRUE)
  14163. {
  14164. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, compareData);
  14165. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14166. isMatch = FALSE;
  14167. }
  14168. if(isMatch == TRUE)
  14169. {
  14170. sprintf(temp, "rm -f /Storage/OCPP/%s", ROOTCA_CS);
  14171. system(temp);
  14172. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14173. goto End;
  14174. }
  14175. }
  14176. // Check ManufacturerRootCertificate
  14177. if(access(ROOTCA_MFG,F_OK) != -1)
  14178. {
  14179. isMatch = TRUE;
  14180. parseCertInfo(ROOTCA_MFG, CERT_PARSE_SerialNumber, compareData);
  14181. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14182. isMatch = FALSE;
  14183. if(isMatch == TRUE)
  14184. {
  14185. parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerNameHash, compareData);
  14186. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14187. isMatch = FALSE;
  14188. }
  14189. if(isMatch == TRUE)
  14190. {
  14191. parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerKeyHash, compareData);
  14192. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14193. isMatch = FALSE;
  14194. }
  14195. if(isMatch == TRUE)
  14196. {
  14197. sprintf(temp, "rm -f %s", ROOTCA_MFG);
  14198. system(temp);
  14199. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14200. goto End;
  14201. }
  14202. }
  14203. // Check certCP
  14204. if(access(CERTIFICATE_CP,F_OK) != -1)
  14205. {
  14206. isMatch = FALSE;
  14207. sprintf(temp ,"openssl x509 -noout -serial -in %s", CERTIFICATE_CP);
  14208. fp = popen(temp, "r");
  14209. if(fp)
  14210. {
  14211. while(fgets(temp, sizeof(temp), fp) != NULL)
  14212. {
  14213. if(strstr(temp, "serial=") != NULL)
  14214. {
  14215. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14216. sscanf(temp, "%*[^=]=%s", compareData);
  14217. break;
  14218. }
  14219. }
  14220. }
  14221. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14222. isMatch = FALSE;
  14223. if(isMatch == TRUE)
  14224. {
  14225. memset(compareData, 0, ARRAY_SIZE(compareData));
  14226. sprintf(temp ,"openssl x509 -noout -issuer -in %s | openssl dgst -%s", CERTIFICATE_CP, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14227. fp = popen(temp, "r");
  14228. if(fp)
  14229. {
  14230. while(fgets(temp, sizeof(temp), fp) != NULL)
  14231. {
  14232. strcat(compareData, temp);
  14233. }
  14234. }
  14235. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) == NULL)
  14236. isMatch = FALSE;
  14237. }
  14238. if(isMatch == TRUE)
  14239. {
  14240. memset(compareData, 0, ARRAY_SIZE(compareData));
  14241. sprintf(temp ,"openssl x509 -noout -pubkey -in %s | openssl dgst -%s", CERTIFICATE_CP, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14242. fp = popen(temp, "r");
  14243. if(fp)
  14244. {
  14245. while(fgets(temp, sizeof(temp), fp) != NULL)
  14246. {
  14247. strcat(compareData, temp);
  14248. }
  14249. }
  14250. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14251. isMatch = FALSE;
  14252. }
  14253. if(isMatch == TRUE)
  14254. {
  14255. sprintf(temp, "rm -f %s", CERTIFICATE_CP);
  14256. system(temp);
  14257. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14258. goto End;
  14259. }
  14260. }
  14261. }
  14262. End:
  14263. json_object_put(DeleteCertificate);
  14264. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  14265. sendDeleteCertificateConfirmation(uuid);
  14266. return result;
  14267. }
  14268. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  14269. {
  14270. mtrace();
  14271. int result = PASS;
  14272. json_object *ExtendedTriggerMessage;
  14273. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  14274. ExtendedTriggerMessage = json_tokener_parse(payload);
  14275. if(!is_error(ExtendedTriggerMessage))
  14276. {
  14277. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  14278. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  14279. {
  14280. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  14281. }
  14282. else
  14283. {
  14284. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  14285. }
  14286. }
  14287. json_object_put(ExtendedTriggerMessage);
  14288. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  14289. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  14290. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  14291. {
  14292. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  14293. }
  14294. else
  14295. {
  14296. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  14297. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  14298. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  14299. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  14300. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  14301. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  14302. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  14303. {
  14304. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  14305. }
  14306. else
  14307. {
  14308. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  14309. }
  14310. }
  14311. sendExtendedTriggerMessageConfirmation(uuid);
  14312. //==========================
  14313. // Trigger message
  14314. //==========================
  14315. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  14316. {
  14317. //sendBootNotificationRequest();
  14318. server_sign = FALSE;
  14319. }
  14320. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  14321. {
  14322. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14323. }
  14324. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  14325. {
  14326. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  14327. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  14328. {
  14329. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  14330. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  14331. }
  14332. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14333. }
  14334. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  14335. {
  14336. refreshStartTimer(&clientTime.Heartbeat);
  14337. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  14338. }
  14339. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  14340. {
  14341. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14342. {
  14343. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  14344. }
  14345. else
  14346. {
  14347. for(int idx=0;idx< gunTotalNumber;idx++)
  14348. {
  14349. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  14350. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  14351. }
  14352. }
  14353. }
  14354. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  14355. {
  14356. char cmdBuf[1024]={0};
  14357. 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);
  14358. system(cmdBuf);
  14359. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  14360. }
  14361. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  14362. {
  14363. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14364. {
  14365. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  14366. }
  14367. else
  14368. {
  14369. for(int idx=0;idx< gunTotalNumber;idx++)
  14370. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  14371. }
  14372. }
  14373. return result;
  14374. }
  14375. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  14376. {
  14377. mtrace();
  14378. int result = PASS;
  14379. json_object *GetInstalledCertificateIds;
  14380. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  14381. GetInstalledCertificateIds = json_tokener_parse(payload);
  14382. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  14383. if(!is_error(GetInstalledCertificateIds))
  14384. {
  14385. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  14386. DEBUG_INFO("Requested Certificate: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14387. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "Accepted");
  14388. // Check CentralSystemRootCertificate
  14389. if((strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "CentralSystemRootCertificate")!= NULL) && (access(ROOTCA_CS,F_OK) != -1))
  14390. {
  14391. char parseData[512] = {0};
  14392. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14393. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14394. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_SerialNumber, parseData) == PASS)
  14395. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14396. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14397. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14398. if(parseCertInfo(ROOTCA_MFG, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14399. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14400. }
  14401. else
  14402. {
  14403. DEBUG_INFO(">>> No CentralSystemRootCertificate found.\n");
  14404. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14405. }
  14406. // Check ManufacturerRootCertificate
  14407. if((strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "ManufacturerRootCertificate") != NULL) && (access(ROOTCA_MFG,F_OK) != -1))
  14408. {
  14409. char parseData[512] = {0};
  14410. if(parseCertInfo(ROOTCA_MFG, 1, parseData) == PASS)
  14411. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14412. if(parseCertInfo(ROOTCA_MFG, 1, parseData) == PASS)
  14413. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14414. if(parseCertInfo(ROOTCA_MFG, 1, parseData) == PASS)
  14415. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14416. if(parseCertInfo(ROOTCA_MFG, 1, parseData) == PASS)
  14417. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14418. }
  14419. else
  14420. {
  14421. DEBUG_INFO(">>> No ManufacturerRootCertificate found.\n");
  14422. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14423. }
  14424. }
  14425. json_object_put(GetInstalledCertificateIds);
  14426. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  14427. sendGetInstalledCertificateIdsConfirmation(uuid);
  14428. return result;
  14429. }
  14430. void* GetLogProcess(void* data)
  14431. {
  14432. pthread_detach(pthread_self());
  14433. mtrace();
  14434. 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};
  14435. int port=0;
  14436. int isSuccess = FALSE;
  14437. char cmdBuf[2048];
  14438. struct tm *tmNow;
  14439. time_t CurrentTime;
  14440. struct tm tmStart;
  14441. struct tm tmStop;
  14442. CurrentTime = time(NULL);
  14443. tmNow=localtime(&CurrentTime);
  14444. uint16_t targetYear, targetMonth;
  14445. json_object *GetLog;
  14446. DEBUG_INFO("GetLogProcess...\n");
  14447. GetLog = json_tokener_parse(data);
  14448. if(!is_error(GetLog))
  14449. {
  14450. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  14451. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  14452. if(json_object_object_get(GetLog, "retries") != NULL)
  14453. {
  14454. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  14455. }
  14456. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  14457. {
  14458. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  14459. }
  14460. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  14461. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  14462. {
  14463. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  14464. }
  14465. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  14466. {
  14467. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  14468. }
  14469. }
  14470. json_object_put(GetLog);
  14471. // Pack log to compress file
  14472. 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) &&
  14473. (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))
  14474. {
  14475. // Pack system log
  14476. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14477. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14478. targetYear = tmStart.tm_year;
  14479. targetMonth = tmStart.tm_mon;
  14480. do
  14481. {
  14482. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14483. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  14484. if(targetMonth+1>=13)
  14485. {
  14486. targetYear += 1;
  14487. targetMonth = 1;
  14488. }
  14489. else
  14490. {
  14491. targetMonth += 1;
  14492. }
  14493. }while((targetYear < (tmNow->tm_year+1900)) ||
  14494. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14495. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  14496. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  14497. system(cmdBuf);
  14498. // Pack charging & event log
  14499. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14500. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  14501. targetYear = tmStart.tm_year;
  14502. targetMonth = tmStart.tm_mon;
  14503. do
  14504. {
  14505. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14506. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  14507. if(targetMonth+1>=13)
  14508. {
  14509. targetYear += 1;
  14510. targetMonth = 1;
  14511. }
  14512. else
  14513. {
  14514. targetMonth += 1;
  14515. }
  14516. }while((targetYear < (tmNow->tm_year+1900)) ||
  14517. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14518. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  14519. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  14520. system(cmdBuf);
  14521. // Combine log file
  14522. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  14523. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  14524. }
  14525. else
  14526. {
  14527. system("exec /root/logPackTools 'log' 6");
  14528. }
  14529. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetLog.Response_filename);
  14530. system(cmdBuf);
  14531. checkUploadLog();
  14532. //****************location*******************/
  14533. if(strcmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"")==0)
  14534. {
  14535. DEBUG_INFO("location is <Empty>!\n");
  14536. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14537. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14538. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14539. goto end;
  14540. }
  14541. memset(protocol, 0, ARRAY_SIZE(protocol));
  14542. memset(user, 0, ARRAY_SIZE(user) );
  14543. memset(password, 0, ARRAY_SIZE(password));
  14544. memset(host, 0, ARRAY_SIZE(host));
  14545. memset(path, 0, ARRAY_SIZE(path));
  14546. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14547. memset(host1, 0, ARRAY_SIZE(host1));
  14548. memset(path1, 0, ARRAY_SIZE(path1));
  14549. /*location: ftp://user:password@host:port/path*/
  14550. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  14551. if((access(fnamePlusPath,F_OK))!=-1)
  14552. {
  14553. DEBUG_INFO("fnamePlusPath exist.\n");
  14554. }
  14555. else
  14556. {
  14557. DEBUG_INFO("fnamePlusPath not exist!\n");
  14558. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14559. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14560. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14561. goto end;
  14562. }
  14563. if(strchr((char*)ShmOCPP16Data->GetLog.log.remoteLocation,'@')==NULL)
  14564. {
  14565. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,
  14566. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14567. protocol, host, &port, path);
  14568. strcpy(user,"anonymous");
  14569. strcpy(password,"");
  14570. }
  14571. else
  14572. {
  14573. //DEBUG_INFO("pch=%s\n", pch);
  14574. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14575. protocol, user, password, host, &port, path);
  14576. }
  14577. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  14578. {
  14579. DEBUG_INFO("protocol is not ftp/http ! \n");
  14580. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14581. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14582. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14583. goto end;
  14584. }
  14585. if(strncmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"http", 4) == 0)
  14586. {
  14587. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14588. sprintf(ftppath,"/%s", path);
  14589. do
  14590. {
  14591. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14592. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14593. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14594. sleep(3);
  14595. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, (char*)ShmOCPP16Data->GetLog.log.remoteLocation);
  14596. if(!isSuccess)
  14597. {
  14598. DEBUG_INFO("Diagnostics fail.\n");
  14599. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14600. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14601. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14602. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14603. }
  14604. else
  14605. {
  14606. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14607. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14608. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14609. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14610. }
  14611. ShmOCPP16Data->GetLog.retries--;
  14612. }while((isSuccess == 0)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14613. }
  14614. else
  14615. {
  14616. sscanf(host,"%[^/]%s",host1, path1);
  14617. if(strlen(path) > 0)
  14618. sprintf(ftppath,"/%s", path);
  14619. else
  14620. sprintf(ftppath,"/%s", path1);
  14621. int ftppathlen=strlen(ftppath);
  14622. int i=1;
  14623. char filenametemp[50];
  14624. while(i < ftppathlen)
  14625. {
  14626. int len=ftppathlen-i;
  14627. if(ftppath[len]== 47) // '/' ascll code: 47
  14628. {
  14629. DEBUG_INFO("find '/' all right\n");
  14630. break;
  14631. }
  14632. i=i+1;
  14633. }
  14634. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14635. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  14636. filenametemp[i+1] = 0;
  14637. if(port == 0)
  14638. port = 21;
  14639. do
  14640. {
  14641. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14642. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14643. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14644. sleep(3);
  14645. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  14646. if(!isSuccess)
  14647. {
  14648. DEBUG_INFO("Diagnostics fail.\n");
  14649. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14650. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14651. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14652. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14653. }
  14654. else
  14655. {
  14656. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14657. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14658. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14659. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14660. }
  14661. ShmOCPP16Data->GetLog.retries--;
  14662. }while((!isSuccess)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14663. }
  14664. end:
  14665. system("rm -f /mnt/*");
  14666. sleep(5);
  14667. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14668. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Idle");
  14669. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14670. interLock.isGetDiagnosticGoing = 0;
  14671. pthread_exit(NULL);
  14672. }
  14673. int handleGetLogRequest(char *uuid, char *payload)
  14674. {
  14675. mtrace();
  14676. int result = PASS;
  14677. time_t CurrentTime;
  14678. struct tm *tm;
  14679. DEBUG_INFO("handleGetLogRequest...\n");
  14680. pthread_t th_Status;
  14681. CurrentTime = time(NULL);
  14682. tm = localtime(&CurrentTime);
  14683. memset(ShmOCPP16Data->GetLog.Response_filename, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetLog.Response_filename));
  14684. 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);
  14685. if(!interLock.isGetDiagnosticGoing)
  14686. {
  14687. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Accepted");
  14688. interLock.isGetDiagnosticGoing = 1;
  14689. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  14690. sleep(1);
  14691. }
  14692. else
  14693. {
  14694. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  14695. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  14696. }
  14697. sendGetLogConfirmation(uuid);
  14698. return result;
  14699. }
  14700. int handleInstallCertificateRequest(char *uuid, char *payload)
  14701. {
  14702. mtrace();
  14703. int result = PASS;
  14704. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  14705. json_object *InstallCertificate;
  14706. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14707. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14708. InstallCertificate = json_tokener_parse(payload);
  14709. if(!is_error(InstallCertificate))
  14710. {
  14711. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14712. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14713. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  14714. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  14715. char temp[1024];
  14716. FILE *fp = fopen(tempCert, "w");
  14717. fprintf(fp, "%s", ShmOCPP16Data->InstallCertificate.certificate);
  14718. fclose(fp);
  14719. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  14720. char strExpDate[30];
  14721. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  14722. fp = popen(temp, "r");
  14723. if(fp)
  14724. {
  14725. while(fgets(temp, sizeof(temp), fp) != NULL)
  14726. {
  14727. if(strstr(temp, "notAfter=") != NULL)
  14728. {
  14729. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14730. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  14731. break;
  14732. }
  14733. }
  14734. }
  14735. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  14736. struct tm tmExpDate;
  14737. struct timeb tbExpDate;
  14738. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  14739. tbExpDate.time = mktime(&tmExpDate);
  14740. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  14741. {
  14742. DEBUG_INFO("The enddate is already expired...\n");
  14743. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14744. goto End;
  14745. }
  14746. // Verify certificate with rootCA
  14747. sprintf(temp ,"openssl verify -CAfile /root/cacert.pem /Storage/OCPP/tempInstallCertificate.pem");
  14748. fp = popen(temp, "r");
  14749. if(fp)
  14750. {
  14751. while(fgets(temp, sizeof(temp), fp) != NULL)
  14752. {
  14753. if((strstr(temp, "tempInstallCertificate.pem: OK") != NULL) || (strstr(temp, "self signed certificate") != NULL))
  14754. {
  14755. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14756. break;
  14757. }
  14758. else
  14759. {
  14760. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14761. }
  14762. }
  14763. }
  14764. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14765. {
  14766. //=====================================================
  14767. // Verify if the certificate is valid or not. (OCSP?)
  14768. //=====================================================
  14769. /*
  14770. DEBUG_INFO("openssl CA verifying...FAIL --> Start OCSP process...\n");
  14771. // Get ocsp url
  14772. char ocspUrl[512];
  14773. sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", tempCert);
  14774. fp = popen(temp, "r");
  14775. if(fp)
  14776. {
  14777. while(fgets(temp, sizeof(temp), fp) != NULL)
  14778. {
  14779. if(strstr(temp, "://") != NULL)
  14780. {
  14781. strcpy(ocspUrl, temp);
  14782. break;
  14783. }
  14784. }
  14785. }
  14786. // Get certificate chain for issuer
  14787. * openssl s_client -connect [serverURL:port] -showcerts | sed -n '/-----BEGIN/,/-------END/p' > tempChain.pem
  14788. *
  14789. // Execute OCSP
  14790. sprintf(temp ,"openssl ocsp -issuer tempChain.pem -cert /Storage/OCPP/tempInstallCertificate.pem -text -url %s", ocspUrl);
  14791. fp = popen(temp, "r");
  14792. if(fp)
  14793. {
  14794. while(fgets(temp, sizeof(temp), fp) != NULL)
  14795. {
  14796. if(strstr(temp, "tempInstallCertificate.pem: good") != NULL)
  14797. {
  14798. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14799. break;
  14800. }
  14801. }
  14802. }
  14803. system("rm -f /Storage/OCPP/tempChain.pem");
  14804. pclose(fp);
  14805. */
  14806. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14807. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14808. {
  14809. DEBUG_INFO("OCSP verifying...FAIL.\n");
  14810. goto End;
  14811. }
  14812. else
  14813. DEBUG_INFO("OCSP verifying...PASS.\n");
  14814. }
  14815. else
  14816. DEBUG_INFO("openssl CA verifying...PASS.\n");
  14817. }
  14818. End:
  14819. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") == 0)
  14820. {
  14821. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "CentralSystemRootCertificate") == 0)
  14822. {
  14823. if(access(ROOTCA_CS,F_OK) != -1)
  14824. {
  14825. DEBUG_INFO("Existed CentralSystemRootCertificate is found. Replacing...\n");
  14826. rename(ROOTCA_CS, "/Storage/OCPP/CentralSystemRootCertificate_fallback.pem");
  14827. rename(tempCert, ROOTCA_CS);
  14828. }
  14829. else
  14830. {
  14831. DEBUG_INFO("No existed CentralSystemRootCertificate. Creating...\n");
  14832. rename(tempCert, ROOTCA_CS);
  14833. }
  14834. }
  14835. else if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "ManufacturerRootCertificate") == 0)
  14836. {
  14837. if(access(ROOTCA_MFG,F_OK) != -1)
  14838. {
  14839. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14840. rename(ROOTCA_MFG, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14841. rename(tempCert, ROOTCA_MFG);
  14842. }
  14843. else
  14844. {
  14845. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14846. rename(tempCert, ROOTCA_MFG);
  14847. }
  14848. }
  14849. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  14850. }
  14851. sendInstallCertificateConfirmation(uuid);
  14852. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14853. {
  14854. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidCentralSystemCertificate");
  14855. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14856. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14857. }
  14858. json_object_put(InstallCertificate);
  14859. return result;
  14860. }
  14861. void *SignedUpdateFirmwareProcess(void *data)
  14862. {
  14863. pthread_detach(pthread_self());
  14864. mtrace();
  14865. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  14866. int port=0;
  14867. int isSuccess = 0;
  14868. char ftpbuf[1024];
  14869. char temp[1024];
  14870. char * pch;
  14871. char firmwareFileName[50];
  14872. DEBUG_INFO("SignedUpdateFirmwareProcess ...\n");
  14873. json_object *SignedUpdateFirmware;
  14874. SignedUpdateFirmware = json_tokener_parse(data);
  14875. if(!is_error(SignedUpdateFirmware))
  14876. {
  14877. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  14878. {
  14879. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  14880. }
  14881. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  14882. {
  14883. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  14884. }
  14885. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  14886. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  14887. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  14888. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  14889. {
  14890. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  14891. }
  14892. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  14893. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  14894. }
  14895. json_object_put(SignedUpdateFirmware);
  14896. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14897. memset(path, 0, ARRAY_SIZE(path));
  14898. // Wait retrieveData
  14899. if(strlen((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location) > 10)
  14900. {
  14901. do
  14902. {
  14903. sleep(1);
  14904. }while(!isOvertNow((uint8_t*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime));
  14905. }
  14906. // Ready to download
  14907. system("rm -f /mnt/*");
  14908. if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"http", 4) == 0)
  14909. {
  14910. sscanf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14911. sprintf(ftppath,"/%s", path);
  14912. DEBUG_INFO("locationstr: %s\n", (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14913. DEBUG_INFO("protocol: %s\n",protocol);
  14914. DEBUG_INFO("host: %s\n",host);
  14915. DEBUG_INFO("path: %s\n",path);
  14916. DEBUG_INFO("ftppath: %s\n",ftppath);
  14917. int ftppathlen=strlen(ftppath);
  14918. int i=1;
  14919. while(i < ftppathlen)
  14920. {
  14921. int len=ftppathlen-i;
  14922. if(ftppath[len]== 47) // '/' ascll code: 47
  14923. {
  14924. DEBUG_INFO("compare '/' all right\n");
  14925. break;
  14926. }
  14927. i=i+1;
  14928. }
  14929. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14930. strncpy(firmwareFileName, ftppath+(ftppathlen-i+1), i+1);
  14931. firmwareFileName[i+1] = 0;
  14932. do
  14933. {
  14934. sleep(1);
  14935. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14936. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14937. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14938. sleep(1);
  14939. isSuccess = httpDownLoadFile(host, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14940. if(!isSuccess)
  14941. {
  14942. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14943. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14944. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14945. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14946. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14947. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14948. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14949. }
  14950. else
  14951. {
  14952. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14953. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14954. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14955. }
  14956. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14957. }while((isSuccess == 0)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14958. }
  14959. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"sftp", 4) == 0) // sftp
  14960. {
  14961. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14962. memset(temp, 0, ARRAY_SIZE(temp));
  14963. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14964. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14965. int ftppathlen=strlen(ftpbuf);
  14966. int i=1;
  14967. while(i < ftppathlen)
  14968. {
  14969. int len=ftppathlen-i;
  14970. if(ftpbuf[len]== 47) // '/' ascii code: 47
  14971. {
  14972. DEBUG_INFO(" compare '/' all right\n");
  14973. break;
  14974. }
  14975. i=i+1;
  14976. }
  14977. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14978. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14979. firmwareFileName[i+1] = 0;
  14980. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14981. pch=strchr(temp,'@');
  14982. if(pch==NULL)
  14983. {
  14984. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14985. protocol, host, &port, path);
  14986. strcpy(user,"anonymous");
  14987. strcpy(password,"");
  14988. }
  14989. else
  14990. {
  14991. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  14992. protocol, user, host, &port, path);
  14993. }
  14994. sscanf(host,"%[^/]%s",host1, path1);
  14995. sprintf(ftppath,"%s:/%s", host,path);
  14996. if(port == 0)
  14997. {
  14998. port = 21;
  14999. }
  15000. do
  15001. {
  15002. sleep(1);
  15003. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15004. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  15005. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15006. sleep(1);
  15007. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15008. if(!isSuccess)
  15009. {
  15010. sleep(1);
  15011. DEBUG_INFO("Update firmware request and download file fail.\n");
  15012. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15013. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15014. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15015. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  15016. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15017. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15018. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15019. }
  15020. else
  15021. {
  15022. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15023. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  15024. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15025. }
  15026. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15027. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15028. }
  15029. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"ftp", 3) == 0) // ftp
  15030. {
  15031. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15032. memset(temp, 0, ARRAY_SIZE(temp));
  15033. //DEBUG_INFO("locationstr=%s\n",locationstr);
  15034. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15035. int ftppathlen=strlen(ftpbuf);
  15036. int i=1;
  15037. while(i < ftppathlen)
  15038. {
  15039. int len=ftppathlen-i;
  15040. if(ftpbuf[len]== 47) // '/' ascll code: 47
  15041. {
  15042. DEBUG_INFO(" compare '/' all right\n");
  15043. break;
  15044. }
  15045. i=i+1;
  15046. }
  15047. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  15048. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  15049. firmwareFileName[i+1] = 0;
  15050. strncpy(temp, ftpbuf, ftppathlen-i+1);
  15051. pch=strchr(temp,'@');
  15052. if(pch==NULL)
  15053. {
  15054. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15055. protocol, host, &port, path);
  15056. strcpy(user,"anonymous");
  15057. strcpy(password,"");
  15058. }
  15059. else
  15060. {
  15061. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  15062. protocol, user, password, host, &port, path);
  15063. }
  15064. sscanf(host,"%[^/]%s",host1, path1);
  15065. sprintf(ftppath,"%s", path1);
  15066. //DEBUG_INFO("protocol =%s\n",protocol);
  15067. //DEBUG_INFO("user =%s\n",user);
  15068. //DEBUG_INFO("password =%s\n",password);
  15069. //DEBUG_INFO("host1 =%s\n",host1);
  15070. //DEBUG_INFO("port =%d\n",port);
  15071. //DEBUG_INFO("path1 =%s\n",path1);
  15072. //DEBUG_INFO("ftppath=%s\n",ftppath);
  15073. //ftpFile(host, user, password, port, ftppath, fname);
  15074. //download firmware pthred
  15075. if(port == 0)
  15076. {
  15077. port = 21;
  15078. }
  15079. do
  15080. {
  15081. sleep(1);
  15082. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15083. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  15084. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15085. sleep(1);
  15086. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15087. if(!isSuccess)
  15088. {
  15089. //BulldogUtil.sleepMs(interval*1000);
  15090. DEBUG_INFO("Update firmware request and download file fail.\n");
  15091. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15092. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15093. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15094. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  15095. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15096. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15097. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15098. }
  15099. else
  15100. {
  15101. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15102. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  15103. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15104. }
  15105. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15106. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15107. }
  15108. else
  15109. {
  15110. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15111. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15112. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15113. sleep(1);
  15114. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15115. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15116. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15117. }
  15118. // Verify firmware image signature
  15119. struct stat st;
  15120. FILE *fp = fopen("/tmp/signingFirmwareUpdate.crt", "w");
  15121. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  15122. fclose(fp);
  15123. system("openssl x509 -pubkey -noout -in /tmp/signingFirmwareUpdate.crt > /tmp/signingFirmwareUpdate.key");
  15124. fp = fopen("/tmp/signingFirmwareUpdate.sign", "w");
  15125. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  15126. fclose(fp);
  15127. system("openssl base64 -d -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15128. stat("/tmp/signingFirmwareUpdate.sign.256", &st);
  15129. if(st.st_size == 0)
  15130. system("openssl base64 -d -A -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15131. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "Downloaded") != NULL)
  15132. {
  15133. sprintf(temp ,"openssl dgst -verify /tmp/signingFirmwareUpdate.key -signature /tmp/signingFirmwareUpdate.sign.256 /mnt/%s", firmwareFileName);
  15134. fp = popen(temp, "r");
  15135. if(fp)
  15136. {
  15137. while(fgets(temp, sizeof(temp), fp) != NULL)
  15138. {
  15139. if(strstr(temp, "Verified OK") != NULL)
  15140. {
  15141. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15142. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "SignatureVerified");
  15143. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15144. }
  15145. else
  15146. {
  15147. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15148. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InvalidSignature");
  15149. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15150. sleep(1);
  15151. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15152. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InstallationFailed");
  15153. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15154. sleep(1);
  15155. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15156. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15157. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15158. }
  15159. break;
  15160. }
  15161. }
  15162. pclose(fp);
  15163. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "SignatureVerified") != NULL)ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  15164. }
  15165. interLock.isUpdateFirmwareGoing = 0;
  15166. pthread_exit(NULL);
  15167. }
  15168. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  15169. {
  15170. mtrace();
  15171. int result = PASS;
  15172. pthread_t t;
  15173. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  15174. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Accepted");
  15175. sendSignedUpdateFirmwareConfirmation(uuid);
  15176. if(!interLock.isUpdateFirmwareGoing)
  15177. {
  15178. interLock.isUpdateFirmwareGoing = 1;
  15179. pthread_create(&t, NULL, SignedUpdateFirmwareProcess, payload);
  15180. sleep(1);
  15181. }
  15182. else
  15183. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  15184. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareConf = 1;
  15185. return result;
  15186. }
  15187. int handleUnknownRequest(char *uuid, char *payload)
  15188. {
  15189. mtrace();
  15190. int result = PASS;
  15191. DEBUG_INFO("handleUnknownRequest...\n");
  15192. sendUnknownConfirmation(uuid);
  15193. return result;
  15194. }
  15195. //==========================================
  15196. // Handle server response routine
  15197. //==========================================
  15198. void handleAuthorizeResponse(char *payload, int gun_index)
  15199. {
  15200. mtrace();
  15201. char expiryDatestr[36]={0};
  15202. char parentIdTagstr[21]={0};
  15203. char statusstr[20]={0};
  15204. int expiryDateISNULL=FALSE;
  15205. int parentIdTagISNULL=FALSE;
  15206. DEBUG_INFO("handleAuthorizeResponse...\n");
  15207. json_object *Authorize;
  15208. Authorize = json_tokener_parse(payload);
  15209. if(!is_error(Authorize))
  15210. {
  15211. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  15212. {
  15213. // Required data
  15214. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  15215. // Optional data
  15216. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  15217. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  15218. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  15219. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  15220. }
  15221. }
  15222. json_object_put(Authorize);
  15223. if(expiryDateISNULL == FALSE)
  15224. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  15225. if(parentIdTagISNULL == FALSE)
  15226. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  15227. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  15228. //Update idTag information to authorization cache if supproted
  15229. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  15230. {
  15231. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  15232. }
  15233. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  15234. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  15235. authorizeRetryTimes = 0;
  15236. }
  15237. void handleBootNotificationResponse(char *payload, int gun_index)
  15238. {
  15239. mtrace();
  15240. char statusStr[12]={0};
  15241. char currentTimeStr[30]={0};
  15242. int intervalInt = 0;
  15243. DEBUG_INFO("handleBootNotificationResponse...\n");
  15244. json_object *BootNotification;
  15245. BootNotification = json_tokener_parse(payload);
  15246. if(!is_error(BootNotification))
  15247. {
  15248. // Required data
  15249. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  15250. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  15251. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  15252. }
  15253. json_object_put(BootNotification);
  15254. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15255. BootNotificationInterval = intervalInt;
  15256. //write back to ShmOCPP16Data->BootNotification
  15257. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  15258. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15259. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  15260. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  15261. {
  15262. BootNotificationInterval = 0;
  15263. if((intervalInt == 0) || (intervalInt >= 10))
  15264. {
  15265. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  15266. HeartBeatWaitTime = intervalInt;
  15267. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  15268. }
  15269. server_sign = TRUE;
  15270. server_pending =FALSE;
  15271. }
  15272. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  15273. {
  15274. server_pending = TRUE;
  15275. }
  15276. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  15277. srand(time(NULL));
  15278. refreshStartTimer(&clientTime.Heartbeat);
  15279. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  15280. SetOcppConnStatus(TRUE);
  15281. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  15282. }
  15283. void handleDataTransferResponse(char *payload, int gun_index)
  15284. {
  15285. json_object *DataTransfer = json_tokener_parse(payload);
  15286. if(!is_error(DataTransfer))
  15287. {
  15288. // Required data
  15289. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  15290. // Optional data
  15291. if(json_object_object_get(DataTransfer, "data") != NULL)
  15292. {
  15293. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15294. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15295. if(!is_error(Data))
  15296. {
  15297. if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Authorize") != NULL)
  15298. {
  15299. if(json_object_object_get(Data, "certificateStatus") != NULL)
  15300. {
  15301. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "%s", json_object_get_string(json_object_object_get(Data, "certificateStatus")));
  15302. }
  15303. if(json_object_object_get(Data, "idTokenInfo") != NULL)
  15304. {
  15305. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Data, "certificateStatus"), "status")));
  15306. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "cacheExpiryDateTime") != NULL)
  15307. {
  15308. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.cacheExpiryDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Data, "certificateStatus"), "cacheExpiryDateTime")));
  15309. }
  15310. }
  15311. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  15312. }
  15313. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Get15118EVCertificate") != NULL)
  15314. {
  15315. if(json_object_object_get(Data, "status") != NULL)
  15316. {
  15317. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15318. }
  15319. if(json_object_object_get(Data, "exiResponse") != NULL)
  15320. {
  15321. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_exiResponse, "%s", json_object_get_string(json_object_object_get(Data, "exiResponse")));
  15322. }
  15323. ShmOCPP16Data->v2g_extend.Get15118EVCertificateConf = 1;
  15324. }
  15325. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "GetCertificateStatus") != NULL)
  15326. {
  15327. if(json_object_object_get(Data, "status") != NULL)
  15328. {
  15329. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15330. }
  15331. if(json_object_object_get(Data, "ocspResult") != NULL)
  15332. {
  15333. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_ocspResult, "%s", json_object_get_string(json_object_object_get(Data, "ocspResult")));
  15334. }
  15335. ShmOCPP16Data->v2g_extend.GetCertificateStatusConf = 1;
  15336. }
  15337. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "SignCertificate") != NULL)
  15338. {
  15339. sprintf((char*)ShmOCPP16Data->v2g_extend.SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15340. ShmOCPP16Data->v2g_extend.SignCertificateConf = 1;
  15341. }
  15342. else
  15343. {
  15344. if(json_object_object_get(Data, "msgId") != NULL)
  15345. {
  15346. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  15347. {
  15348. 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")));
  15349. }
  15350. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  15351. {
  15352. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15353. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  15354. }
  15355. }
  15356. }
  15357. }
  15358. json_object_put(Data);
  15359. }
  15360. }
  15361. json_object_put(DataTransfer);
  15362. }
  15363. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  15364. {
  15365. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  15366. //struct json_object *obj;
  15367. // obj = json_tokener_parse(payload);
  15368. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  15369. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  15370. //No fields are defined.
  15371. }
  15372. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15373. {
  15374. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  15375. //struct json_object *obj;
  15376. // obj = json_tokener_parse(payload);
  15377. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  15378. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  15379. //No fields are defined.
  15380. }
  15381. void handleHeartbeatResponse(char *payload, int gun_index)
  15382. {
  15383. mtrace();
  15384. DEBUG_INFO("handleHeartbeatResponse...\n");
  15385. json_object *Heartbeat;
  15386. Heartbeat = json_tokener_parse(payload);
  15387. if(!is_error(Heartbeat))
  15388. {
  15389. // Required data
  15390. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  15391. }
  15392. json_object_put(Heartbeat);
  15393. if(FirstHeartBeat == 0)
  15394. {
  15395. FirstHeartBeat = 1;
  15396. DEBUG_INFO("FirstHeartBeat \n");
  15397. }
  15398. HeartBeatWithNOResponse = 0;
  15399. refreshStartTimer(&clientTime.Heartbeat);
  15400. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  15401. }
  15402. void handleMeterValuesResponse(char *payload, int gun_index)
  15403. {
  15404. mtrace();
  15405. DEBUG_INFO("handleMeterValuesResponse...\n");
  15406. isQueueSendable = 1;
  15407. }
  15408. void handleStartTransactionResponse(char *payload, int gun_index)
  15409. {
  15410. mtrace();
  15411. //int transactionIdInt = 0;
  15412. FILE *outfile;
  15413. char data[100]={0};
  15414. DEBUG_INFO("handleStartTransactionResponse...\n");
  15415. json_object *StartTransaction;
  15416. StartTransaction = json_tokener_parse(payload);
  15417. if(!is_error(StartTransaction))
  15418. {
  15419. // Required data
  15420. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  15421. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  15422. // Optional data
  15423. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  15424. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  15425. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15426. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  15427. }
  15428. json_object_put(StartTransaction);
  15429. OCPP_updatePeriodEnergy(gun_index);
  15430. //-----------Start : write to the Queue TransactionId file -----------------//
  15431. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  15432. {}
  15433. else
  15434. {
  15435. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  15436. if(log == NULL)
  15437. {
  15438. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  15439. return ;
  15440. }
  15441. else
  15442. {
  15443. fclose(log);
  15444. }
  15445. }
  15446. // open file for writing
  15447. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  15448. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  15449. {
  15450. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  15451. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  15452. fputs(data, outfile);
  15453. fclose (outfile);
  15454. }
  15455. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15456. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15457. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  15458. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  15459. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15460. isQueueSendable = 1;
  15461. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  15462. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  15463. }
  15464. void handleStatusNotificationResponse(char *payload, int gun_index)
  15465. {
  15466. mtrace();
  15467. DEBUG_INFO("handleStatusNotificationResponse...\n");
  15468. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15469. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15470. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  15471. }
  15472. void handleStopTransactionnResponse(char *payload, int gun_index)
  15473. {
  15474. mtrace();
  15475. DEBUG_INFO("handleStopTransactionnResponse...\n");
  15476. json_object *StopTransaction;
  15477. StopTransaction = json_tokener_parse(payload);
  15478. if(!is_error(StopTransaction))
  15479. {
  15480. // Optional data
  15481. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  15482. {
  15483. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  15484. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  15485. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  15486. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15487. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  15488. }
  15489. }
  15490. json_object_put(StopTransaction);
  15491. isQueueSendable = 1;
  15492. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  15493. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  15494. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15495. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15496. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  15497. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  15498. }
  15499. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  15500. {
  15501. mtrace();
  15502. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  15503. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  15504. }
  15505. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  15506. {
  15507. mtrace();
  15508. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  15509. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  15510. }
  15511. void handleSignCertificateResponse(char *payload, int gun_index)
  15512. {
  15513. mtrace();
  15514. DEBUG_INFO("handleSignCertificateResponse...\n");
  15515. json_object *SignCertificate;
  15516. SignCertificate = json_tokener_parse(payload);
  15517. if(!is_error(SignCertificate))
  15518. {
  15519. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  15520. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  15521. }
  15522. json_object_put(SignCertificate);
  15523. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  15524. }
  15525. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15526. {
  15527. mtrace();
  15528. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  15529. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  15530. }
  15531. //==========================================
  15532. // Handle Error routine
  15533. //==========================================
  15534. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  15535. {
  15536. mtrace();
  15537. #ifdef SystemLogMessage
  15538. DEBUG_INFO("errorCode: %s\n", errorCode);
  15539. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  15540. DEBUG_INFO("errorDetails: %s\n", payload);
  15541. #endif
  15542. }
  15543. //===============================================
  15544. // Common routine
  15545. //===============================================
  15546. int initialConfigurationTable(void)
  15547. {
  15548. //clock_t start_t, end_t, total_t;
  15549. FILE *fp;
  15550. FILE *outfile;
  15551. char str[512]={0};
  15552. char sstr[256]={0};
  15553. int c = 0;
  15554. char *loc;
  15555. int confVersion = 21;
  15556. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  15557. //start_t = clock();
  15558. //printf("Starting of the program, start_t = %ld\n", start_t);
  15559. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  15560. // Check configuration file size is correct
  15561. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  15562. {
  15563. struct stat st;
  15564. stat("/Storage/OCPP/OCPPConfiguration", &st);
  15565. if(st.st_size < 3100)
  15566. {
  15567. system("rm -f /Storage/OCPP/OCPPConfiguration");
  15568. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  15569. }
  15570. }
  15571. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  15572. {
  15573. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15574. if(outfile == NULL)
  15575. {
  15576. DEBUG_INFO("Error opening file\n");
  15577. return FALSE;
  15578. }
  15579. /*Core Profile*/
  15580. //AllowOfflineTxForUnknownId
  15581. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  15584. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15585. //AuthorizationCacheEnabled
  15586. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15589. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15590. //AuthorizeRemoteTxRequests
  15591. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  15592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  15594. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15595. //BlinkRepeat
  15596. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15599. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15600. //ClockAlignedDataInterval
  15601. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15605. //ConnectionTimeOut
  15606. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15608. if(ShmSysConfigAndInfo->SysConfig.ModelName[3]=='J')
  15609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "55" );
  15610. else
  15611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15612. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15613. //GetConfigurationMaxKeys
  15614. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15616. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  15617. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15618. // HeartbeatInterval
  15619. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  15622. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15623. // LightIntensity
  15624. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15627. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15628. // LocalAuthorizeOffline
  15629. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  15630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15632. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15633. // LocalPreAuthorize
  15634. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  15635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15638. // MaxEnergyOnInvalidId
  15639. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15643. // MeterValuesAlignedData
  15644. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15646. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15647. 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" );
  15648. else
  15649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15650. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15651. // MeterValuesAlignedDataMaxLength
  15652. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15654. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  15656. else
  15657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  15658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15659. // MeterValuesSampledData
  15660. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15662. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15663. 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" );
  15664. else
  15665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15666. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15667. // MeterValuesSampledDataMaxLength
  15668. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15670. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  15672. else
  15673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  15674. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15675. // MeterValueSampleInterval
  15676. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  15679. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15680. // MinimumStatusDuration
  15681. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  15684. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  15685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15686. // NumberOfConnectors
  15687. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15689. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15690. {
  15691. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15692. }
  15693. else
  15694. {
  15695. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15696. }
  15697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15698. // ResetRetries
  15699. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15702. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15703. // ConnectorPhaseRotation
  15704. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15707. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15708. // ConnectorPhaseRotationMaxLength
  15709. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15712. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15713. // StopTransactionOnEVSideDisconnect
  15714. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  15715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15717. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15718. // StopTransactionOnInvalidId
  15719. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  15720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15721. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15722. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15723. // StopTxnAlignedData
  15724. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  15727. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15728. // StopTxnAlignedDataMaxLength
  15729. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  15732. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15733. // StopTxnSampledData
  15734. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15736. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  15738. else
  15739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  15740. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15741. // StopTxnSampledDataMaxLength
  15742. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15744. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15745. {
  15746. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  15747. }
  15748. else
  15749. {
  15750. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  15751. }
  15752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15753. // SupportedFeatureProfiles
  15754. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15758. // SupportedFeatureProfilesMaxLength
  15759. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15762. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15763. // TransactionMessageAttempts
  15764. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15767. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15768. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15769. // TransactionMessageRetryInterval
  15770. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15773. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15775. // UnlockConnectorOnEVSideDisconnect
  15776. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  15777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15779. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15780. // WebSocketPingInterval
  15781. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15785. // QueueOffLineMeterValues
  15786. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  15787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  15789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15790. // AuthorizationKey
  15791. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  15794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15795. // SecurityProfile
  15796. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15798. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  15799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15800. // DefaultPrice
  15801. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15805. // CustomDisplayCostAndPrice
  15806. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15810. // CustomIdleFeeAfterStop
  15811. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15814. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15815. // TimeOffset
  15816. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  15819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15820. // NextTimeOffsetTransitionDateTime
  15821. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  15824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15825. // TimeOffsetNextTransition
  15826. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  15829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15830. // SystemUptimeSec
  15831. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15835. // FreeVend
  15836. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15840. // FreeVendIdtag
  15841. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15844. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15845. // OcppServer
  15846. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15848. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15849. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15850. // MaintainServer
  15851. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15853. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  15854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15855. // StatusNotificationPeriodically
  15856. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  15857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15859. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15860. // StatusNotificationInterval
  15861. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15865. // PreAuthAmount
  15866. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  15869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15870. // isEnableLocalPowerSharing
  15871. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15873. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15875. // PowerSharingServerIP
  15876. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15878. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  15879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15880. // EVCCID_PREFIX
  15881. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15885. // OffLineMaxChargingPower
  15886. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  15889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15890. // Configuration Version
  15891. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  15892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15893. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  15894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15895. // Charging profile refresh interval
  15896. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  15897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  15898. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  15899. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  15900. // CpoName
  15901. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  15902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  15903. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "Zerova");
  15904. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  15905. // Ocpp Software certificated version
  15906. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  15907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  15908. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  15909. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  15910. //* Local Auth List Management Profile*/
  15911. #if 0
  15912. //For OCTT Test Case
  15913. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  15915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15916. #endif
  15917. #if 1
  15918. //LocalAuthListEnabled
  15919. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15922. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15923. #endif
  15924. //LocalAuthListMaxLength
  15925. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  15928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15929. //SendLocalListMaxLength
  15930. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  15933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15934. //ReserveConnectorZeroSupported
  15935. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15939. //* Smart Charging Profile */
  15940. //ChargeProfileMaxStackLevel
  15941. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  15944. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15945. // ChargingScheduleAllowedChargingRateUnit
  15946. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  15949. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15950. // ChargingScheduleMaxPeriods
  15951. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15954. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15955. // ConnectorSwitch3to1PhaseSupported
  15956. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  15959. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15960. // MaxChargingProfilesInstalled
  15961. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  15964. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15965. fclose(outfile);
  15966. }
  15967. else
  15968. {
  15969. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  15970. char keystr[60]={0};
  15971. char readonlystr[10]={0};
  15972. char valuestr[256]={0};
  15973. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  15974. if(fp == NULL) {
  15975. DEBUG_INFO("Error opening file");
  15976. return FALSE;
  15977. }
  15978. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  15979. {
  15980. //DEBUG_INFO("Get Configuration \n");
  15981. if(strlen(str) > 0)
  15982. {
  15983. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15984. //*************************key*********************************/
  15985. if(strstr(str, "key") != NULL)
  15986. {
  15987. loc = strstr(str, "key");
  15988. c = 0;
  15989. memset(sstr ,0, ARRAY_SIZE(sstr) );
  15990. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  15991. {
  15992. sstr[c] = loc[strlen("key")+3+c];
  15993. c++;
  15994. }
  15995. sstr[c] = '\0';
  15996. strcpy(keystr,sstr);
  15997. }
  15998. //*************************readonly*********************************/
  15999. if(strstr(str, "readonly") != NULL)
  16000. {
  16001. loc = strstr(str, "readonly");
  16002. c = 0;
  16003. memset(sstr ,0, ARRAY_SIZE(sstr) );
  16004. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  16005. {
  16006. sstr[c] = loc[strlen("readonly")+2+c];
  16007. c++;
  16008. }
  16009. sstr[c] = '\0';
  16010. strcpy(readonlystr,sstr);
  16011. }
  16012. //*************************value*********************************/
  16013. if(strstr(str, "value") != NULL)
  16014. {
  16015. loc = strstr(str, "value");
  16016. c = 0;
  16017. memset(sstr ,0, ARRAY_SIZE(sstr) );
  16018. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  16019. {
  16020. sstr[c] = loc[strlen("value")+3+c];
  16021. c++;
  16022. }
  16023. sstr[c] = '\0';
  16024. strcpy(valuestr,sstr);
  16025. }
  16026. // DEBUG_INFO("keystr=%s\n",keystr);
  16027. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  16028. // DEBUG_INFO("valuestr=%s\n",valuestr);
  16029. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  16030. {
  16031. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  16032. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16033. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  16034. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  16035. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  16036. }
  16037. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  16038. {
  16039. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  16040. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16041. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  16042. }
  16043. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  16044. {
  16045. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16046. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  16047. }
  16048. if(strcmp(keystr, "BlinkRepeat") == 0)
  16049. {
  16050. //Charger.BlinkRepeat = Integer.parseInt(value);
  16051. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  16053. }
  16054. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  16055. {
  16056. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  16058. }
  16059. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  16060. {
  16061. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16062. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  16063. }
  16064. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  16065. {
  16066. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16067. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  16068. }
  16069. if(strcmp(keystr, "HeartbeatInterval") == 0)
  16070. {
  16071. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16072. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  16073. HeartBeatWaitTime = atoi(valuestr);
  16074. }
  16075. if(strcmp(keystr, "LightIntensity") == 0)
  16076. {
  16077. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16078. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  16079. }
  16080. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  16081. {
  16082. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16083. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  16084. }
  16085. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  16086. {
  16087. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16088. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  16089. }
  16090. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  16091. {
  16092. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16093. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  16094. }
  16095. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  16096. {
  16097. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16098. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  16099. }
  16100. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  16101. {
  16102. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  16104. }
  16105. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  16106. {
  16107. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16108. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  16109. }
  16110. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  16111. {
  16112. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  16114. }
  16115. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  16116. {
  16117. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16118. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  16119. }
  16120. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  16121. {
  16122. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  16124. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  16125. }
  16126. if(strcmp(keystr, "NumberOfConnectors") == 0)
  16127. {
  16128. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16129. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  16130. }
  16131. if(strcmp(keystr, "ResetRetries") == 0)
  16132. {
  16133. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16134. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  16135. }
  16136. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  16137. {
  16138. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16139. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  16140. }
  16141. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  16142. {
  16143. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16144. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  16145. }
  16146. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  16147. {
  16148. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16149. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  16150. }
  16151. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  16152. {
  16153. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16154. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  16155. }
  16156. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  16157. {
  16158. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  16160. }
  16161. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  16162. {
  16163. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16164. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16165. }
  16166. if(strcmp(keystr, "StopTxnSampledData") == 0)
  16167. {
  16168. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16169. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  16170. }
  16171. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  16172. {
  16173. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16174. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16175. }
  16176. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  16177. {
  16178. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  16180. }
  16181. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  16182. {
  16183. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16184. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  16185. }
  16186. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  16187. {
  16188. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16189. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  16190. TransactionMessageAttemptsValue = atoi(valuestr);
  16191. }
  16192. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  16193. {
  16194. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16195. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  16196. TransactionMessageRetryIntervalValue = atoi(valuestr);
  16197. }
  16198. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  16199. {
  16200. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16201. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  16202. }
  16203. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  16204. {
  16205. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16206. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  16207. }
  16208. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  16209. {
  16210. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16211. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  16212. }
  16213. if(strcmp(keystr, "AuthorizationKey") == 0)
  16214. {
  16215. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16216. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  16217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  16218. }
  16219. if(strcmp(keystr, "SecurityProfile") == 0)
  16220. {
  16221. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  16223. }
  16224. if(strcmp(keystr, "DefaultPrice") == 0)
  16225. {
  16226. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16227. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  16228. }
  16229. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  16230. {
  16231. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16232. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  16233. }
  16234. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  16235. {
  16236. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16237. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  16238. }
  16239. if(strcmp(keystr, "TimeOffset") == 0)
  16240. {
  16241. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16242. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  16243. }
  16244. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  16245. {
  16246. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16247. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  16248. }
  16249. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  16250. {
  16251. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16252. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  16253. }
  16254. if(strcmp(keystr, "SystemUptimeSec") == 0)
  16255. {
  16256. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16257. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  16258. }
  16259. if(strcmp(keystr, "FreeVend") == 0)
  16260. {
  16261. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  16263. }
  16264. if(strcmp(keystr, "FreeVendIdtag") == 0)
  16265. {
  16266. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16267. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  16268. }
  16269. if(strcmp(keystr, "OcppServer") == 0)
  16270. {
  16271. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16272. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  16273. }
  16274. if(strcmp(keystr, "MaintainServer") == 0)
  16275. {
  16276. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16277. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  16278. }
  16279. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  16280. {
  16281. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16282. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  16283. }
  16284. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  16285. {
  16286. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16287. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  16288. }
  16289. if(strcmp(keystr, "PreAuthAmount") == 0)
  16290. {
  16291. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16292. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  16293. }
  16294. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  16295. {
  16296. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16297. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  16298. }
  16299. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  16300. {
  16301. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16302. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  16303. }
  16304. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  16305. {
  16306. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16307. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  16308. }
  16309. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  16310. {
  16311. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16312. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  16313. }
  16314. if(strcmp(keystr, "ConfigurationVersion") == 0)
  16315. {
  16316. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  16318. }
  16319. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  16320. {
  16321. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  16323. }
  16324. if(strcmp(keystr, "CpoName") == 0)
  16325. {
  16326. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", valuestr);
  16328. }
  16329. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  16330. {
  16331. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  16333. }
  16334. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  16335. {
  16336. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  16338. }
  16339. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  16340. {
  16341. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  16343. }
  16344. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  16345. {
  16346. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16347. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  16348. }
  16349. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  16350. {
  16351. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16352. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  16353. }
  16354. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  16355. {
  16356. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16357. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  16358. }
  16359. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16360. {
  16361. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16362. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  16363. }
  16364. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  16365. {
  16366. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16367. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  16368. }
  16369. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  16370. {
  16371. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16372. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  16373. }
  16374. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  16375. {
  16376. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16377. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  16378. }
  16379. }
  16380. }
  16381. fclose(fp);
  16382. }
  16383. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  16384. {
  16385. return PASS;
  16386. }
  16387. else
  16388. {
  16389. return FAIL;
  16390. }
  16391. }
  16392. void StoreConfigurationTable(void)
  16393. {
  16394. FILE *outfile;
  16395. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  16396. if(outfile == NULL)
  16397. {
  16398. DEBUG_INFO("Error opening file");
  16399. return ;
  16400. }
  16401. /*Core Profile*/
  16402. //AllowOfflineTxForUnknownId
  16403. /*
  16404. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  16405. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  16406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  16407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  16408. */
  16409. //DEBUG_INFO("data=%s\n",data);
  16410. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  16411. //AuthorizationCacheEnabled
  16412. /*
  16413. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  16414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  16415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  16416. */
  16417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  16418. //AuthorizeRemoteTxRequests
  16419. /*
  16420. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  16421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  16422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  16423. */
  16424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  16425. //BlinkRepeat
  16426. /*
  16427. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  16428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  16429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  16430. */
  16431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  16432. //ClockAlignedDataInterval
  16433. /*
  16434. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  16435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  16436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  16437. */
  16438. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  16439. //ConnectionTimeOut
  16440. /*
  16441. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  16442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  16443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  16444. */
  16445. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  16446. //GetConfigurationMaxKeys
  16447. /*
  16448. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  16449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  16450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  16451. */
  16452. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  16453. // HeartbeatInterval
  16454. /*
  16455. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  16456. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  16457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  16458. */
  16459. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  16460. // LightIntensity
  16461. /*
  16462. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  16463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  16464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  16465. */
  16466. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  16467. // LocalAuthorizeOffline
  16468. /*
  16469. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  16470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  16471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  16472. */
  16473. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16474. // LocalPreAuthorize
  16475. /*
  16476. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  16477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  16478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  16479. */
  16480. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  16481. // MaxEnergyOnInvalidId
  16482. /*
  16483. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  16484. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  16485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  16486. */
  16487. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  16488. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  16489. // MeterValuesAlignedData
  16490. /*
  16491. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  16492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  16493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16494. */
  16495. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  16496. // MeterValuesAlignedDataMaxLength
  16497. /*
  16498. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  16499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  16500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  16501. */
  16502. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  16503. // MeterValuesSampledData
  16504. /*
  16505. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  16506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  16507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16508. */
  16509. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  16510. // MeterValuesSampledDataMaxLength
  16511. /*
  16512. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  16513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  16514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  16515. */
  16516. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  16517. // MeterValueSampleInterval
  16518. /*
  16519. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  16520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  16521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  16522. */
  16523. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  16524. // MinimumStatusDuration
  16525. /*
  16526. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  16527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  16528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  16529. */
  16530. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16531. // NumberOfConnectors
  16532. /*
  16533. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  16534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  16535. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16536. {
  16537. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  16538. }
  16539. else
  16540. {
  16541. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  16542. }
  16543. */
  16544. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  16545. // ResetRetries
  16546. /*
  16547. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  16548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  16549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  16550. */
  16551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  16552. // ConnectorPhaseRotation
  16553. /*
  16554. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  16555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  16556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  16557. */
  16558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  16559. // ConnectorPhaseRotationMaxLength
  16560. /*
  16561. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  16562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  16563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  16564. */
  16565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  16566. // StopTransactionOnEVSideDisconnect
  16567. /*
  16568. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  16569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  16570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  16571. */
  16572. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  16573. // StopTransactionOnInvalidId
  16574. /*
  16575. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  16576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  16577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  16578. */
  16579. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  16580. // StopTxnAlignedData
  16581. /*
  16582. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  16583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  16584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  16585. */
  16586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  16587. // StopTxnAlignedDataMaxLength
  16588. /*
  16589. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  16590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  16591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  16592. */
  16593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  16594. // StopTxnSampledData
  16595. /*
  16596. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  16597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  16598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  16599. */
  16600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  16601. // StopTxnSampledDataMaxLength
  16602. /*
  16603. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  16604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  16605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  16606. */
  16607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  16608. // SupportedFeatureProfiles
  16609. /*
  16610. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  16611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  16612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  16613. */
  16614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  16615. // SupportedFeatureProfilesMaxLength
  16616. /*
  16617. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  16618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  16619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  16620. */
  16621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  16622. // TransactionMessageAttempts
  16623. /*
  16624. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  16625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  16626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  16627. */
  16628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16629. // TransactionMessageRetryInterval
  16630. /*
  16631. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  16632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  16633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  16634. */
  16635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16636. // UnlockConnectorOnEVSideDisconnect
  16637. /*
  16638. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  16639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  16640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  16641. */
  16642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  16643. // WebSocketPingInterval
  16644. /*
  16645. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  16646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  16647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  16648. */
  16649. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16650. // QueueOffLineMeterValues
  16651. /*
  16652. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  16653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  16654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  16655. */
  16656. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  16657. // AuthorizationKey
  16658. /*
  16659. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  16660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  16661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  16662. */
  16663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16664. // SecurityProfile
  16665. /*
  16666. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  16667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  16668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  16669. */
  16670. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16671. // DefaultPrice
  16672. /*
  16673. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  16674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  16675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  16676. */
  16677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16678. // CustomDisplayCostAndPrice
  16679. /*
  16680. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  16681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  16682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  16683. */
  16684. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  16685. // CustomIdleFeeAfterStop
  16686. /*
  16687. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  16688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  16689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  16690. */
  16691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  16692. // TimeOffset
  16693. /*
  16694. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  16695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  16696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  16697. */
  16698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  16699. // NextTimeOffsetTransitionDateTime
  16700. /*
  16701. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  16702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  16703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  16704. */
  16705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  16706. // TimeOffsetNextTransition
  16707. /*
  16708. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  16709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  16710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  16711. */
  16712. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  16713. // SystemUptimeSec
  16714. /*
  16715. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  16716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  16717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  16718. */
  16719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  16720. // FreeVend
  16721. /*
  16722. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  16723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  16724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  16725. */
  16726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  16727. // FreeVendIdtag
  16728. /*
  16729. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  16730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  16731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  16732. */
  16733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16734. // OcppServer
  16735. /*
  16736. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  16737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  16738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  16739. */
  16740. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16741. // MaintainServer
  16742. /*
  16743. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  16744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  16745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  16746. */
  16747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16748. // StatusNotificationPeriodically
  16749. /*
  16750. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  16751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  16752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  16753. */
  16754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  16755. // StatusNotificationInterval
  16756. /*
  16757. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  16758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  16759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  16760. */
  16761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  16762. // PreAuthAmount
  16763. /*
  16764. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  16765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  16766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  16767. */
  16768. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  16769. // isEnableLocalPowerSharing
  16770. /*
  16771. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  16772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  16773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  16774. */
  16775. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  16776. // PowerSharingServerIP
  16777. /*
  16778. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  16779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  16780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  16781. */
  16782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  16783. // EVCCID_PREFIX
  16784. /*
  16785. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  16786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  16787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  16788. */
  16789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  16790. // OffLineMaxChargingPower
  16791. /*
  16792. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  16793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  16794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  16795. */
  16796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  16797. // ConfigurationVersion
  16798. /*
  16799. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  16800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  16801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  16802. */
  16803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  16804. // CharingProfileRefreshInterval
  16805. /*
  16806. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  16807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  16808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  16809. */
  16810. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  16811. // CpoName
  16812. /*
  16813. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  16814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  16815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "" );
  16816. */
  16817. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  16818. // OcppSoftwareVersion
  16819. /*
  16820. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  16821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  16822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  16823. */
  16824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  16825. //* Local Auth List Management Profile*/
  16826. //LocalAuthListEnabled
  16827. /*
  16828. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  16829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  16830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  16831. */
  16832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16833. //LocalAuthListMaxLength
  16834. /*
  16835. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  16836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  16837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  16838. */
  16839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  16840. //SendLocalListMaxLength
  16841. /*
  16842. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  16843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  16844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  16845. */
  16846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  16847. //ReserveConnectorZeroSupported
  16848. /*
  16849. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  16850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  16851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  16852. */
  16853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16854. //* Smart Charging Profile */
  16855. //ChargeProfileMaxStackLevel
  16856. /*
  16857. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  16858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  16859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  16860. */
  16861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16862. // ChargingScheduleAllowedChargingRateUnit
  16863. /*
  16864. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  16865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  16866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  16867. */
  16868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16869. // ChargingScheduleMaxPeriods
  16870. /*
  16871. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  16872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  16873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  16874. */
  16875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16876. // ConnectorSwitch3to1PhaseSupported
  16877. /*
  16878. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  16879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  16880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  16881. */
  16882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16883. // MaxChargingProfilesInstalled
  16884. /*
  16885. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  16886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  16887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  16888. */
  16889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16890. fclose(outfile);
  16891. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16892. }
  16893. void getKeyValue(char *keyReq)
  16894. {
  16895. int isEmpty = FALSE;
  16896. int isKnowKey = FALSE;
  16897. DEBUG_INFO("keyReq = %s\n", keyReq);
  16898. if((keyReq == NULL) || (strlen(keyReq) == 0))
  16899. isEmpty = TRUE;
  16900. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  16901. {
  16902. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  16903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  16904. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16905. {
  16906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  16907. }
  16908. else
  16909. {
  16910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  16911. }
  16912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  16913. isKnowKey = TRUE;
  16914. }
  16915. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  16916. {
  16917. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  16918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  16919. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16920. {
  16921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  16922. }
  16923. else
  16924. {
  16925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  16926. }
  16927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  16928. isKnowKey = TRUE;
  16929. }
  16930. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  16931. {
  16932. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  16933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  16934. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16935. {
  16936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  16937. }
  16938. else
  16939. {
  16940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  16941. }
  16942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  16943. isKnowKey = TRUE;
  16944. }
  16945. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  16946. {
  16947. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  16948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  16949. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16950. {
  16951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  16952. }
  16953. else
  16954. {
  16955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  16956. }
  16957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  16958. isKnowKey = TRUE;
  16959. }
  16960. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  16961. {
  16962. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  16963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  16964. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16965. {
  16966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  16967. }
  16968. else
  16969. {
  16970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  16971. }
  16972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  16973. isKnowKey = TRUE;
  16974. }
  16975. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  16976. {
  16977. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  16978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  16979. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16980. {
  16981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  16982. }
  16983. else
  16984. {
  16985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  16986. }
  16987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  16988. isKnowKey = TRUE;
  16989. }
  16990. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  16991. {
  16992. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  16993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  16994. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16995. {
  16996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  16997. }
  16998. else
  16999. {
  17000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  17001. }
  17002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  17003. isKnowKey = TRUE;
  17004. }
  17005. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  17006. {
  17007. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  17008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  17009. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  17010. {
  17011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  17012. }
  17013. else
  17014. {
  17015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  17016. }
  17017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  17018. isKnowKey = TRUE;
  17019. }
  17020. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  17021. {
  17022. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  17023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  17024. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  17025. {
  17026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  17027. }
  17028. else
  17029. {
  17030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  17031. }
  17032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  17033. isKnowKey = TRUE;
  17034. }
  17035. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  17036. {
  17037. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  17038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  17039. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  17040. {
  17041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  17042. }
  17043. else
  17044. {
  17045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  17046. }
  17047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  17048. isKnowKey = TRUE;
  17049. }
  17050. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  17051. {
  17052. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  17053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  17054. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  17055. {
  17056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  17057. }
  17058. else
  17059. {
  17060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  17061. }
  17062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  17063. isKnowKey = TRUE;
  17064. }
  17065. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  17066. {
  17067. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  17068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  17069. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  17070. {
  17071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17072. }
  17073. else
  17074. {
  17075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17076. }
  17077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  17078. isKnowKey = TRUE;
  17079. }
  17080. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  17081. {
  17082. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  17083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  17084. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  17085. {
  17086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17087. }
  17088. else
  17089. {
  17090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17091. }
  17092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  17093. isKnowKey = TRUE;
  17094. }
  17095. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  17096. {
  17097. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  17098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  17099. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  17100. {
  17101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17102. }
  17103. else
  17104. {
  17105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17106. }
  17107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  17108. isKnowKey = TRUE;
  17109. }
  17110. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  17111. {
  17112. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  17113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  17114. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  17115. {
  17116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  17117. }
  17118. else
  17119. {
  17120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  17121. }
  17122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  17123. isKnowKey = TRUE;
  17124. }
  17125. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  17126. {
  17127. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  17128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  17129. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  17130. {
  17131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17132. }
  17133. else
  17134. {
  17135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17136. }
  17137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  17138. isKnowKey = TRUE;
  17139. }
  17140. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  17141. {
  17142. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  17143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  17144. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  17145. {
  17146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  17147. }
  17148. else
  17149. {
  17150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  17151. }
  17152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  17153. isKnowKey = TRUE;
  17154. }
  17155. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  17156. {
  17157. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  17158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  17159. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  17160. {
  17161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  17162. }
  17163. else
  17164. {
  17165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  17166. }
  17167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  17168. isKnowKey = TRUE;
  17169. }
  17170. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  17171. {
  17172. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  17173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  17174. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  17175. {
  17176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  17177. }
  17178. else
  17179. {
  17180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  17181. }
  17182. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  17183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  17184. isKnowKey = TRUE;
  17185. }
  17186. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  17187. {
  17188. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  17189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  17190. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  17191. {
  17192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  17193. }
  17194. else
  17195. {
  17196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  17197. }
  17198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  17199. isKnowKey = TRUE;
  17200. }
  17201. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  17202. {
  17203. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  17204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  17205. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17206. {
  17207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  17208. }
  17209. else
  17210. {
  17211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  17212. }
  17213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  17214. isKnowKey = TRUE;
  17215. }
  17216. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  17217. {
  17218. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  17219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  17220. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  17221. {
  17222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17223. }
  17224. else
  17225. {
  17226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17227. }
  17228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  17229. isKnowKey = TRUE;
  17230. }
  17231. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  17232. {
  17233. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  17234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  17235. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17236. {
  17237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17238. }
  17239. else
  17240. {
  17241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17242. }
  17243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  17244. isKnowKey = TRUE;
  17245. }
  17246. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  17247. {
  17248. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  17249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  17250. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17251. {
  17252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17253. }
  17254. else
  17255. {
  17256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17257. }
  17258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  17259. isKnowKey = TRUE;
  17260. }
  17261. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  17262. {
  17263. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  17264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  17265. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17266. {
  17267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17268. }
  17269. else
  17270. {
  17271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17272. }
  17273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  17274. isKnowKey = TRUE;
  17275. }
  17276. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  17277. {
  17278. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  17279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  17280. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17281. {
  17282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17283. }
  17284. else
  17285. {
  17286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17287. }
  17288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  17289. isKnowKey = TRUE;
  17290. }
  17291. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  17292. {
  17293. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  17294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  17295. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17296. {
  17297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  17298. }
  17299. else
  17300. {
  17301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  17302. }
  17303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  17304. isKnowKey = TRUE;
  17305. }
  17306. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  17307. {
  17308. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  17309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  17310. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17311. {
  17312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17313. }
  17314. else
  17315. {
  17316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17317. }
  17318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  17319. isKnowKey = TRUE;
  17320. }
  17321. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  17322. {
  17323. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  17324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  17325. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17326. {
  17327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  17328. }
  17329. else
  17330. {
  17331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  17332. }
  17333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  17334. isKnowKey = TRUE;
  17335. }
  17336. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  17337. {
  17338. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  17339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  17340. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17341. {
  17342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17343. }
  17344. else
  17345. {
  17346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17347. }
  17348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  17349. isKnowKey = TRUE;
  17350. }
  17351. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  17352. {
  17353. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  17354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  17355. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17356. {
  17357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  17358. }
  17359. else
  17360. {
  17361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  17362. }
  17363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  17364. isKnowKey = TRUE;
  17365. }
  17366. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  17367. {
  17368. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  17369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  17370. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17371. {
  17372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  17373. }
  17374. else
  17375. {
  17376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  17377. }
  17378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  17379. isKnowKey = TRUE;
  17380. }
  17381. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  17382. {
  17383. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  17384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  17385. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17386. {
  17387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17388. }
  17389. else
  17390. {
  17391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17392. }
  17393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  17394. isKnowKey = TRUE;
  17395. }
  17396. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  17397. {
  17398. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  17399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  17400. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17401. {
  17402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  17403. }
  17404. else
  17405. {
  17406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  17407. }
  17408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  17409. isKnowKey = TRUE;
  17410. }
  17411. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  17412. {
  17413. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  17414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  17415. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17416. {
  17417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  17418. }
  17419. else
  17420. {
  17421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  17422. }
  17423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  17424. isKnowKey = TRUE;
  17425. }
  17426. /*
  17427. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  17428. {
  17429. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  17430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  17431. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  17432. {
  17433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  17434. }
  17435. else
  17436. {
  17437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  17438. }
  17439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  17440. isKnowKey = TRUE;
  17441. }*/
  17442. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  17443. {
  17444. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  17445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  17446. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17447. {
  17448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  17449. }
  17450. else
  17451. {
  17452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  17453. }
  17454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  17455. isKnowKey = TRUE;
  17456. }
  17457. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  17458. {
  17459. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  17460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  17461. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  17462. {
  17463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  17464. }
  17465. else
  17466. {
  17467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  17468. }
  17469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  17470. isKnowKey = TRUE;
  17471. }
  17472. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  17473. {
  17474. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  17475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  17476. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17477. {
  17478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  17479. }
  17480. else
  17481. {
  17482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  17483. }
  17484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  17485. isKnowKey = TRUE;
  17486. }
  17487. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  17488. {
  17489. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  17490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  17491. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17492. {
  17493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  17494. }
  17495. else
  17496. {
  17497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  17498. }
  17499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  17500. isKnowKey = TRUE;
  17501. }
  17502. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  17503. {
  17504. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  17505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  17506. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17507. {
  17508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  17509. }
  17510. else
  17511. {
  17512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  17513. }
  17514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  17515. isKnowKey = TRUE;
  17516. }
  17517. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  17518. {
  17519. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  17520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  17521. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17522. {
  17523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  17524. }
  17525. else
  17526. {
  17527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  17528. }
  17529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  17530. isKnowKey = TRUE;
  17531. }
  17532. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  17533. {
  17534. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  17535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  17536. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17537. {
  17538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  17539. }
  17540. else
  17541. {
  17542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  17543. }
  17544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  17545. isKnowKey = TRUE;
  17546. }
  17547. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  17548. {
  17549. struct sysinfo s_info;
  17550. int error = sysinfo(&s_info);
  17551. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  17552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  17553. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  17554. {
  17555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  17556. }
  17557. else
  17558. {
  17559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  17560. }
  17561. if(error != 0)
  17562. {
  17563. DEBUG_WARN("System uptime get error: %d\n", error);
  17564. }
  17565. else
  17566. {
  17567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  17568. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  17569. }
  17570. isKnowKey = TRUE;
  17571. }
  17572. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  17573. {
  17574. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  17575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  17576. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17577. {
  17578. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  17579. }
  17580. else
  17581. {
  17582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  17583. }
  17584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  17585. isKnowKey = TRUE;
  17586. }
  17587. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  17588. {
  17589. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  17590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  17591. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17592. {
  17593. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  17594. }
  17595. else
  17596. {
  17597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  17598. }
  17599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  17600. isKnowKey = TRUE;
  17601. }
  17602. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  17603. {
  17604. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  17605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  17606. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17607. {
  17608. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  17609. }
  17610. else
  17611. {
  17612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  17613. }
  17614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  17615. isKnowKey = TRUE;
  17616. }
  17617. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  17618. {
  17619. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  17620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  17621. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17622. {
  17623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  17624. }
  17625. else
  17626. {
  17627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  17628. }
  17629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  17630. isKnowKey = TRUE;
  17631. }
  17632. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  17633. {
  17634. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  17635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  17636. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17637. {
  17638. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  17639. }
  17640. else
  17641. {
  17642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  17643. }
  17644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  17645. isKnowKey = TRUE;
  17646. }
  17647. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  17648. {
  17649. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  17650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  17651. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17652. {
  17653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  17654. }
  17655. else
  17656. {
  17657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  17658. }
  17659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  17660. isKnowKey = TRUE;
  17661. }
  17662. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  17663. {
  17664. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  17665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  17666. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17667. {
  17668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  17669. }
  17670. else
  17671. {
  17672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  17673. }
  17674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  17675. isKnowKey = TRUE;
  17676. }
  17677. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  17678. {
  17679. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  17680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  17681. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17682. {
  17683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  17684. }
  17685. else
  17686. {
  17687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  17688. }
  17689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  17690. isKnowKey = TRUE;
  17691. }
  17692. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  17693. {
  17694. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  17695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  17696. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17697. {
  17698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  17699. }
  17700. else
  17701. {
  17702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  17703. }
  17704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  17705. isKnowKey = TRUE;
  17706. }
  17707. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  17708. {
  17709. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  17710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  17711. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17712. {
  17713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  17714. }
  17715. else
  17716. {
  17717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  17718. }
  17719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  17720. isKnowKey = TRUE;
  17721. }
  17722. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  17723. {
  17724. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  17725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  17726. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17727. {
  17728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  17729. }
  17730. else
  17731. {
  17732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  17733. }
  17734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  17735. isKnowKey = TRUE;
  17736. }
  17737. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  17738. {
  17739. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  17740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  17741. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  17742. {
  17743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  17744. }
  17745. else
  17746. {
  17747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  17748. }
  17749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  17750. isKnowKey = TRUE;
  17751. }
  17752. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  17753. {
  17754. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  17755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  17756. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  17757. {
  17758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  17759. }
  17760. else
  17761. {
  17762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  17763. }
  17764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  17765. isKnowKey = TRUE;
  17766. }
  17767. if(isEmpty || strcmp(keyReq, "CpoName") == 0 )
  17768. {
  17769. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CpoName].Item, "CpoName");
  17770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Key, "CpoName");
  17771. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  17772. {
  17773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "0"/*"FALSE"*/);
  17774. }
  17775. else
  17776. {
  17777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "1"/*"TRUE"*/);
  17778. }
  17779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData );
  17780. isKnowKey = TRUE;
  17781. }
  17782. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  17783. {
  17784. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  17785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  17786. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  17787. {
  17788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  17789. }
  17790. else
  17791. {
  17792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  17793. }
  17794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  17795. isKnowKey = TRUE;
  17796. }
  17797. #if 1
  17798. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  17799. {
  17800. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  17801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  17802. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17803. {
  17804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  17805. }
  17806. else
  17807. {
  17808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  17809. }
  17810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  17811. isKnowKey = TRUE;
  17812. }
  17813. #endif
  17814. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  17815. {
  17816. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  17817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  17818. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17819. {
  17820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17821. }
  17822. else
  17823. {
  17824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17825. }
  17826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  17827. isKnowKey = TRUE;
  17828. }
  17829. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  17830. {
  17831. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  17832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  17833. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17834. {
  17835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17836. }
  17837. else
  17838. {
  17839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17840. }
  17841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  17842. isKnowKey = TRUE;
  17843. }
  17844. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  17845. {
  17846. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  17847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  17848. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17849. {
  17850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  17851. }
  17852. else
  17853. {
  17854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  17855. }
  17856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  17857. isKnowKey = TRUE;
  17858. }
  17859. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  17860. {
  17861. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  17862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  17863. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17864. {
  17865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  17866. }
  17867. else
  17868. {
  17869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  17870. }
  17871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  17872. isKnowKey = TRUE;
  17873. }
  17874. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  17875. {
  17876. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  17877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  17878. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17879. {
  17880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  17881. }
  17882. else
  17883. {
  17884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  17885. }
  17886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  17887. isKnowKey = TRUE;
  17888. }
  17889. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  17890. {
  17891. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  17892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  17893. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17894. {
  17895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  17896. }
  17897. else
  17898. {
  17899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  17900. }
  17901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  17902. isKnowKey = TRUE;
  17903. }
  17904. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  17905. {
  17906. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  17907. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  17908. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17909. {
  17910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  17911. }
  17912. else
  17913. {
  17914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  17915. }
  17916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  17917. isKnowKey = TRUE;
  17918. }
  17919. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  17920. {
  17921. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  17922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  17923. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17924. {
  17925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  17926. }
  17927. else
  17928. {
  17929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  17930. }
  17931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  17932. isKnowKey = TRUE;
  17933. }
  17934. //=========================================================
  17935. if(!isEmpty && !isKnowKey)
  17936. {
  17937. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  17938. strcpy(unknownkey[UnknownKeynum], keyReq);
  17939. UnknownKeynum = UnknownKeynum + 1;
  17940. }
  17941. }
  17942. void processUnkownKey(void)
  17943. {
  17944. DEBUG_INFO("processUnkownKey...\n");
  17945. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  17946. for(int index=0; index < UnknownKeynum; index++)
  17947. {
  17948. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  17949. {
  17950. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  17951. }
  17952. }
  17953. }
  17954. int setKeyValue(char *key, char *value)
  17955. {
  17956. int isSuccess = NotSupported;
  17957. int check_ascii=0;
  17958. char str[501]={0};
  17959. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  17960. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  17961. {
  17962. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  17963. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  17964. {
  17965. strcpy(str, (const char*)value);
  17966. for(int i = 0; str[i]; i++){
  17967. str[i] = tolower(str[i]);
  17968. }
  17969. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17970. isSuccess = ConfigurationStatus_Accepted;
  17971. }
  17972. else
  17973. {
  17974. isSuccess = ConfigurationStatus_Rejected;
  17975. }
  17976. }
  17977. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  17978. {
  17979. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  17980. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  17981. {
  17982. strcpy(str, (const char*)value);
  17983. for(int i = 0; str[i]; i++){
  17984. str[i] = tolower(str[i]);
  17985. }
  17986. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  17987. isSuccess = ConfigurationStatus_Accepted;
  17988. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  17989. }
  17990. else
  17991. {
  17992. isSuccess = ConfigurationStatus_Rejected;
  17993. }
  17994. }
  17995. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  17996. {
  17997. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  17998. {
  17999. strcpy(str, (const char*)value);
  18000. for(int i = 0; str[i]; i++)
  18001. {
  18002. str[i] = tolower(str[i]);
  18003. }
  18004. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  18005. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18006. isSuccess = ConfigurationStatus_Accepted;
  18007. }
  18008. else
  18009. {
  18010. isSuccess = ConfigurationStatus_Rejected;
  18011. }
  18012. }
  18013. if(strcmp(key, "BlinkRepeat") == 0)
  18014. {
  18015. //Charger.BlinkRepeat = Integer.parseInt(value);
  18016. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  18017. {
  18018. check_ascii = value[0];
  18019. if( (check_ascii < 48) || (check_ascii > 57) )
  18020. {
  18021. isSuccess = ConfigurationStatus_Rejected;
  18022. }
  18023. else
  18024. {
  18025. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  18026. isSuccess = ConfigurationStatus_Accepted;
  18027. }
  18028. }
  18029. else
  18030. {
  18031. isSuccess = ConfigurationStatus_Rejected;
  18032. }
  18033. }
  18034. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  18035. {
  18036. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  18037. {
  18038. check_ascii = value[0];
  18039. if( (check_ascii < 48) || (check_ascii > 57) )
  18040. {
  18041. isSuccess = ConfigurationStatus_Rejected;
  18042. }
  18043. else
  18044. {
  18045. if((atoi(value) == 0) || (atoi(value) >= 5))
  18046. {
  18047. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  18048. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  18049. isSuccess = ConfigurationStatus_Accepted;
  18050. }
  18051. else
  18052. isSuccess = ConfigurationStatus_Rejected;
  18053. }
  18054. }
  18055. else
  18056. {
  18057. isSuccess = ConfigurationStatus_Rejected;
  18058. }
  18059. }
  18060. if(strcmp(key, "ConnectionTimeOut") == 0 )
  18061. {
  18062. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  18063. {
  18064. check_ascii = value[0];
  18065. if( (check_ascii < 48) || (check_ascii > 57) )
  18066. {
  18067. isSuccess = ConfigurationStatus_Rejected;
  18068. }
  18069. else
  18070. {
  18071. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  18072. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  18073. isSuccess = ConfigurationStatus_Accepted;
  18074. }
  18075. }
  18076. else
  18077. {
  18078. isSuccess = ConfigurationStatus_Rejected;
  18079. }
  18080. }
  18081. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  18082. {
  18083. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  18084. {
  18085. check_ascii = value[0];
  18086. if( (check_ascii < 48) || (check_ascii > 57) )
  18087. {
  18088. isSuccess = ConfigurationStatus_Rejected;
  18089. }
  18090. else
  18091. {
  18092. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18093. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  18094. isSuccess = ConfigurationStatus_Accepted;
  18095. }
  18096. }
  18097. else
  18098. {
  18099. isSuccess = ConfigurationStatus_Rejected;
  18100. }
  18101. }
  18102. if(strcmp(key, "HeartbeatInterval") == 0)
  18103. {
  18104. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  18105. {
  18106. check_ascii = value[0];
  18107. if( (check_ascii < 48) || (check_ascii > 57) )
  18108. {
  18109. isSuccess = ConfigurationStatus_Rejected;
  18110. }
  18111. else
  18112. {
  18113. if((atoi(value) == 0) || (atoi(value) >= 10))
  18114. {
  18115. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18116. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  18117. HeartBeatWaitTime = atoi(value);
  18118. isSuccess = ConfigurationStatus_Accepted;
  18119. }
  18120. else
  18121. {
  18122. isSuccess = ConfigurationStatus_Rejected;
  18123. }
  18124. }
  18125. }
  18126. else
  18127. {
  18128. isSuccess = ConfigurationStatus_Rejected;
  18129. }
  18130. }
  18131. if(strcmp(key, "LightIntensity") == 0)
  18132. {
  18133. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  18134. {
  18135. check_ascii = value[0];
  18136. if( (check_ascii < 48) || (check_ascii > 57) )
  18137. {
  18138. isSuccess = ConfigurationStatus_Rejected;
  18139. }
  18140. else
  18141. {
  18142. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  18143. isSuccess = ConfigurationStatus_Accepted;
  18144. }
  18145. }
  18146. else
  18147. {
  18148. isSuccess = ConfigurationStatus_Rejected;
  18149. }
  18150. }
  18151. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  18152. {
  18153. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  18154. {
  18155. strcpy(str, (const char*)value);
  18156. for(int i = 0; str[i]; i++)
  18157. {
  18158. str[i] = tolower(str[i]);
  18159. }
  18160. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18161. isSuccess = ConfigurationStatus_Accepted;
  18162. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  18163. }
  18164. else
  18165. {
  18166. isSuccess = ConfigurationStatus_Rejected;
  18167. }
  18168. }
  18169. if(strcmp(key, "LocalPreAuthorize") == 0)
  18170. {
  18171. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  18172. {
  18173. strcpy(str, (const char*)value);
  18174. for(int i = 0; str[i]; i++)
  18175. {
  18176. str[i] = tolower(str[i]);
  18177. }
  18178. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18179. isSuccess = ConfigurationStatus_Accepted;
  18180. }
  18181. else
  18182. {
  18183. isSuccess = ConfigurationStatus_Rejected;
  18184. }
  18185. }
  18186. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  18187. {
  18188. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  18189. {
  18190. check_ascii = value[0];
  18191. if( (check_ascii < 48) || (check_ascii > 57) )
  18192. {
  18193. isSuccess = ConfigurationStatus_Rejected;
  18194. }
  18195. else
  18196. {
  18197. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  18198. isSuccess = ConfigurationStatus_Accepted;
  18199. }
  18200. }
  18201. else
  18202. {
  18203. isSuccess = ConfigurationStatus_Rejected;
  18204. }
  18205. }
  18206. if(strcmp(key, "MeterValuesAlignedData") == 0)
  18207. {
  18208. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  18209. {
  18210. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  18211. isSuccess = ConfigurationStatus_Accepted;
  18212. }
  18213. else
  18214. {
  18215. isSuccess = ConfigurationStatus_Rejected;
  18216. }
  18217. }
  18218. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  18219. {
  18220. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  18221. {
  18222. check_ascii = value[0];
  18223. if( (check_ascii < 48) || (check_ascii > 57) )
  18224. {
  18225. isSuccess = ConfigurationStatus_Rejected;
  18226. }
  18227. else
  18228. {
  18229. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18230. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  18231. isSuccess = ConfigurationStatus_Accepted;
  18232. }
  18233. }
  18234. else
  18235. {
  18236. isSuccess = ConfigurationStatus_Rejected;
  18237. }
  18238. }
  18239. if(strcmp(key, "MeterValuesSampledData") == 0 )
  18240. {
  18241. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  18242. {
  18243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  18244. isSuccess = ConfigurationStatus_Accepted;
  18245. }
  18246. else
  18247. {
  18248. isSuccess = ConfigurationStatus_Rejected;
  18249. }
  18250. }
  18251. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  18252. {
  18253. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  18254. {
  18255. check_ascii = value[0];
  18256. if( (check_ascii < 48) || (check_ascii > 57) )
  18257. {
  18258. isSuccess = ConfigurationStatus_Rejected;
  18259. }
  18260. else
  18261. {
  18262. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18263. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  18264. isSuccess = ConfigurationStatus_Accepted;
  18265. }
  18266. }
  18267. else
  18268. {
  18269. isSuccess = ConfigurationStatus_Rejected;
  18270. }
  18271. }
  18272. if(strcmp(key, "MeterValueSampleInterval") == 0)
  18273. {
  18274. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  18275. {
  18276. check_ascii = value[0];
  18277. if( (check_ascii < 48) || (check_ascii > 57) )
  18278. {
  18279. isSuccess = ConfigurationStatus_Rejected;
  18280. }
  18281. else
  18282. {
  18283. if((atoi(value) == 0) || (atoi(value) >= 3))
  18284. {
  18285. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  18287. isSuccess = ConfigurationStatus_Accepted;
  18288. }
  18289. else
  18290. {
  18291. isSuccess = ConfigurationStatus_Rejected;
  18292. }
  18293. }
  18294. }
  18295. else
  18296. {
  18297. isSuccess = ConfigurationStatus_Rejected;
  18298. }
  18299. }
  18300. if(strcmp(key, "MinimumStatusDuration") == 0)
  18301. {
  18302. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  18303. {
  18304. check_ascii = value[0];
  18305. if( (check_ascii < 48) || (check_ascii > 57) )
  18306. {
  18307. isSuccess = ConfigurationStatus_Rejected;
  18308. }
  18309. else
  18310. {
  18311. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  18312. {
  18313. isSuccess = ConfigurationStatus_Rejected;
  18314. }
  18315. else
  18316. {
  18317. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  18318. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  18319. server_cycle_Status = atoi(value); //StatusNotification Cycle
  18320. isSuccess = ConfigurationStatus_Accepted;
  18321. }
  18322. }
  18323. }
  18324. else
  18325. {
  18326. isSuccess = ConfigurationStatus_Rejected;
  18327. }
  18328. }
  18329. if(strcmp(key, "NumberOfConnectors") == 0)
  18330. {
  18331. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  18332. {
  18333. check_ascii = value[0];
  18334. if( (check_ascii < 48) || (check_ascii > 57) )
  18335. {
  18336. isSuccess = ConfigurationStatus_Rejected;
  18337. }
  18338. else
  18339. {
  18340. //Charger.ResetRetries = Integer.parseInt(value);
  18341. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  18342. isSuccess = ConfigurationStatus_Accepted;
  18343. }
  18344. }
  18345. else
  18346. {
  18347. isSuccess = ConfigurationStatus_Rejected;
  18348. }
  18349. }
  18350. if(strcmp(key, "ResetRetries") == 0)
  18351. {
  18352. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  18353. {
  18354. check_ascii = value[0];
  18355. if( (check_ascii < 48) || (check_ascii > 57) )
  18356. {
  18357. isSuccess = ConfigurationStatus_Rejected;
  18358. }
  18359. else
  18360. {
  18361. //Charger.ResetRetries = Integer.parseInt(value);
  18362. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  18363. isSuccess = ConfigurationStatus_Accepted;
  18364. }
  18365. }
  18366. else
  18367. {
  18368. isSuccess = ConfigurationStatus_Rejected;
  18369. }
  18370. }
  18371. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  18372. {
  18373. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  18374. {
  18375. strcpy(str, (const char*)value);
  18376. for(int i = 0; str[i]; i++)
  18377. {
  18378. str[i] = tolower(str[i]);
  18379. }
  18380. if(strcmp(str, "notapplicable")== 0)
  18381. {
  18382. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  18383. isSuccess = ConfigurationStatus_Accepted;
  18384. }
  18385. else if(strcmp(str, "unknown")== 0)
  18386. {
  18387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  18388. isSuccess = ConfigurationStatus_Accepted;
  18389. }
  18390. else if(strcmp(str, "rst")== 0)
  18391. {
  18392. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  18393. isSuccess = ConfigurationStatus_Accepted;
  18394. }
  18395. else if(strcmp(str, "rts")== 0)
  18396. {
  18397. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  18398. isSuccess = ConfigurationStatus_Accepted;
  18399. }
  18400. else if(strcmp(str, "srt")== 0)
  18401. {
  18402. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  18403. isSuccess = ConfigurationStatus_Accepted;
  18404. }
  18405. else if(strcmp(str, "str")== 0)
  18406. {
  18407. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  18408. isSuccess = ConfigurationStatus_Accepted;
  18409. }
  18410. else if(strcmp(str, "trs")== 0)
  18411. {
  18412. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  18413. isSuccess = ConfigurationStatus_Accepted;
  18414. }
  18415. else if(strcmp(str, "tsr")== 0)
  18416. {
  18417. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  18418. isSuccess = ConfigurationStatus_Accepted;
  18419. }
  18420. else
  18421. {
  18422. isSuccess = ConfigurationStatus_Rejected;
  18423. }
  18424. }
  18425. else
  18426. {
  18427. isSuccess = ConfigurationStatus_Rejected;
  18428. }
  18429. }
  18430. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  18431. {
  18432. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  18433. {
  18434. check_ascii = value[0];
  18435. if( (check_ascii < 48) || (check_ascii > 57) )
  18436. {
  18437. isSuccess = ConfigurationStatus_Rejected;
  18438. }
  18439. else
  18440. {
  18441. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  18442. isSuccess = ConfigurationStatus_Accepted;
  18443. }
  18444. }
  18445. else
  18446. {
  18447. isSuccess = ConfigurationStatus_Rejected;
  18448. }
  18449. }
  18450. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  18451. {
  18452. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  18453. {
  18454. strcpy(str, (const char*)value);
  18455. for(int i = 0; str[i]; i++)
  18456. {
  18457. str[i] = tolower(str[i]);
  18458. }
  18459. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18460. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18461. isSuccess = ConfigurationStatus_Accepted;
  18462. }
  18463. else
  18464. {
  18465. isSuccess = ConfigurationStatus_Rejected;
  18466. }
  18467. }
  18468. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  18469. {
  18470. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  18471. {
  18472. strcpy(str, (const char*)value);
  18473. for(int i = 0; str[i]; i++)
  18474. {
  18475. str[i] = tolower(str[i]);
  18476. }
  18477. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  18478. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18479. isSuccess = ConfigurationStatus_Accepted;
  18480. }
  18481. else
  18482. {
  18483. isSuccess = ConfigurationStatus_Rejected;
  18484. }
  18485. }
  18486. if(strcmp(key, "StopTxnAlignedData") == 0)
  18487. {
  18488. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  18489. {
  18490. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  18491. isSuccess = ConfigurationStatus_Accepted;
  18492. }
  18493. else
  18494. {
  18495. isSuccess = ConfigurationStatus_Rejected;
  18496. }
  18497. }
  18498. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  18499. {
  18500. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  18501. {
  18502. check_ascii = value[0];
  18503. if( (check_ascii < 48) || (check_ascii > 57) )
  18504. {
  18505. isSuccess = ConfigurationStatus_Rejected;
  18506. }
  18507. else
  18508. {
  18509. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  18510. isSuccess = ConfigurationStatus_Accepted;
  18511. }
  18512. }
  18513. else
  18514. {
  18515. isSuccess = ConfigurationStatus_Rejected;
  18516. }
  18517. }
  18518. if(strcmp(key, "StopTxnSampledData") == 0)
  18519. {
  18520. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  18521. {
  18522. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  18523. isSuccess = ConfigurationStatus_Accepted;
  18524. }
  18525. else
  18526. {
  18527. isSuccess = ConfigurationStatus_Rejected;
  18528. }
  18529. }
  18530. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  18531. {
  18532. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  18533. {
  18534. check_ascii = value[0];
  18535. if( (check_ascii < 48) || (check_ascii > 57) )
  18536. {
  18537. isSuccess = ConfigurationStatus_Rejected;
  18538. }
  18539. else
  18540. {
  18541. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  18542. isSuccess = ConfigurationStatus_Accepted;
  18543. }
  18544. }
  18545. else
  18546. {
  18547. isSuccess = ConfigurationStatus_Rejected;
  18548. }
  18549. }
  18550. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  18551. {
  18552. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  18553. {
  18554. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  18555. isSuccess = ConfigurationStatus_Accepted;
  18556. }
  18557. else
  18558. {
  18559. isSuccess = ConfigurationStatus_Rejected;
  18560. }
  18561. }
  18562. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  18563. {
  18564. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  18565. {
  18566. check_ascii = value[0];
  18567. if( (check_ascii < 48) || (check_ascii > 57) )
  18568. {
  18569. isSuccess = ConfigurationStatus_Rejected;
  18570. }
  18571. else
  18572. {
  18573. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  18574. isSuccess = ConfigurationStatus_Accepted;
  18575. }
  18576. }
  18577. else
  18578. {
  18579. isSuccess = ConfigurationStatus_Rejected;
  18580. }
  18581. }
  18582. if(strcmp(key, "TransactionMessageAttempts") == 0)
  18583. {
  18584. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  18585. {
  18586. check_ascii = value[0];
  18587. if( (check_ascii < 48) || (check_ascii > 57) )
  18588. {
  18589. isSuccess = ConfigurationStatus_Rejected;
  18590. }
  18591. else
  18592. {
  18593. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  18594. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  18595. TransactionMessageAttemptsValue = atoi(value);
  18596. isSuccess = ConfigurationStatus_Accepted;
  18597. }
  18598. }
  18599. else
  18600. {
  18601. isSuccess = ConfigurationStatus_Rejected;
  18602. }
  18603. }
  18604. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  18605. {
  18606. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  18607. {
  18608. check_ascii = value[0];
  18609. if( (check_ascii < 48) || (check_ascii > 57) )
  18610. {
  18611. isSuccess = ConfigurationStatus_Rejected;
  18612. }
  18613. else
  18614. {
  18615. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  18616. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  18617. TransactionMessageRetryIntervalValue = atoi(value);
  18618. isSuccess = ConfigurationStatus_Accepted;
  18619. }
  18620. }
  18621. else
  18622. {
  18623. isSuccess = ConfigurationStatus_Rejected;
  18624. }
  18625. }
  18626. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  18627. {
  18628. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  18629. {
  18630. strcpy(str, (const char*)value);
  18631. for(int i = 0; str[i]; i++)
  18632. {
  18633. str[i] = tolower(str[i]);
  18634. }
  18635. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18637. isSuccess = ConfigurationStatus_Accepted;
  18638. }
  18639. else
  18640. {
  18641. isSuccess = ConfigurationStatus_Rejected;
  18642. }
  18643. }
  18644. if(strcmp(key, "WebSocketPingInterval") == 0)
  18645. {
  18646. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  18647. {
  18648. check_ascii = value[0];
  18649. if( (check_ascii < 48) || (check_ascii > 57) )
  18650. {
  18651. isSuccess = ConfigurationStatus_Rejected;
  18652. }
  18653. else
  18654. {
  18655. if((atoi(value) == 0) || (atoi(value) >= 10))
  18656. {
  18657. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  18658. isSuccess = ConfigurationStatus_Accepted;
  18659. }
  18660. else
  18661. isSuccess = ConfigurationStatus_Rejected;
  18662. }
  18663. }
  18664. else
  18665. {
  18666. isSuccess = ConfigurationStatus_Rejected;
  18667. }
  18668. }
  18669. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  18670. {
  18671. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  18672. {
  18673. strcpy(str, (const char*)value);
  18674. for(int i = 0; str[i]; i++)
  18675. {
  18676. str[i] = tolower(str[i]);
  18677. }
  18678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18679. isSuccess = ConfigurationStatus_Accepted;
  18680. }
  18681. else
  18682. {
  18683. isSuccess = ConfigurationStatus_Rejected;
  18684. }
  18685. }
  18686. if(strcmp(key, "AuthorizationKey") == 0)
  18687. {
  18688. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  18689. {
  18690. strcpy(str, (const char*)value);
  18691. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  18692. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18693. isSuccess = ConfigurationStatus_Accepted;
  18694. }
  18695. else
  18696. {
  18697. isSuccess = ConfigurationStatus_Rejected;
  18698. }
  18699. }
  18700. if(strcmp(key, "SecurityProfile") == 0)
  18701. {
  18702. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  18703. {
  18704. check_ascii = value[0];
  18705. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  18706. {
  18707. isSuccess = ConfigurationStatus_Rejected;
  18708. }
  18709. else if(check_ascii == 0x33)
  18710. {
  18711. isSuccess = NotSupported;
  18712. }
  18713. else
  18714. {
  18715. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  18716. {
  18717. if(((check_ascii - 0x30) == 1) ||
  18718. ((check_ascii - 0x30) == 2) ||
  18719. (((check_ascii - 0x30) == 3) && (access(CERTIFICATE_CP,F_OK) != -1)))
  18720. {
  18721. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  18722. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  18723. isSuccess = ConfigurationStatus_Accepted;
  18724. }
  18725. else
  18726. isSuccess = ConfigurationStatus_Rejected;
  18727. }
  18728. else
  18729. isSuccess = ConfigurationStatus_Rejected;
  18730. }
  18731. }
  18732. else
  18733. {
  18734. isSuccess = ConfigurationStatus_Rejected;
  18735. }
  18736. }
  18737. if(strcmp(key, "DefaultPrice") == 0)
  18738. {
  18739. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  18740. {
  18741. strcpy(str, (const char*)value);
  18742. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  18743. isSuccess = ConfigurationStatus_Accepted;
  18744. }
  18745. else
  18746. {
  18747. isSuccess = ConfigurationStatus_Rejected;
  18748. }
  18749. }
  18750. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  18751. {
  18752. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  18753. {
  18754. strcpy(str, (const char*)value);
  18755. for(int i = 0; str[i]; i++)
  18756. {
  18757. str[i] = tolower(str[i]);
  18758. }
  18759. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18760. isSuccess = ConfigurationStatus_Accepted;
  18761. }
  18762. else
  18763. {
  18764. isSuccess = ConfigurationStatus_Rejected;
  18765. }
  18766. }
  18767. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  18768. {
  18769. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  18770. {
  18771. strcpy(str, (const char*)value);
  18772. for(int i = 0; str[i]; i++)
  18773. {
  18774. str[i] = tolower(str[i]);
  18775. }
  18776. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18777. isSuccess = ConfigurationStatus_Accepted;
  18778. }
  18779. else
  18780. {
  18781. isSuccess = ConfigurationStatus_Rejected;
  18782. }
  18783. }
  18784. if(strcmp(key, "TimeOffset") == 0)
  18785. {
  18786. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  18787. {
  18788. strcpy(str, (const char*)value);
  18789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  18790. isSuccess = ConfigurationStatus_Accepted;
  18791. }
  18792. else
  18793. {
  18794. isSuccess = ConfigurationStatus_Rejected;
  18795. }
  18796. }
  18797. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  18798. {
  18799. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  18800. {
  18801. strcpy(str, (const char*)value);
  18802. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  18803. isSuccess = ConfigurationStatus_Accepted;
  18804. }
  18805. else
  18806. {
  18807. isSuccess = ConfigurationStatus_Rejected;
  18808. }
  18809. }
  18810. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  18811. {
  18812. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  18813. {
  18814. strcpy(str, (const char*)value);
  18815. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  18816. isSuccess = ConfigurationStatus_Accepted;
  18817. }
  18818. else
  18819. {
  18820. isSuccess = ConfigurationStatus_Rejected;
  18821. }
  18822. }
  18823. if(strcmp(key, "SystemUptimeSec") == 0)
  18824. {
  18825. isSuccess = NotSupported;
  18826. }
  18827. if(strcmp(key, "FreeVend") == 0)
  18828. {
  18829. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  18830. {
  18831. strcpy(str, (const char*)value);
  18832. for(int i = 0; str[i]; i++)
  18833. {
  18834. str[i] = tolower(str[i]);
  18835. }
  18836. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  18837. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18838. isSuccess = ConfigurationStatus_Accepted;
  18839. }
  18840. else
  18841. {
  18842. isSuccess = ConfigurationStatus_Rejected;
  18843. }
  18844. }
  18845. if(strcmp(key, "FreeVendIdtag") == 0)
  18846. {
  18847. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  18848. {
  18849. strcpy(str, (const char*)value);
  18850. if(strlen(str) <= 20)
  18851. {
  18852. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  18853. isSuccess = ConfigurationStatus_Accepted;
  18854. }
  18855. else
  18856. {
  18857. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  18858. isSuccess = ConfigurationStatus_Rejected;
  18859. }
  18860. }
  18861. else
  18862. {
  18863. isSuccess = ConfigurationStatus_Rejected;
  18864. }
  18865. }
  18866. if(strcmp(key, "OcppServer") == 0)
  18867. {
  18868. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  18869. {
  18870. strcpy(str, (const char*)value);
  18871. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  18872. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  18873. isSuccess = ConfigurationStatus_Accepted;
  18874. }
  18875. else
  18876. {
  18877. isSuccess = ConfigurationStatus_Rejected;
  18878. }
  18879. }
  18880. if(strcmp(key, "MaintainServer") == 0)
  18881. {
  18882. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  18883. {
  18884. strcpy(str, (const char*)value);
  18885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  18886. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  18887. isSuccess = ConfigurationStatus_Accepted;
  18888. }
  18889. else
  18890. {
  18891. isSuccess = ConfigurationStatus_Rejected;
  18892. }
  18893. }
  18894. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  18895. {
  18896. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  18897. {
  18898. strcpy(str, (const char*)value);
  18899. for(int i = 0; str[i]; i++)
  18900. {
  18901. str[i] = tolower(str[i]);
  18902. }
  18903. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  18904. isSuccess = ConfigurationStatus_Accepted;
  18905. }
  18906. else
  18907. {
  18908. isSuccess = ConfigurationStatus_Rejected;
  18909. }
  18910. }
  18911. if(strcmp(key, "StatusNotificationInterval") == 0)
  18912. {
  18913. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].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. if((atoi(value) == 0) || (atoi(value) >= 10))
  18923. {
  18924. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  18925. isSuccess = ConfigurationStatus_Accepted;
  18926. }
  18927. else
  18928. isSuccess = ConfigurationStatus_Rejected;
  18929. }
  18930. }
  18931. else
  18932. {
  18933. isSuccess = ConfigurationStatus_Rejected;
  18934. }
  18935. }
  18936. if(strcmp(key, "PreAuthAmount") == 0)
  18937. {
  18938. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  18939. {
  18940. check_ascii = value[0];
  18941. if( (check_ascii < 48) || (check_ascii > 57) )
  18942. {
  18943. isSuccess = ConfigurationStatus_Rejected;
  18944. }
  18945. else
  18946. {
  18947. if(atof(value) >= 0)
  18948. {
  18949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  18950. isSuccess = ConfigurationStatus_Accepted;
  18951. }
  18952. else
  18953. isSuccess = ConfigurationStatus_Rejected;
  18954. }
  18955. }
  18956. else
  18957. {
  18958. isSuccess = ConfigurationStatus_Rejected;
  18959. }
  18960. }
  18961. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  18962. {
  18963. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  18964. {
  18965. check_ascii = value[0];
  18966. if( (check_ascii < 48) || (check_ascii > 57) )
  18967. {
  18968. isSuccess = ConfigurationStatus_Rejected;
  18969. }
  18970. else
  18971. {
  18972. if(atoi(value) >= 0)
  18973. {
  18974. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  18975. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  18976. isSuccess = ConfigurationStatus_Accepted;
  18977. }
  18978. else
  18979. isSuccess = ConfigurationStatus_Rejected;
  18980. }
  18981. }
  18982. else
  18983. {
  18984. isSuccess = ConfigurationStatus_Rejected;
  18985. }
  18986. }
  18987. if(strcmp(key, "PowerSharingServerIP") == 0)
  18988. {
  18989. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  18990. {
  18991. strcpy(str, (const char*)value);
  18992. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  18993. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  18994. isSuccess = ConfigurationStatus_Accepted;
  18995. }
  18996. else
  18997. {
  18998. isSuccess = ConfigurationStatus_Rejected;
  18999. }
  19000. }
  19001. if(strcmp(key, "EVCCID_PREFIX") == 0)
  19002. {
  19003. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  19004. {
  19005. strcpy(str, (const char*)value);
  19006. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  19007. isSuccess = ConfigurationStatus_Accepted;
  19008. }
  19009. else
  19010. {
  19011. isSuccess = ConfigurationStatus_Rejected;
  19012. }
  19013. }
  19014. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  19015. {
  19016. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  19017. {
  19018. if(atoi(value) > modelnameInfo.ratedPower)
  19019. {
  19020. isSuccess = ConfigurationStatus_Rejected;
  19021. }
  19022. else{
  19023. strcpy(str, (const char*)value);
  19024. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  19025. isSuccess = ConfigurationStatus_Accepted;
  19026. }
  19027. }
  19028. else
  19029. {
  19030. isSuccess = ConfigurationStatus_Rejected;
  19031. }
  19032. }
  19033. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  19034. {
  19035. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  19036. {
  19037. if((atoi(value) != 0) && (atoi(value) < 5))
  19038. {
  19039. isSuccess = ConfigurationStatus_Rejected;
  19040. }
  19041. else{
  19042. strcpy(str, (const char*)value);
  19043. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  19044. isSuccess = ConfigurationStatus_Accepted;
  19045. }
  19046. }
  19047. else
  19048. {
  19049. isSuccess = ConfigurationStatus_Rejected;
  19050. }
  19051. }
  19052. if(strcmp(key, "CpoName") == 0)
  19053. {
  19054. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  19055. {
  19056. strcpy(str, (const char*)value);
  19057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", str );
  19058. isSuccess = ConfigurationStatus_Accepted;
  19059. }
  19060. else
  19061. {
  19062. isSuccess = ConfigurationStatus_Rejected;
  19063. }
  19064. }
  19065. #if 0
  19066. //For OCPP Test Case
  19067. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  19068. {
  19069. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19070. {
  19071. strcpy(str, (const char*)value);
  19072. for(int i = 0; str[i]; i++)
  19073. {
  19074. str[i] = tolower(str[i]);
  19075. }
  19076. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19077. isSuccess = ConfigurationStatus_Accepted;
  19078. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19079. }
  19080. else
  19081. {
  19082. isSuccess = ConfigurationStatus_Rejected;
  19083. }
  19084. }
  19085. #endif
  19086. #if 1
  19087. if(strcmp(key, "LocalAuthListEnabled") == 0)
  19088. {
  19089. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19090. {
  19091. strcpy(str, (const char*)value);
  19092. for(int i = 0; str[i]; i++)
  19093. {
  19094. str[i] = tolower(str[i]);
  19095. }
  19096. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19097. isSuccess = ConfigurationStatus_Accepted;
  19098. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19099. }
  19100. else
  19101. {
  19102. isSuccess = ConfigurationStatus_Rejected;
  19103. }
  19104. }
  19105. #endif
  19106. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  19107. {
  19108. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  19109. {
  19110. check_ascii = value[0];
  19111. if( (check_ascii < 48) || (check_ascii > 57) )
  19112. {
  19113. isSuccess = ConfigurationStatus_Rejected;
  19114. }
  19115. else
  19116. {
  19117. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  19118. isSuccess = ConfigurationStatus_Accepted;
  19119. }
  19120. }
  19121. else
  19122. {
  19123. isSuccess = ConfigurationStatus_Rejected;
  19124. }
  19125. }
  19126. if(strcmp(key, "SendLocalListMaxLength") == 0)
  19127. {
  19128. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  19129. {
  19130. check_ascii = value[0];
  19131. if( (check_ascii < 48) || (check_ascii > 57) )
  19132. {
  19133. isSuccess = ConfigurationStatus_Rejected;
  19134. }
  19135. else
  19136. {
  19137. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  19138. isSuccess = ConfigurationStatus_Accepted;
  19139. }
  19140. }
  19141. else
  19142. {
  19143. isSuccess = ConfigurationStatus_Rejected;
  19144. }
  19145. }
  19146. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  19147. {
  19148. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  19149. {
  19150. strcpy(str, (const char*)value);
  19151. for(int i = 0; str[i]; i++)
  19152. {
  19153. str[i] = tolower(str[i]);
  19154. }
  19155. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19156. isSuccess = ConfigurationStatus_Accepted;
  19157. }
  19158. else
  19159. {
  19160. isSuccess = ConfigurationStatus_Rejected;
  19161. }
  19162. }
  19163. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  19164. {
  19165. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  19166. {
  19167. check_ascii = value[0];
  19168. if( (check_ascii < 48) || (check_ascii > 57) )
  19169. {
  19170. isSuccess = ConfigurationStatus_Rejected;
  19171. }
  19172. else
  19173. {
  19174. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  19175. isSuccess = ConfigurationStatus_Accepted;
  19176. }
  19177. }
  19178. else
  19179. {
  19180. isSuccess = ConfigurationStatus_Rejected;
  19181. }
  19182. }
  19183. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  19184. {
  19185. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  19186. {
  19187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  19188. isSuccess = ConfigurationStatus_Accepted;
  19189. }
  19190. else
  19191. {
  19192. isSuccess = ConfigurationStatus_Rejected;
  19193. }
  19194. }
  19195. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  19196. {
  19197. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  19198. {
  19199. check_ascii = value[0];
  19200. if( (check_ascii < 48) || (check_ascii > 57) )
  19201. {
  19202. isSuccess = ConfigurationStatus_Rejected;
  19203. }
  19204. else
  19205. {
  19206. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  19207. isSuccess = ConfigurationStatus_Accepted;
  19208. }
  19209. }
  19210. else
  19211. {
  19212. isSuccess = ConfigurationStatus_Rejected;
  19213. }
  19214. }
  19215. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  19216. {
  19217. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  19218. {
  19219. strcpy(str, (const char*)value);
  19220. for(int i = 0; str[i]; i++)
  19221. {
  19222. str[i] = tolower(str[i]);
  19223. }
  19224. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19225. isSuccess = ConfigurationStatus_Accepted;
  19226. }
  19227. else
  19228. {
  19229. isSuccess = ConfigurationStatus_Rejected;
  19230. }
  19231. }
  19232. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  19233. {
  19234. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  19235. {
  19236. check_ascii = value[0];
  19237. if( (check_ascii < 48) || (check_ascii > 57) )
  19238. {
  19239. isSuccess = ConfigurationStatus_Rejected;
  19240. }
  19241. else
  19242. {
  19243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  19244. isSuccess = ConfigurationStatus_Accepted;
  19245. }
  19246. }
  19247. else
  19248. {
  19249. isSuccess = ConfigurationStatus_Rejected;
  19250. }
  19251. }
  19252. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19253. return isSuccess;
  19254. }
  19255. int TransactionMessageAttemptsGet(void)
  19256. {
  19257. return TransactionMessageAttemptsValue;
  19258. }
  19259. int FirstHeartBeatResponse(void)
  19260. {
  19261. return FirstHeartBeat;
  19262. }
  19263. int TransactionMessageRetryIntervalGet(void)
  19264. {
  19265. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19266. }
  19267. int ReadHttpStatus(int sock)
  19268. {
  19269. //char c;
  19270. char buff[1024]="",*ptr=buff+1;
  19271. int bytes_received, status;
  19272. DEBUG_INFO("Begin Response ..\n");
  19273. while((bytes_received = recv(sock, ptr, 1, 0))){
  19274. if(bytes_received==-1){
  19275. perror("ReadHttpStatus");
  19276. exit(1);
  19277. }
  19278. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  19279. ptr++;
  19280. }
  19281. *ptr=0;
  19282. ptr=buff+1;
  19283. sscanf(ptr,"%*s %d ", &status);
  19284. DEBUG_INFO("%s\n",ptr);
  19285. DEBUG_INFO("status=%d\n",status);
  19286. DEBUG_INFO("End Response ..\n");
  19287. return (bytes_received>0)?status:0;
  19288. }
  19289. //the only filed that it parsed is 'Content-Length'
  19290. int ParseHeader(int sock)
  19291. {
  19292. //char c;
  19293. char buff[1024]="",*ptr=buff+4;
  19294. int bytes_received;
  19295. DEBUG_INFO("Begin HEADER ..\n");
  19296. while((bytes_received = recv(sock, ptr, 1, 0))){
  19297. if(bytes_received==-1){
  19298. perror("Parse Header");
  19299. exit(1);
  19300. }
  19301. if(
  19302. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  19303. (ptr[-1]=='\r') && (*ptr=='\n' )
  19304. ) break;
  19305. ptr++;
  19306. }
  19307. *ptr=0;
  19308. ptr=buff+4;
  19309. //printf("%s",ptr);
  19310. if(bytes_received){
  19311. ptr=strstr(ptr,"Content-Length:");
  19312. if(ptr){
  19313. sscanf(ptr,"%*s %d",&bytes_received);
  19314. }else
  19315. bytes_received=-1; //unknown size
  19316. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  19317. }
  19318. DEBUG_INFO("End HEADER ..\n");
  19319. return bytes_received ;
  19320. }
  19321. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  19322. {
  19323. int result = TRUE;
  19324. char rmFileCmd[100]={0};
  19325. char FilePath[100]={0};
  19326. char ftpbuf[200];
  19327. int systemresult;
  19328. sprintf(FilePath,"/mnt/%s",filename);
  19329. system("ping 8.8.8.8 &");
  19330. if((access(FilePath,F_OK))!=-1)
  19331. {
  19332. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19333. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19334. system(rmFileCmd);
  19335. }
  19336. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19337. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  19338. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19339. systemresult = system(ftpbuf);
  19340. if(systemresult != 0)
  19341. {
  19342. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  19343. result = FALSE;
  19344. }
  19345. system("pkill ping");
  19346. return result;
  19347. }
  19348. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  19349. {
  19350. int result = TRUE;
  19351. char rmFileCmd[100]={0};
  19352. char FilePath[100]={0};
  19353. char ftpbuf[200];
  19354. int systemresult;
  19355. sprintf(FilePath,"/mnt/%s",filename);
  19356. system("ping 8.8.8.8 &");
  19357. if((access(FilePath,F_OK))!=-1)
  19358. {
  19359. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19360. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19361. system(rmFileCmd);
  19362. }
  19363. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19364. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  19365. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19366. systemresult = system(ftpbuf);
  19367. if(systemresult != 0)
  19368. {
  19369. DEBUG_WARN("scp error!\n");
  19370. result = FALSE;
  19371. }
  19372. system("pkill ping");
  19373. return result;
  19374. }
  19375. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  19376. {
  19377. int result = TRUE;
  19378. char rmFileCmd[100]={0};
  19379. char FilePath[100]={0};
  19380. char ftpbuf[200];
  19381. int systemresult;
  19382. sprintf(FilePath,"/mnt/%s",filename);
  19383. system("ping 8.8.8.8 &");
  19384. if((access(FilePath,F_OK))!=-1)
  19385. {
  19386. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19387. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19388. system(rmFileCmd);
  19389. }
  19390. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19391. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  19392. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19393. systemresult = system(ftpbuf);
  19394. if(systemresult != 0)
  19395. {
  19396. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  19397. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19398. systemresult = system(ftpbuf);
  19399. if(systemresult != 0)
  19400. {
  19401. DEBUG_WARN("FTP download fail!\n");
  19402. result = FALSE;
  19403. }
  19404. }
  19405. system("pkill ping");
  19406. return result;
  19407. }
  19408. int httpUploadFile(char *location, char *path, char *filename,char *url)
  19409. {
  19410. char rmFileCmd[100]={0};
  19411. char FilePath[100]={0};
  19412. char buf[512];
  19413. int systemresult = 0;
  19414. //DEBUG_INFO("filename=%s\n",filename);
  19415. //DEBUG_INFO("url=%s\n",url);
  19416. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  19417. if((access(FilePath,F_OK))!=-1)
  19418. {
  19419. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19420. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19421. system(rmFileCmd);
  19422. }
  19423. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  19424. if(fp == NULL)
  19425. {
  19426. DEBUG_INFO("log is NULL\n");
  19427. return FALSE;
  19428. }
  19429. else
  19430. {
  19431. fprintf(fp, "%s\n", url);
  19432. fprintf(fp, "%s\n", filename);
  19433. fclose(fp);
  19434. }
  19435. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  19436. if(phpFP == NULL)
  19437. {
  19438. DEBUG_INFO("PHP upload fail.\n");
  19439. return FALSE;
  19440. }
  19441. else
  19442. {
  19443. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19444. {
  19445. if(strstr(buf, "result") != NULL)
  19446. {
  19447. sscanf(buf, "result: %d", &systemresult);
  19448. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  19449. }
  19450. }
  19451. pclose(phpFP);
  19452. }
  19453. if(systemresult != 1)
  19454. {
  19455. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  19456. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  19457. if(phpFP == NULL)
  19458. {
  19459. DEBUG_WARN("PHP PUT upload fail.\n");
  19460. return FALSE;
  19461. }
  19462. else
  19463. {
  19464. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19465. {
  19466. if(strstr(buf, "result") != NULL)
  19467. {
  19468. sscanf(buf, "result: %d", &systemresult);
  19469. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  19470. }
  19471. }
  19472. pclose(phpFP);
  19473. }
  19474. }
  19475. if(systemresult != 1)
  19476. {
  19477. DEBUG_WARN("PHP PUT upload fail.\n");
  19478. return FALSE;
  19479. }
  19480. return TRUE;
  19481. }
  19482. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  19483. {
  19484. int result = FALSE;
  19485. char ftpbuf[200];
  19486. int systemresult;
  19487. /*
  19488. // Domaind name transfer to IP address
  19489. struct hostent* server;
  19490. char *IPbuffer;
  19491. server = gethostbyname(location);
  19492. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  19493. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19494. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  19495. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  19496. systemresult = system(ftpbuf);
  19497. if(systemresult != 0)
  19498. {
  19499. DEBUG_INFO("ftpput error!\n");
  19500. }
  19501. else
  19502. {
  19503. result = TRUE;
  19504. DEBUG_INFO("ftpput OK!\n");
  19505. }
  19506. return result;
  19507. }
  19508. int GetOcppServerURL()
  19509. {
  19510. int result = FALSE;
  19511. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  19512. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  19513. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  19514. struct yuarel url;
  19515. char urlStr[512];
  19516. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  19517. {
  19518. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  19519. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19520. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19521. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  19522. if(yuarel_parse(&url, urlStr) != -1)
  19523. {
  19524. sprintf(OcppProtocol, "%s", url.scheme);
  19525. sprintf(OcppHost, "%s", url.host);
  19526. if(url.path == NULL)
  19527. OcppTempPath[0] = '\0';
  19528. else
  19529. {
  19530. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  19531. {
  19532. sprintf(OcppTempPath, "%s/", url.path);
  19533. }
  19534. else
  19535. {
  19536. sprintf(OcppTempPath, "%s", url.path);
  19537. }
  19538. }
  19539. if(url.port == 0)
  19540. {
  19541. if(strcmp(OcppProtocol, "wss") == 0)
  19542. OcppPort = 443;
  19543. else
  19544. OcppPort = 80;
  19545. }
  19546. else
  19547. OcppPort = url.port;
  19548. result = TRUE;
  19549. }
  19550. }
  19551. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  19552. {
  19553. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  19554. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19555. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19556. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  19557. if(yuarel_parse(&url, urlStr) != -1)
  19558. {
  19559. sprintf(OcppProtocol, "%s", url.scheme);
  19560. sprintf(OcppHost, "%s", url.host);
  19561. if(url.path == NULL)
  19562. OcppTempPath[0] = '\0';
  19563. else
  19564. sprintf(OcppTempPath, "%s", url.path);
  19565. if(url.port == 0)
  19566. {
  19567. if(strcmp(OcppProtocol, "wss") == 0)
  19568. OcppPort = 443;
  19569. else
  19570. OcppPort = 80;
  19571. }
  19572. else
  19573. OcppPort = url.port;
  19574. result = TRUE;
  19575. }
  19576. }
  19577. else
  19578. {
  19579. strcpy(OcppHost,"");
  19580. }
  19581. return result;
  19582. }
  19583. int GetOcppPath()
  19584. {
  19585. int result = FALSE;
  19586. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  19587. {
  19588. if(OcppTempPath == NULL)
  19589. {
  19590. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19591. }
  19592. else
  19593. {
  19594. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19595. }
  19596. result = TRUE;
  19597. goto End;
  19598. }
  19599. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  19600. {
  19601. if(OcppTempPath == NULL)
  19602. {
  19603. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  19604. }
  19605. else
  19606. {
  19607. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  19608. }
  19609. result = TRUE;
  19610. goto End;
  19611. }
  19612. else
  19613. {
  19614. strcpy(OcppPath,"");
  19615. }
  19616. End:
  19617. return result;
  19618. }
  19619. int GetOcppPort()
  19620. {
  19621. return OcppPort;
  19622. }
  19623. int GetOcppConnStatus(void)
  19624. {
  19625. return ShmOCPP16Data->OcppConnStatus;
  19626. }
  19627. void SetOcppConnStatus(uint8_t status)
  19628. {
  19629. ShmOCPP16Data->OcppConnStatus = status;
  19630. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  19631. }
  19632. int GetHeartBeatWithNOResponse(void)
  19633. {
  19634. return HeartBeatWithNOResponse;
  19635. }
  19636. void SetHeartBeatWithNOResponse(void)
  19637. {
  19638. HeartBeatWithNOResponse = 0;
  19639. }
  19640. void GetStartTransactionIdTag(int gun_index)
  19641. {
  19642. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  19643. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  19644. }
  19645. int GetStartTransactionId(int gun_index)
  19646. {
  19647. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19648. }
  19649. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  19650. {
  19651. char ch;
  19652. FILE *fptr1;
  19653. int temptransactionId;
  19654. char str[100]={0};
  19655. temptransactionId = 0;
  19656. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  19657. {
  19658. DEBUG_INFO("IdTag is empty.\n");
  19659. return temptransactionId;
  19660. }
  19661. /*------ Read the file ----------------*/
  19662. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  19663. if (!fptr1)
  19664. {
  19665. DEBUG_INFO("QueueTransactionId file open error.\n");
  19666. //printf(" File not found or unable to open the input file!!\n");
  19667. return temptransactionId;
  19668. }
  19669. ch=fgetc(fptr1);
  19670. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  19671. rewind(fptr1);
  19672. if(ch!=EOF)
  19673. {
  19674. // printf("%c",ch);
  19675. while (fgets(str, 100, fptr1) != NULL)
  19676. {
  19677. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19678. if(str[0]=='\0')
  19679. {
  19680. break;
  19681. }
  19682. char *revbuf[8] = {0}; // Variable store string split
  19683. int num = 0;// Quantity after string split
  19684. DEBUG_INFO("Transaction queue data= %s\n", str);
  19685. splitstring(str,",",revbuf,&num); // String split
  19686. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  19687. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  19688. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  19689. DEBUG_INFO("------------------------------\n");
  19690. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  19691. {
  19692. if(isStopTransaction)
  19693. {
  19694. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  19695. {
  19696. temptransactionId = atoi(revbuf[2]);
  19697. //break;
  19698. }
  19699. }
  19700. else
  19701. {
  19702. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  19703. {
  19704. temptransactionId = atoi(revbuf[2]);
  19705. //break;
  19706. }
  19707. }
  19708. }
  19709. }
  19710. }
  19711. else
  19712. DEBUG_INFO("EOF\n");
  19713. fclose(fptr1);
  19714. /*------- End of reading ---------------*/
  19715. return temptransactionId;
  19716. }
  19717. void SetTransactionIdZero(int transactionId)
  19718. {
  19719. char ch;
  19720. FILE *fptr1, *fptr2;
  19721. int temptransactionId = 0;
  19722. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  19723. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  19724. if (!fptr1)
  19725. {
  19726. //printf(" File not found or unable to open the input file!!\n");
  19727. return ;
  19728. }
  19729. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  19730. if (!fptr2)
  19731. {
  19732. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  19733. fclose(fptr1);
  19734. return ;
  19735. }
  19736. ch=fgetc(fptr1);
  19737. rewind(fptr1);
  19738. if(ch!=EOF)
  19739. {
  19740. // copy all contents to the temporary file except the specific line
  19741. while (fgets(str, 100, fptr1) != NULL)
  19742. {
  19743. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19744. if(str[0]=='\0')
  19745. {
  19746. break;
  19747. }
  19748. char *revbuf[8] = {0};
  19749. int num = 0;
  19750. strcpy(strtemp, str);
  19751. splitstring(str,",",revbuf,&num);
  19752. if(revbuf[2][0] != '\0')
  19753. {
  19754. temptransactionId = atoi(revbuf[2]);
  19755. if(transactionId != temptransactionId)
  19756. {
  19757. fprintf(fptr2, "%s\n", strtemp);
  19758. }
  19759. }
  19760. }
  19761. }
  19762. fclose(fptr1);
  19763. fclose(fptr2);
  19764. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  19765. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  19766. /*------ Read the file ----------------*/
  19767. }
  19768. int InternetDisconnect(void)
  19769. {
  19770. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  19771. }
  19772. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  19773. void storeTempStopTransaction(int gun_index)
  19774. {
  19775. char guid[37]={0};
  19776. int tempIndex = 0;
  19777. char TempStopTransaction[256];
  19778. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19779. DEBUG_INFO("storeTempStopTransaction...\n");
  19780. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  19781. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  19782. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  19783. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19784. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19785. {
  19786. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19787. {
  19788. tempIndex = ((gun_index==2) ? 1: 0);
  19789. }
  19790. else
  19791. {
  19792. tempIndex = gun_index;
  19793. }
  19794. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19795. {
  19796. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19797. {
  19798. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  19799. }
  19800. }// END OF CHAdeMO_QUANTITY
  19801. }
  19802. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19803. {
  19804. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19805. {
  19806. tempIndex = ((gun_index==2) ? 1: 0);
  19807. }
  19808. else
  19809. {
  19810. tempIndex = gun_index;
  19811. }
  19812. for (int index = 0; index < CCS_QUANTITY; index++)
  19813. {
  19814. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19815. {
  19816. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  19817. }
  19818. }// END OF CCS_QUANTITY
  19819. }
  19820. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19821. {
  19822. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19823. {
  19824. tempIndex = ((gun_index==2) ? 1: 0);
  19825. }
  19826. else
  19827. {
  19828. tempIndex = gun_index;
  19829. }
  19830. for (int index = 0; index < GB_QUANTITY; index++)
  19831. {
  19832. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19833. {
  19834. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  19835. }
  19836. }// END OF GB_QUANTITY
  19837. }
  19838. else if(gunType[gun_index] == GUN_TYPE_DO)
  19839. {
  19840. tempIndex = gun_index;
  19841. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19842. {
  19843. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19844. {
  19845. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  19846. }
  19847. }
  19848. }
  19849. else
  19850. {
  19851. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19852. {
  19853. tempIndex = 2;
  19854. }
  19855. else
  19856. {
  19857. tempIndex = gun_index;
  19858. }
  19859. for (int index = 0; index < AC_QUANTITY; index++)
  19860. {
  19861. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19862. {
  19863. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  19864. }
  19865. }// END OF AC_QUANTITY
  19866. }
  19867. //Stop Transaction Time
  19868. struct timeval tmnow;
  19869. struct tm *tm;
  19870. char buf[28];//, usec_buf[6];
  19871. gettimeofday(&tmnow, NULL);
  19872. time_t t;
  19873. t = time(NULL);
  19874. /*UTC time and date*/
  19875. tm = gmtime(&t);
  19876. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  19877. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  19878. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19879. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  19880. random_uuid(guid);
  19881. /***********************************transactionData******************************************************/
  19882. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  19883. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  19884. //=================================
  19885. //1. Transaction_Begin
  19886. //=================================
  19887. //============================== Energy.Active.Import.Interval ===========================================
  19888. //=================================
  19889. //2. Transaction_End
  19890. //=================================
  19891. //2.1====================================== Current.Import L1 ==============================================
  19892. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  19893. {
  19894. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  19895. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19896. {
  19897. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19898. {
  19899. tempIndex = ((gun_index==2) ? 1: 0);
  19900. }
  19901. else
  19902. {
  19903. tempIndex = gun_index;
  19904. }
  19905. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19906. {
  19907. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19908. {
  19909. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  19910. }
  19911. }// End of for CHAdeMO_QUANTITY
  19912. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  19913. }
  19914. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19915. {
  19916. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19917. {
  19918. tempIndex = ((gun_index==2) ? 1: 0);
  19919. }
  19920. else
  19921. {
  19922. tempIndex = gun_index;
  19923. }
  19924. for (int index = 0; index < CCS_QUANTITY; index++)
  19925. {
  19926. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19927. {
  19928. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  19929. }
  19930. }// End of for CCS_QUANTITY
  19931. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  19932. }
  19933. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19934. {
  19935. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19936. {
  19937. tempIndex = ((gun_index==2) ? 1: 0);
  19938. }
  19939. else
  19940. {
  19941. tempIndex = gun_index;
  19942. }
  19943. for (int index = 0; index < GB_QUANTITY; index++)
  19944. {
  19945. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19946. {
  19947. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  19948. }
  19949. }// End of for GB_QUANTITY
  19950. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  19951. }
  19952. else if(gunType[gun_index] == GUN_TYPE_DO)
  19953. {
  19954. tempIndex = gun_index;
  19955. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19956. {
  19957. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19958. {
  19959. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  19960. }
  19961. }
  19962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  19963. }
  19964. else
  19965. {
  19966. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19967. {
  19968. tempIndex = 2;
  19969. }
  19970. else
  19971. {
  19972. tempIndex = gun_index;
  19973. }
  19974. for (int index = 0; index < AC_QUANTITY; index++)
  19975. {
  19976. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19977. {
  19978. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  19979. }
  19980. }// End of for AC_QUANTITY
  19981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  19982. }
  19983. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  19984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  19985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  19986. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  19987. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  19988. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  19989. }
  19990. //2.2===================================== Energy.Active.Import.Interval ==========================================
  19991. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  19992. {
  19993. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  19994. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19995. {
  19996. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19997. {
  19998. tempIndex = ((gun_index==2) ? 1: 0);
  19999. }
  20000. else
  20001. {
  20002. tempIndex = gun_index;
  20003. }
  20004. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20005. {
  20006. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20007. {
  20008. 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
  20009. }
  20010. }// END OF CHAdeMO_QUANTITY
  20011. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  20012. }
  20013. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20014. {
  20015. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20016. {
  20017. tempIndex = ((gun_index==2) ? 1: 0);
  20018. }
  20019. else
  20020. {
  20021. tempIndex = gun_index;
  20022. }
  20023. for (int index = 0; index < CCS_QUANTITY; index++)
  20024. {
  20025. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20026. {
  20027. 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
  20028. }
  20029. }// END OF CCS_QUANTITY
  20030. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  20031. }
  20032. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20033. {
  20034. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20035. {
  20036. tempIndex = ((gun_index==2) ? 1: 0);
  20037. }
  20038. else
  20039. {
  20040. tempIndex = gun_index;
  20041. }
  20042. for (int index = 0; index < GB_QUANTITY; index++)
  20043. {
  20044. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20045. {
  20046. 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
  20047. }
  20048. }// END OF GB_QUANTITY
  20049. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  20050. }
  20051. else if(gunType[gun_index] == GUN_TYPE_DO)
  20052. {
  20053. tempIndex = gun_index;
  20054. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20055. {
  20056. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20057. {
  20058. 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
  20059. }
  20060. }
  20061. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  20062. }
  20063. else
  20064. {
  20065. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20066. {
  20067. tempIndex = 2;
  20068. }
  20069. else
  20070. {
  20071. tempIndex = gun_index;
  20072. }
  20073. for (int index = 0; index < AC_QUANTITY; index++)
  20074. {
  20075. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20076. {
  20077. 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
  20078. }
  20079. }// END OF AC_QUANTITY
  20080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  20081. }
  20082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  20084. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  20085. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  20086. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  20087. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  20088. }
  20089. //2.3====================================== Power.Active.Import =========================================
  20090. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  20091. {
  20092. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20093. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20094. {
  20095. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20096. {
  20097. tempIndex = ((gun_index==2) ? 1: 0);
  20098. }
  20099. else
  20100. {
  20101. tempIndex = gun_index;
  20102. }
  20103. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20104. {
  20105. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20106. {
  20107. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20108. }
  20109. } // End for CHAdeMO_QUANTITY
  20110. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  20111. }
  20112. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20113. {
  20114. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20115. {
  20116. tempIndex = ((gun_index==2) ? 1: 0);
  20117. }
  20118. else
  20119. {
  20120. tempIndex = gun_index;
  20121. }
  20122. for (int index = 0; index < CCS_QUANTITY; index++)
  20123. {
  20124. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20125. {
  20126. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20127. }
  20128. } // END for CCS_QUANTITY
  20129. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  20130. }
  20131. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20132. {
  20133. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20134. {
  20135. tempIndex = ((gun_index==2) ? 1: 0);
  20136. }
  20137. else
  20138. {
  20139. tempIndex = gun_index;
  20140. }
  20141. for (int index = 0; index < GB_QUANTITY; index++)
  20142. {
  20143. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20144. {
  20145. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20146. }
  20147. }// END for GB_QUANTITY
  20148. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  20149. }
  20150. else if(gunType[gun_index] == GUN_TYPE_DO)
  20151. {
  20152. tempIndex = gun_index;
  20153. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20154. {
  20155. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20156. {
  20157. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20158. }
  20159. }
  20160. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  20161. }
  20162. else
  20163. {
  20164. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20165. {
  20166. tempIndex = 2;
  20167. }
  20168. else
  20169. {
  20170. tempIndex = gun_index;
  20171. }
  20172. for (int index = 0; index < AC_QUANTITY; index++)
  20173. {
  20174. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20175. {
  20176. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  20177. }
  20178. } // END for AC_QUANTITY
  20179. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  20180. }
  20181. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  20183. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  20184. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  20185. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  20186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  20187. }
  20188. //2.4====================================== Voltage L1 ====================================================
  20189. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  20190. {
  20191. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20192. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20193. {
  20194. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20195. {
  20196. tempIndex = ((gun_index==2) ? 1: 0);
  20197. }
  20198. else
  20199. {
  20200. tempIndex = gun_index;
  20201. }
  20202. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20203. {
  20204. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20205. {
  20206. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  20207. }
  20208. } // END OF FOR CHAdeMO_QUANTITY
  20209. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  20210. }
  20211. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20212. {
  20213. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20214. {
  20215. tempIndex = ((gun_index==2) ? 1: 0);
  20216. }
  20217. else
  20218. {
  20219. tempIndex = gun_index;
  20220. }
  20221. for (int index = 0; index < CCS_QUANTITY; index++)
  20222. {
  20223. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20224. {
  20225. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  20226. }
  20227. } // END OF FOR CCS_QUANTITY
  20228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  20229. }
  20230. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20231. {
  20232. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20233. {
  20234. tempIndex = ((gun_index==2) ? 1: 0);
  20235. }
  20236. else
  20237. {
  20238. tempIndex = gun_index;
  20239. }
  20240. for (int index = 0; index < GB_QUANTITY; index++)
  20241. {
  20242. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20243. {
  20244. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  20245. }
  20246. } // END OF FOR GB_QUANTITY
  20247. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  20248. }
  20249. else if(gunType[gun_index] == GUN_TYPE_DO)
  20250. {
  20251. tempIndex = gun_index;
  20252. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20253. {
  20254. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20255. {
  20256. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  20257. }
  20258. }
  20259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  20260. }
  20261. else
  20262. {
  20263. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20264. {
  20265. tempIndex = 2;
  20266. }
  20267. else
  20268. {
  20269. tempIndex = gun_index;
  20270. }
  20271. for (int index = 0; index < AC_QUANTITY; index++)
  20272. {
  20273. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20274. {
  20275. 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
  20276. }
  20277. } // END OF FOR AC_QUANTITY
  20278. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  20279. }
  20280. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20281. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  20282. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  20283. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  20284. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  20285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  20286. }
  20287. //2.5============================================== End SoC =========================================================
  20288. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  20289. {
  20290. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20291. 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))
  20292. {
  20293. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  20294. {
  20295. tempIndex = ((gun_index==2) ? 1: 0);
  20296. }
  20297. else
  20298. {
  20299. tempIndex = gun_index;
  20300. }
  20301. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20302. {
  20303. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20304. {
  20305. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20306. {
  20307. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  20308. }
  20309. }
  20310. }
  20311. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20312. {
  20313. for (int index = 0; index < CCS_QUANTITY; index++)
  20314. {
  20315. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20316. {
  20317. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  20318. }
  20319. }
  20320. }
  20321. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20322. {
  20323. for (int index = 0; index < GB_QUANTITY; index++)
  20324. {
  20325. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20326. {
  20327. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  20328. }
  20329. }
  20330. }
  20331. else if(gunType[gun_index] == GUN_TYPE_DO)
  20332. {
  20333. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20334. {
  20335. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20336. {
  20337. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  20338. }
  20339. }
  20340. }
  20341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20342. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  20343. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  20344. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  20345. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  20346. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  20347. } // END FOR DC CASE
  20348. }
  20349. //2.6====================================== Current.Import L2 ==============================================
  20350. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  20351. {
  20352. // AC 3 phase L2 current
  20353. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  20354. {
  20355. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20356. {
  20357. tempIndex = 2;
  20358. }
  20359. else
  20360. {
  20361. tempIndex = gun_index;
  20362. }
  20363. for (int index = 0; index < AC_QUANTITY; index++)
  20364. {
  20365. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20366. {
  20367. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  20368. }
  20369. }// End of for AC_QUANTITY
  20370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  20371. }
  20372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  20374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  20375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  20376. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  20377. }
  20378. //2.7====================================== Current.Import L3 ==============================================
  20379. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  20380. {
  20381. // AC 3 phase L3 current
  20382. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  20383. {
  20384. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20385. {
  20386. tempIndex = 2;
  20387. }
  20388. else
  20389. {
  20390. tempIndex = gun_index;
  20391. }
  20392. for (int index = 0; index < AC_QUANTITY; index++)
  20393. {
  20394. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20395. {
  20396. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  20397. }
  20398. }// End of for AC_QUANTITY
  20399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  20400. }
  20401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20402. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  20403. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  20404. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  20405. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  20406. }
  20407. //2.9====================================== Voltage L2 ====================================================
  20408. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  20409. {
  20410. // AC 3 phase L2 volatge
  20411. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  20412. {
  20413. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20414. {
  20415. tempIndex = 2;
  20416. }
  20417. else
  20418. {
  20419. tempIndex = gun_index;
  20420. }
  20421. for (int index = 0; index < AC_QUANTITY; index++)
  20422. {
  20423. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20424. {
  20425. 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
  20426. }
  20427. } // END OF FOR AC_QUANTITY
  20428. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  20429. }
  20430. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20431. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  20432. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  20433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  20434. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  20435. }
  20436. //2.10====================================== Voltage L3 ====================================================
  20437. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  20438. {
  20439. // AC 3 phase L3 volatge
  20440. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  20441. {
  20442. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20443. {
  20444. tempIndex = 2;
  20445. }
  20446. else
  20447. {
  20448. tempIndex = gun_index;
  20449. }
  20450. for (int index = 0; index < AC_QUANTITY; index++)
  20451. {
  20452. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20453. {
  20454. 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
  20455. }
  20456. } // END OF FOR AC_QUANTITY
  20457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  20458. }
  20459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  20460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  20461. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  20462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  20463. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  20464. }
  20465. //====================== Start SoC ================================
  20466. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  20467. {
  20468. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  20469. 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))
  20470. {
  20471. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  20472. {
  20473. tempIndex = ((gun_index==2) ? 1: 0);
  20474. }
  20475. else
  20476. {
  20477. tempIndex = gun_index;
  20478. }
  20479. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20480. {
  20481. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20482. {
  20483. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  20484. {
  20485. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  20486. }
  20487. }
  20488. }
  20489. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20490. {
  20491. for (int index = 0; index < CCS_QUANTITY; index++)
  20492. {
  20493. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20494. {
  20495. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  20496. }
  20497. }
  20498. }
  20499. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20500. {
  20501. for (int index = 0; index < GB_QUANTITY; index++)
  20502. {
  20503. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20504. {
  20505. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  20506. }
  20507. }
  20508. }
  20509. else if(gunType[gun_index] == GUN_TYPE_DO)
  20510. {
  20511. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20512. {
  20513. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20514. {
  20515. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  20516. }
  20517. }
  20518. }
  20519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  20520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  20521. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  20522. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  20523. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  20524. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  20525. } // END FOR DC CASE
  20526. }
  20527. //======================================== Message create ==============================================
  20528. json_object *StopTransaction = json_object_new_object();
  20529. json_object *transactionDatas = json_object_new_array();
  20530. json_object *sampledValues = json_object_new_array();
  20531. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  20532. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  20533. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  20534. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  20535. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  20536. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  20537. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  20538. {
  20539. json_object *transactionData = json_object_new_object();
  20540. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  20541. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  20542. {
  20543. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  20544. {
  20545. json_object *sampledValue = json_object_new_object();
  20546. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  20547. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  20548. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  20549. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  20550. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  20551. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  20552. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  20553. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  20554. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  20555. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  20556. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  20557. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  20558. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  20559. json_object_array_add(sampledValues, sampledValue);
  20560. }
  20561. }
  20562. json_object_object_add(transactionData, "sampledValue", sampledValues);
  20563. json_object_array_add(transactionDatas, transactionData);
  20564. }
  20565. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  20566. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  20567. ,MESSAGE_TYPE_CALL
  20568. ,guid
  20569. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  20570. json_object_put(StopTransaction);
  20571. // Check File "TempStopTransaction" Exist
  20572. if((access(TempStopTransaction,F_OK))!=-1)
  20573. {
  20574. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  20575. fclose(fopen(TempStopTransaction, "w"));
  20576. }
  20577. else
  20578. {
  20579. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  20580. FILE *log = fopen(TempStopTransaction, "w+");
  20581. if(log == NULL)
  20582. {
  20583. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  20584. return ;
  20585. }
  20586. else
  20587. {
  20588. fclose(log);
  20589. }
  20590. }
  20591. //Add TempStopTransaction | Update TempStopTransaction
  20592. // open file for writing
  20593. FILE *outfile;
  20594. outfile = fopen (TempStopTransaction, "a");
  20595. //DEBUG_INFO("data = %s\n", queuedata);
  20596. fputs(queuedata, outfile);
  20597. fputs("\n", outfile);
  20598. fclose (outfile);
  20599. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  20600. OCPP_updatePeriodEnergy(gun_index);
  20601. }
  20602. void checkTempStopTransaction(int gun_index)
  20603. {
  20604. FILE *fptr1;
  20605. char ch;
  20606. char str[QUEUE_MESSAGE_LENGTH]={0};
  20607. char guid[37]={0};
  20608. char tempdata[65]={0};
  20609. char connectorStr[2]={0};
  20610. char TempStopTransaction[256];
  20611. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  20612. fptr1 = fopen(TempStopTransaction, "r");
  20613. //TempStopTransaction格式: 槍號,StopTransaction封包
  20614. if (!fptr1)
  20615. {
  20616. //printf(" File not found or unable to open the input file!!\n");
  20617. return ;
  20618. }
  20619. ch=fgetc(fptr1);
  20620. //printf(" Now the content of the file %s is : \n",fname);
  20621. rewind(fptr1);
  20622. if(ch!=EOF)
  20623. {
  20624. // copy all contents to the temporary file except the specific line
  20625. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  20626. {
  20627. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  20628. if(str[0]=='\0')
  20629. {
  20630. break;
  20631. }
  20632. //TempStopTransaction格式: 槍號,StopTransaction封包
  20633. strncpy(connectorStr, str, 1);
  20634. if(atoi(connectorStr) != (gun_index+1))
  20635. {
  20636. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  20637. fclose(fptr1);
  20638. return ;
  20639. }
  20640. //random_uuid(guid);
  20641. strncpy(guid, str+6, 36); //copy guid
  20642. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  20643. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  20644. {
  20645. //DEBUG_INFO("StopTransaction mapitem pass\n");
  20646. }
  20647. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  20648. OCPP_insert_transaction_msg(NO, str);
  20649. memset(str,0,ARRAY_SIZE(str));
  20650. }
  20651. }
  20652. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  20653. fclose(fptr1);
  20654. remove(TempStopTransaction); // remove the original file
  20655. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  20656. }
  20657. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  20658. {
  20659. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  20660. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  20661. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  20662. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  20663. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  20664. }
  20665. void FillTransactionId(int ConnectorId, int TransactionId)
  20666. {
  20667. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  20668. ShmOCPP16Data->StartTransaction[ConnectorId-1].ResponseTransactionId = TransactionId;
  20669. }
  20670. int GetWebSocketPingInterval(void)
  20671. {
  20672. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  20673. }
  20674. int GetServerSign(void)
  20675. {
  20676. return server_sign;
  20677. }
  20678. uint8_t GetOcppSecurityProfile()
  20679. {
  20680. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  20681. }
  20682. void MergeCertificates()
  20683. {
  20684. char cmdBuf[2048]={0};
  20685. if(access(ROOTCA_CS,F_OK) != -1)
  20686. {
  20687. sprintf(cmdBuf, "cat /root/cacert.pem %s > /root/certCA.pem", ROOTCA_CS);
  20688. }
  20689. else
  20690. {
  20691. sprintf(cmdBuf, "cat /root/cacert.pem > /root/certCA.pem");
  20692. }
  20693. system(cmdBuf);
  20694. }
  20695. void GetOcppChargerBoxId(uint8_t *data)
  20696. {
  20697. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  20698. }
  20699. void GetOcppSecurityPassword(uint8_t *data)
  20700. {
  20701. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  20702. }
  20703. void SetOcppVersion(uint8_t *version)
  20704. {
  20705. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  20706. DEBUG_INFO("ocpp version: %s\n", version);
  20707. if(strstr((char*)version, "ocpp1.6") != NULL)
  20708. {
  20709. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  20710. }
  20711. else if(strstr((char*)version, "ocpp2.0") != NULL)
  20712. {
  20713. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  20714. system("pkill OcppBackend");
  20715. }
  20716. }
  20717. void SetServerSign(int value)
  20718. {
  20719. server_sign = value;
  20720. }
  20721. int GetBootNotificationInterval(void)
  20722. {
  20723. return BootNotificationInterval;
  20724. }
  20725. int GetInternetConn(void)
  20726. {
  20727. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  20728. }
  20729. int GetBackendConnectionTimeout(void)
  20730. {
  20731. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  20732. }
  20733. int isConnectorInitMode(int gun_index)
  20734. {
  20735. int tempIndex = 0;
  20736. int result = TRUE;
  20737. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  20738. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20739. {
  20740. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20741. {
  20742. tempIndex = ((gun_index==2) ? 1: 0);
  20743. }
  20744. else
  20745. {
  20746. tempIndex = gun_index;
  20747. }
  20748. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20749. {
  20750. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  20751. {
  20752. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20753. } //end of the same index
  20754. }//end of for CHAdeMO_QUANTITY
  20755. }
  20756. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20757. {
  20758. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20759. {
  20760. tempIndex = ((gun_index==2) ? 1: 0);
  20761. }
  20762. else
  20763. {
  20764. tempIndex = gun_index;
  20765. }
  20766. for (int index = 0; index < CCS_QUANTITY; index++)
  20767. {
  20768. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20769. {
  20770. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20771. } //end of the same index
  20772. } // end of for CCS_QUANTITY
  20773. }
  20774. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20775. {
  20776. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20777. {
  20778. tempIndex = ((gun_index==2) ? 1: 0);
  20779. }
  20780. else
  20781. {
  20782. tempIndex = gun_index;
  20783. }
  20784. for (int index = 0; index < GB_QUANTITY; index++)
  20785. {
  20786. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20787. {
  20788. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20789. } //end of the same index
  20790. } // end of for GB_QUANTITY
  20791. }
  20792. else if(gunType[gun_index] == GUN_TYPE_DO)
  20793. {
  20794. tempIndex = gun_index;
  20795. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20796. {
  20797. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20798. {
  20799. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20800. } //end of the same index
  20801. }
  20802. }
  20803. else
  20804. {
  20805. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20806. {
  20807. tempIndex = 2;
  20808. }
  20809. else
  20810. {
  20811. tempIndex = gun_index;
  20812. }
  20813. for (int index = 0; index < AC_QUANTITY; index++)
  20814. {
  20815. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20816. {
  20817. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20818. }//end of the same index
  20819. }//end of for AC_QUANTITY
  20820. }
  20821. return result;
  20822. }
  20823. void refreshProcDogTimer()
  20824. {
  20825. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  20826. }
  20827. void InitialSystemValue(void)
  20828. {
  20829. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  20830. locallistVersion=0;
  20831. BootNotificationInterval = 0;
  20832. authorizeRetryTimes = 0;
  20833. GunStatusInterval = 10;
  20834. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  20835. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  20836. //Hear Beat
  20837. HeartBeatWithNOResponse = 0;
  20838. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  20839. FirstHeartBeat = 0;
  20840. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  20841. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  20842. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  20843. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  20844. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  20845. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  20846. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  20847. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  20848. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  20849. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  20850. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  20851. //Status && ConnectorPlugIn Setting
  20852. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20853. {
  20854. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  20855. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  20856. }
  20857. for (int index = 0; index < CCS_QUANTITY; index++)
  20858. {
  20859. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  20860. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  20861. }
  20862. for (int index = 0; index < GB_QUANTITY; index++)
  20863. {
  20864. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  20865. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  20866. }
  20867. for (int index = 0; index < AC_QUANTITY; index++)
  20868. {
  20869. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  20870. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  20871. }
  20872. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20873. {
  20874. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  20875. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  20876. }
  20877. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  20878. {
  20879. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  20880. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  20881. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  20882. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  20883. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  20884. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  20885. }
  20886. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  20887. refreshStartTimer(&clientTime.Heartbeat);
  20888. sleep(1);
  20889. }
  20890. void LWS_Send(char *str)
  20891. {
  20892. //=====================================================
  20893. // Check InternetConn 0: disconnected, 1: connected
  20894. //====================================================
  20895. if(GetOcppConnStatus() == 0)
  20896. {
  20897. DEBUG_INFO("offline now !!!\n");
  20898. return;
  20899. }
  20900. // Only disable isWebsocketSendable operation initiated by charger
  20901. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20902. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20903. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20904. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20905. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20906. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20907. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20908. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20909. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20910. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20911. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20912. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20913. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20914. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20915. {
  20916. isWebsocketSendable = 0;
  20917. }
  20918. pthread_mutex_lock(&lock_send);
  20919. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20920. sprintf((char *)SendBuffer, "%s", str);
  20921. SendBufLen = strlen(str);
  20922. pthread_mutex_unlock(&lock_send);
  20923. lws_callback_on_writable(wsi_client);
  20924. //lws_service(context, 0);
  20925. //sleep(1);
  20926. }
  20927. void LWS_SendNow(char *str)
  20928. {
  20929. //=====================================================
  20930. // Check InternetConn 0: disconnected, 1: connected
  20931. //====================================================
  20932. if(GetOcppConnStatus() == 0)
  20933. {
  20934. DEBUG_INFO("offline now !!!\n");
  20935. return;
  20936. }
  20937. // Only disable isWebsocketSendable operation initiated by charger
  20938. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20939. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20940. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20941. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20942. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20943. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20944. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20945. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20946. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20947. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20948. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20949. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20950. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20951. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20952. {
  20953. isWebsocketSendable = 0;
  20954. }
  20955. pthread_mutex_lock(&lock_send);
  20956. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20957. sprintf((char *)SendBuffer, "%s", str);
  20958. SendBufLen = strlen(str);
  20959. pthread_mutex_unlock(&lock_send);
  20960. lws_callback_on_writable(wsi_client);
  20961. lws_service(context, 0);
  20962. //sleep(1);
  20963. }