MessageHandler.c 837 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266
  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 int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int locallistVersion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  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. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  58. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  59. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  60. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  61. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  62. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  63. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  64. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  65. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  66. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  67. static int TransactionMessageAttemptsValue = 0;
  68. static int TransactionMessageRetryIntervalValue = 0;
  69. static int TempMeterValueInterval = 0;
  70. static struct OCPPAuthLocalElemet
  71. {
  72. int listVersionInt;
  73. char idTagstr[21];
  74. char parentIdTag[21];
  75. char expiryDate[36];
  76. char idTagstatus[16];
  77. }idTagQuery;
  78. //=============================================
  79. // OCPP HeartBeat Response Not Receive Counts
  80. //============================================
  81. static int HeartBeatWithNOResponse = 0;
  82. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  83. extern sqlite3 *db;
  84. int TransactionMessageAttemptsGet(void);
  85. int TransactionMessageRetryIntervalGet(void);
  86. int GetOcppConnStatus(void);
  87. void SetOcppConnStatus(uint8_t status);
  88. int setKeyValue(char *key, char *value);
  89. void OCPP_get_TableAuthlocalAllData(void);
  90. void processUnkownKey(void);
  91. struct StructOCPPMeterValue
  92. {
  93. unsigned char TimeStamp[28];
  94. struct StructSampledValue SampledValue[10];
  95. };
  96. struct ClientTime
  97. {
  98. unsigned int Heartbeat;
  99. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  100. unsigned int StartTransaction;
  101. unsigned int StopTransaction;
  102. unsigned int MeterValues[CONNECTOR_QUANTITY];
  103. }clientTime;
  104. typedef union
  105. {
  106. //Operations Initiated by Central System
  107. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  108. struct
  109. {
  110. //CsMsgValue[0]
  111. unsigned char StatusNotificationReq:1; //bit 0,
  112. unsigned char StatusNotificationConf:1; //bit 1,
  113. unsigned char TriggerMeterValue:1; //bit 2,
  114. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  115. unsigned char isOnCharging:1; //bit 4,
  116. unsigned char :3; //bit5~7
  117. }bits[CONNECTOR_QUANTITY];
  118. }CpinitiateMsg;
  119. CpinitiateMsg cpinitateMsg;
  120. //GetConfiguration Array
  121. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  123. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  124. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  125. #if 0
  126. static char *ChargePointErrorCodeStr[] = {
  127. MACROSTR(ConnectorLockFailure),
  128. MACROSTR(EVCommunicationError),
  129. MACROSTR(GroundFailure),
  130. MACROSTR(HighTemperature),
  131. MACROSTR(InternalError),
  132. MACROSTR(LocalListConflict),
  133. MACROSTR(NoError),
  134. MACROSTR(OtherError),
  135. MACROSTR(OverCurrentFailure),
  136. MACROSTR(OverVoltage),
  137. MACROSTR(PowerMeterFailure),
  138. MACROSTR(PowerSwitchFailure),
  139. MACROSTR(ReaderFailure),
  140. MACROSTR(ResetFailure),
  141. MACROSTR(UnderVoltage),
  142. MACROSTR(WeakSignal)
  143. };
  144. #endif
  145. static char * ChargePointStatusStr[] = {
  146. MACROSTR(Available),
  147. MACROSTR(Preparing),
  148. MACROSTR(Charging),
  149. MACROSTR(SuspendedEVSE),
  150. MACROSTR(SuspendedEV),
  151. MACROSTR(Finishing),
  152. MACROSTR(Reserved),
  153. MACROSTR(Unavailable),
  154. MACROSTR(Faulted)
  155. };
  156. static char *RegistrationStatusStr[] = {
  157. MACROSTR(Accepted),
  158. MACROSTR(Pending),
  159. MACROSTR(Rejected)
  160. };
  161. static char *AvailabilityTypeStr[] = {
  162. MACROSTR(Inoperative),
  163. MACROSTR(Operative)
  164. };
  165. static char *AvailabilityStatusStr[] = {
  166. MACROSTR(Accepted),
  167. MACROSTR(Rejected),
  168. MACROSTR(Scheduled)
  169. };
  170. static char *ConfigurationStatusStr[] = {
  171. MACROSTR(Accepted),
  172. MACROSTR(Rejected),
  173. MACROSTR(RebootRequired),
  174. MACROSTR(NotSupported)
  175. };
  176. static char *ClearCacheStatusStr[] = {
  177. MACROSTR(Accepted),
  178. MACROSTR(Rejected)
  179. };
  180. static char *ChargingProfilePurposeTypeStr[] = {
  181. MACROSTR(ChargePointMaxProfile),
  182. MACROSTR(TxDefaultProfile),
  183. MACROSTR(TxProfile)
  184. };
  185. static char *ChargingProfileStatusStr[] = {
  186. MACROSTR(Accepted),
  187. MACROSTR(Rejected),
  188. MACROSTR(NotSupported)
  189. };
  190. static char *ClearChargingProfileStatusStr[] = {
  191. MACROSTR(Accepted),
  192. MACROSTR(Unknown)
  193. };
  194. static char *GetCompositeScheduleStatusStr[] = {
  195. MACROSTR(Accepted),
  196. MACROSTR(Rejected)
  197. };
  198. static char *UpdateTypeStr[] = {
  199. MACROSTR(Differential),
  200. MACROSTR(Full)
  201. };
  202. static char *UpdateStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Failed),
  205. MACROSTR(NotSupported),
  206. MACROSTR(VersionMismatch)
  207. };
  208. static char *RemoteStartStopStatusStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Rejected)
  211. };
  212. static char *ReservationStatusStr[] = {
  213. MACROSTR(Accepted),
  214. MACROSTR(Faulted),
  215. MACROSTR(Occupied),
  216. MACROSTR(Rejected),
  217. MACROSTR(Unavailable)
  218. };
  219. static char *ResetTypeStr[] = {
  220. MACROSTR(Hard),
  221. MACROSTR(Soft)
  222. };
  223. static char *ResetStatusStr[] = {
  224. MACROSTR(Accepted),
  225. MACROSTR(Rejected)
  226. };
  227. static char * DiagnosticsStatusStr[] = {
  228. MACROSTR(Idle),
  229. MACROSTR(Uploaded),
  230. MACROSTR(UploadFailed),
  231. MACROSTR(Uploading)
  232. };
  233. static char * FirmwareStatusStr[] = {
  234. MACROSTR(Downloaded),
  235. MACROSTR(DownloadFailed),
  236. MACROSTR(Downloading),
  237. MACROSTR(Idle),
  238. MACROSTR(InstallationFailed),
  239. MACROSTR(Installing),
  240. MACROSTR(Installed)
  241. };
  242. static char * MessageTriggerStr[] = {
  243. MACROSTR(BootNotification),
  244. MACROSTR(DiagnosticsStatusNotification),
  245. MACROSTR(FirmwareStatusNotification),
  246. MACROSTR(Heartbeat),
  247. MACROSTR(MeterValues),
  248. MACROSTR(StatusNotification)
  249. };
  250. static char * TriggerMessageStatusStr[] = {
  251. MACROSTR(Accepted),
  252. MACROSTR(Rejected),
  253. MACROSTR(NotImplemented)
  254. };
  255. static char * UnlockStatusStr[] = {
  256. MACROSTR(Unlocked),
  257. MACROSTR(UnlockFailed),
  258. MACROSTR(NotSupported)
  259. };
  260. #if 0
  261. static char * StopTransactionReasonStr[] = {
  262. MACROSTR(EmergencyStop),
  263. MACROSTR(EVDisconnected),
  264. MACROSTR(HardReset),
  265. MACROSTR(Local),
  266. MACROSTR(Other),
  267. MACROSTR(PowerLoss),
  268. MACROSTR(Reboot),
  269. MACROSTR(Remote),
  270. MACROSTR(SoftReset),
  271. MACROSTR(UnlockCommand),
  272. MACROSTR(DeAuthorized)
  273. };
  274. #endif
  275. static char * CancelReservationStatusStr[] = {
  276. MACROSTR(Accepted),
  277. MACROSTR(Rejected)
  278. };
  279. static char * ReadingContextStr[] = {
  280. MACROSTR(Interruption.Begin),
  281. MACROSTR(Interruption.End),
  282. MACROSTR(Other),
  283. MACROSTR(Sample.Clock),
  284. MACROSTR(Sample.Periodic),
  285. MACROSTR(Transaction.Begin),
  286. MACROSTR(Transaction.End),
  287. MACROSTR(Trigger)
  288. };
  289. static char * ValueFormatStr[] = {
  290. MACROSTR(Raw),
  291. MACROSTR(SignedData)
  292. };
  293. static char * MeasurandStr[] = {
  294. MACROSTR(Current.Export),
  295. MACROSTR(Current.Import),
  296. MACROSTR(Current.Offered),
  297. MACROSTR(Energy.Active.Export.Register),
  298. MACROSTR(Energy.Active.Import.Register),
  299. MACROSTR(Energy.Reactive.Export.Register),
  300. MACROSTR(Energy.Reactive.Import.Register),
  301. MACROSTR(Energy.Active.Export.Interval),
  302. MACROSTR(Energy.Active.Import.Interval),
  303. MACROSTR(Energy.Reactive.Export.Interval),
  304. MACROSTR(Energy.Reactive.Import.Interval),
  305. MACROSTR(Frequency),
  306. MACROSTR(Power.Active.Export),
  307. MACROSTR(Power.Active.Import),
  308. MACROSTR(Power.Factor),
  309. MACROSTR(Power.Offered),
  310. MACROSTR(Power.Reactive.ExportMACROSTR),
  311. MACROSTR(Power.Reactive.Import),
  312. MACROSTR(RPM),
  313. MACROSTR(SoC),
  314. MACROSTR(Temperature),
  315. MACROSTR(Voltage)
  316. };
  317. static char * LocationStr[] = {
  318. MACROSTR(Body),
  319. MACROSTR(Cable),
  320. MACROSTR(EV),
  321. MACROSTR(Inlet),
  322. MACROSTR(Outlet)
  323. };
  324. static char * PhaseStr[] = {
  325. MACROSTR(L1),
  326. MACROSTR(L2),
  327. MACROSTR(L3),
  328. MACROSTR(N),
  329. MACROSTR(L1-N),
  330. MACROSTR(L2-N),
  331. MACROSTR(L3-N),
  332. MACROSTR(L1-L2),
  333. MACROSTR(L2-L3),
  334. MACROSTR(L3-L1)
  335. };
  336. static char * UnitOfMeasureStr[] = {
  337. MACROSTR(Wh),
  338. MACROSTR(kWh),
  339. MACROSTR(varh),
  340. MACROSTR(kvarh),
  341. MACROSTR(W),
  342. MACROSTR(kW),
  343. MACROSTR(VA),
  344. MACROSTR(kVA),
  345. MACROSTR(var),
  346. MACROSTR(kvar),
  347. MACROSTR(A),
  348. MACROSTR(V),
  349. MACROSTR(Celsius),
  350. MACROSTR(Fahrenheit),
  351. MACROSTR(K),
  352. MACROSTR(Percent)
  353. };
  354. //=========================================
  355. // TTIA routine
  356. //=========================================
  357. int sendTTIAInfo(uint8_t gun_index)
  358. {
  359. static int sn = 0;
  360. int result = FAIL;
  361. struct hostent *server;
  362. int udp_socket_fd;
  363. struct sockaddr_in dest_addr = {0};
  364. uint8_t tx_buf[80] = {0};
  365. uint8_t logBuf[256]= {0};
  366. uint8_t tempIndex, socStart, socEnd;
  367. uint16_t PresentChargedEnergy;
  368. struct tm tmStart, tmEnd;
  369. DEBUG_INFO("sendTTIAInfo...\n");
  370. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  371. {
  372. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  373. {
  374. tempIndex = ((gun_index==2) ? 1: 0);
  375. }
  376. else
  377. {
  378. tempIndex = gun_index;
  379. }
  380. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  381. {
  382. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  383. {
  384. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  385. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  386. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  387. }
  388. }
  389. }
  390. else if(gunType[gun_index] == GUN_TYPE_CCS)
  391. {
  392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  393. {
  394. tempIndex = ((gun_index==2) ? 1: 0);
  395. }
  396. else
  397. {
  398. tempIndex = gun_index;
  399. }
  400. for (int index = 0; index < CCS_QUANTITY; index++)
  401. {
  402. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  403. {
  404. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  405. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  406. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  407. }
  408. }
  409. }
  410. else if(gunType[gun_index] == GUN_TYPE_GBT)
  411. {
  412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  413. {
  414. tempIndex = ((gun_index==2) ? 1: 0);
  415. }
  416. else
  417. {
  418. tempIndex = gun_index;
  419. }
  420. for (int index = 0; index < GB_QUANTITY; index++)
  421. {
  422. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  423. {
  424. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  425. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  426. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  427. }
  428. }
  429. }
  430. else if(gunType[gun_index] == GUN_TYPE_DO)
  431. {
  432. tempIndex = gun_index;
  433. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  434. {
  435. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  436. {
  437. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  438. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  439. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  440. }
  441. }
  442. }
  443. else
  444. {
  445. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  446. {
  447. tempIndex = 2;
  448. }
  449. else
  450. {
  451. tempIndex = gun_index;
  452. }
  453. for (int index = 0; index < AC_QUANTITY; index++)
  454. {
  455. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  456. {
  457. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  458. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  459. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  460. }
  461. }// END
  462. }
  463. // Message assembly
  464. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  465. tx_buf[4] = 0x02; // Protocol Version
  466. tx_buf[5] = 0xb0; // Message ID
  467. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  468. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  469. tx_buf[8] = 0x00; // CarID low byte
  470. tx_buf[9] = 0x00; // CarID high byte
  471. tx_buf[10] = 0x00; // ID Storage
  472. tx_buf[11] = 0x00; // Driver lowest byte
  473. tx_buf[12] = 0x00; // Driver 2nd byte
  474. tx_buf[13] = 0x00; // Driver 3rd byte
  475. tx_buf[14] = 0x00; // Driver highest byte
  476. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  477. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  478. tx_buf[17] = 0x00; // Reserve
  479. tx_buf[18] = 60 & 0xff; // Payload length low byte
  480. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  481. // EVSE provider
  482. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  483. // EVSE provider
  484. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  485. // EVSE id
  486. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  487. // Connector id
  488. tx_buf[37] = gun_index;
  489. // EVSE station
  490. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  491. // Vehicle SN
  492. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  493. // Mileage
  494. tx_buf[61] = 0x00; // lowest byte
  495. tx_buf[62] = 0x00; // 2nd byte
  496. tx_buf[63] = 0x00; // highest byte
  497. // Start date time 6 bytes
  498. 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))
  499. {
  500. tx_buf[64] = (tmStart.tm_year-2000);
  501. tx_buf[65] = tmStart.tm_mon;
  502. tx_buf[66] = tmStart.tm_mday;
  503. tx_buf[67] = tmStart.tm_hour;
  504. tx_buf[68] = tmStart.tm_min;
  505. tx_buf[69] = tmStart.tm_sec;
  506. }
  507. // Stop date time 6 bytes
  508. 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))
  509. {
  510. tx_buf[70] = (tmEnd.tm_year-2000);
  511. tx_buf[71] = tmEnd.tm_mon;
  512. tx_buf[72] = tmEnd.tm_mday;
  513. tx_buf[73] = tmEnd.tm_hour;
  514. tx_buf[74] = tmEnd.tm_min;
  515. tx_buf[75] = tmEnd.tm_sec;
  516. }
  517. // Session energy 2 bytes
  518. tx_buf[76] = PresentChargedEnergy & 0xff;
  519. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  520. // Start SOC 1 byte
  521. tx_buf[78] = socStart;
  522. // Stop SOC 1 byte
  523. tx_buf[79] = socEnd;
  524. // Open socket
  525. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  526. if(udp_socket_fd == -1)
  527. {
  528. DEBUG_ERROR("UDP socket create failed!\n");
  529. }
  530. else
  531. {
  532. // Get server DNS entry
  533. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  534. if (server == NULL)
  535. {
  536. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  537. }
  538. else
  539. {
  540. // Build the server's Internet address
  541. bzero((char *) &dest_addr, sizeof(dest_addr));
  542. dest_addr.sin_family = AF_INET;
  543. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  544. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  545. if(sendto(udp_socket_fd, tx_buf, strlen((char*)tx_buf), 0, &dest_addr, sizeof(dest_addr)) >= 0)
  546. {
  547. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  548. {
  549. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  550. }
  551. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  552. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  553. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  554. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  555. DEBUG_TTIA_INFO("---------- Header ----------\n");
  556. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  557. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  558. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  559. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  560. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  561. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  562. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  563. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  564. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  565. DEBUG_TTIA_INFO("Len: 0x3C\n");
  566. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  567. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  568. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  569. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  570. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  571. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  572. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  573. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  574. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  575. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  576. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  577. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  578. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  579. DEBUG_TTIA_INFO("=========================================\n");
  580. sn++;
  581. result = PASS;
  582. }
  583. else
  584. {
  585. DEBUG_ERROR("UDP sent out fail.\n");
  586. }
  587. }
  588. }
  589. return result;
  590. }
  591. //=========================================
  592. // Save configuration
  593. //=========================================
  594. int runShellCmd(const char*cmd)
  595. {
  596. int result = FAIL;
  597. char buf[256];
  598. FILE *fp;
  599. fp = popen(cmd, "r");
  600. if(fp != NULL)
  601. {
  602. while(fgets(buf, sizeof(buf), fp) != NULL)
  603. {
  604. DEBUG_INFO("%s\n", buf);
  605. }
  606. result = PASS;
  607. }
  608. pclose(fp);
  609. return result;
  610. }
  611. int StoreUsrConfigData(struct SysConfigData *UsrData)
  612. {
  613. int result = PASS;
  614. int fd,wrd;
  615. unsigned int i,Chk;
  616. unsigned char *ptr, *BufTmp;
  617. int MtdBlockSize = 0x300000;
  618. Chk=0;
  619. ptr=(unsigned char *)UsrData;
  620. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  621. {
  622. memset(BufTmp,0,MtdBlockSize);
  623. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  624. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  625. Chk+=*(BufTmp+i);
  626. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  627. // Output configuration to file.
  628. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  629. if (fd < 0)
  630. {
  631. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  632. free(BufTmp);
  633. return 0;
  634. }
  635. wrd=write(fd, BufTmp, MtdBlockSize);
  636. close(fd);
  637. if(wrd<MtdBlockSize)
  638. {
  639. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  640. free(BufTmp);
  641. return 0;
  642. }
  643. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  644. DEBUG_INFO("Erase /dev/mtd10.\n");
  645. runShellCmd("flash_erase /dev/mtd10 0 0");
  646. DEBUG_INFO("Write /dev/mtd10.\n");
  647. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  648. DEBUG_INFO("Erase /dev/mtd11.\n");
  649. runShellCmd("flash_erase /dev/mtd11 0 0");
  650. DEBUG_INFO("Write /dev/mtd11.\n");
  651. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  652. system("rm -f /mnt/EvseConfig.bin");
  653. DEBUG_INFO("EvseConfig write to flash OK\n");
  654. }
  655. else
  656. {
  657. DEBUG_ERROR("alloc BlockSize NG\r\n");
  658. result = FAIL;
  659. }
  660. if(BufTmp!=NULL)
  661. free(BufTmp);
  662. return result;
  663. }
  664. //=========================================
  665. // Sqlite3 related function
  666. //=========================================
  667. static int selectSqlCount = 0;
  668. static int callback(void *data, int argc, char **argv, char **azColName){
  669. int i;
  670. //printf("%s: ", (const char*)data);
  671. selectSqlCount = argc;
  672. for(i = 0; i<argc; i++){
  673. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  674. }
  675. //printf("\n");
  676. return 0;
  677. }
  678. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  679. //int i;
  680. //printf("%s:\n", (const char*)data);
  681. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  682. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  683. return 0;
  684. }
  685. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  686. //printf("%s:\n", (const char*)data);
  687. //idTag
  688. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  689. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  690. //parentIdTag
  691. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  692. //expir_date
  693. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  694. //status
  695. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  696. //version
  697. if(columenCount > 5)
  698. idTagQuery.listVersionInt = atoi(columnValue[5]);
  699. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  700. return 0;
  701. }
  702. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  703. {
  704. // localversion = argv[5] ? atoi(argv[5]) : 0;
  705. // printf("localversion=%d\n", localversion);
  706. return 0;
  707. }
  708. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  709. {
  710. for (int i = 0; i < n_columns; i++)
  711. {
  712. DEBUG_INFO("%s\t", col_values[i]);
  713. }
  714. DEBUG_INFO("\n");
  715. return 0;
  716. }
  717. int OCPP_cleanLocalCache()
  718. {
  719. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  720. char *errMsg = 0;
  721. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  722. if (SQLITE_OK != rc)
  723. {
  724. DEBUG_INFO("SQL error: %s\n",errMsg);
  725. return FALSE;
  726. }
  727. return TRUE;
  728. }
  729. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  730. {
  731. int isSuccess = TRUE;
  732. int ret = 0;
  733. //const char* data = "Callback function called";
  734. char sql[300];
  735. char zErrMsg[200];
  736. memset(sql, 0, 300);
  737. memset(zErrMsg, 0, 200);
  738. 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);
  739. //* Execute SQL statement */
  740. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  741. if( ret != SQLITE_OK )
  742. {
  743. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  744. isSuccess = FALSE;
  745. }
  746. return isSuccess;
  747. }
  748. void OCPP_getIdTagFromLocalCache(char idTag[])
  749. {
  750. int rc = 0;
  751. char sql[100];
  752. char zErrMsg[100];
  753. memset(sql, 0, 100);
  754. memset(zErrMsg, 0, 100);
  755. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  756. memset(&idTagQuery, 0, sizeof(idTagQuery));
  757. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  758. /* Execute SQL statement */
  759. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  760. if( rc != SQLITE_OK )
  761. {
  762. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  763. }
  764. }
  765. void OCPP_getListVerion()
  766. {
  767. int rc = 0;
  768. // const char* data = "Callback function called";
  769. char sql[100];
  770. char zErrMsg[100];
  771. memset(sql, 0, 100);
  772. memset(zErrMsg, 0, 100);
  773. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  774. /* Execute SQL statement */
  775. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  776. if( rc != SQLITE_OK )
  777. {
  778. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  779. }
  780. }
  781. void OCPP_get_TableAuthlocalAllData(void)
  782. {
  783. int rc = 0;
  784. char sql[100];
  785. char zErrMsg[100];
  786. memset(sql, 0, 100);
  787. memset(zErrMsg, 0, 100);
  788. sprintf(sql,"select * from ocpp_auth_local ");
  789. /* Execute SQL statement */
  790. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  791. if( rc != SQLITE_OK )
  792. {
  793. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  794. }
  795. //return ver;
  796. }
  797. int OCPP_cleanLocalList()
  798. {
  799. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  800. char *errMsg = 0;
  801. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  802. if (SQLITE_OK != rc)
  803. {
  804. DEBUG_INFO("%s\n",errMsg);
  805. return FALSE;
  806. }
  807. return TRUE;
  808. }
  809. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  810. {
  811. int isSuccess = FALSE;
  812. int ret = 0;
  813. //const char* data = "Callback function called";
  814. char sql[300];
  815. char zErrMsg[200];
  816. memset(sql, 0, 300);
  817. memset(zErrMsg, 0, 200);
  818. 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);
  819. //* Execute SQL statement */
  820. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  821. if( ret != SQLITE_OK )
  822. {
  823. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  824. return isSuccess;
  825. }
  826. memset(sql, 0, 300);
  827. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  828. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  829. if( ret != SQLITE_OK )
  830. {
  831. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  832. return isSuccess;
  833. }
  834. isSuccess = TRUE;
  835. return isSuccess;
  836. }
  837. void OCPP_getIdTagFromLocalList(char idTag[])
  838. {
  839. int rc = 0;
  840. // const char* data = "Callback function called";
  841. char sql[100];
  842. char zErrMsg[100];
  843. memset(sql, 0, 100);
  844. memset(zErrMsg, 0, 100);
  845. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  846. memset(&idTagQuery, 0, sizeof(idTagQuery));
  847. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  848. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  849. /* Execute SQL statement */
  850. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  851. if( rc != SQLITE_OK )
  852. {
  853. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  854. }
  855. //return ver;
  856. }
  857. void OCPP_deleteIdTagFromLocalList(char idTag[])
  858. {
  859. //int ver = 0;
  860. //int isSuccess = FALSE;
  861. int rc = 0;
  862. char sql[100];
  863. char zErrMsg[100];
  864. memset(sql, 0, 100);
  865. memset(zErrMsg, 0, 100);
  866. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  867. //* Execute SQL statement */
  868. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  869. if( rc != SQLITE_OK )
  870. {
  871. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  872. }
  873. }
  874. int getCurrentYear()
  875. {
  876. int result = 0;
  877. time_t CurrentTime;
  878. struct tm *tm;
  879. CurrentTime = time(NULL);
  880. tm=localtime(&CurrentTime);
  881. result = (tm->tm_year + 1900);
  882. return result;
  883. }
  884. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  885. {
  886. int result = PASS;
  887. char* errMsg = NULL;
  888. char sqlStr[8192];
  889. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  890. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  891. {
  892. result = FAIL;
  893. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  894. }
  895. 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));
  896. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  897. {
  898. result = FAIL;
  899. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  900. }
  901. return result;
  902. }
  903. //==========================================
  904. // Check time passed since today
  905. //==========================================
  906. long long DiffTimebWithNow(struct timeb ST)
  907. {
  908. //return milli-second
  909. struct timeb ET;
  910. long long StartTime,StopTime;
  911. ftime(&ET);
  912. StartTime=(long long)ST.time;
  913. StopTime=(long long)ET.time;
  914. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  915. }
  916. int getTimePassSinceToday(uint8_t gun_index)
  917. {
  918. int result = -1;
  919. static time_t lastTime[4];
  920. time_t t;
  921. struct tm *tmStartToday;
  922. struct timeb tbStartToday;
  923. t=time(NULL);
  924. if(difftime(t, lastTime[gun_index])>0)
  925. {
  926. tmStartToday=localtime(&t);
  927. tmStartToday->tm_hour = 0;
  928. tmStartToday->tm_min = 0;
  929. tmStartToday->tm_sec = 0;
  930. tbStartToday.time = mktime(tmStartToday);
  931. tbStartToday.millitm = 0;
  932. result = DiffTimebWithNow(tbStartToday)/1000;
  933. lastTime[gun_index] = t;
  934. }
  935. return result;
  936. }
  937. void getNowDatetime(uint8_t *data)
  938. {
  939. time_t t = time(NULL);
  940. struct tm tm = *localtime(&t);
  941. 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);
  942. }
  943. int syncDateTimeRTC(uint8_t *data)
  944. {
  945. struct ParsingResult
  946. {
  947. int result;
  948. int scanedElement;
  949. int year;
  950. int month;
  951. int mday;
  952. int hour;
  953. int min;
  954. int sec;
  955. int tz_hour;
  956. int tz_min;
  957. float minSec;
  958. }result;
  959. struct tm tmOrg;
  960. struct tm *tmTarget;
  961. struct timeb tbTarget;
  962. char buf[128];
  963. memset(&result, 0x00, sizeof(struct ParsingResult));
  964. result.result = PASS;
  965. if(strstr((char*)data, ".") != NULL)
  966. {
  967. // Original data with mini second
  968. if(strstr((char*)data, "Z") != NULL)
  969. {
  970. // Original data with Z
  971. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  972. &result.year,
  973. &result.month,
  974. &result.mday,
  975. &result.hour,
  976. &result.min,
  977. &result.sec,
  978. &result.minSec);
  979. }
  980. else
  981. {
  982. // Original data without Z
  983. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  984. &result.year,
  985. &result.month,
  986. &result.mday,
  987. &result.hour,
  988. &result.min,
  989. &result.sec,
  990. &result.minSec,
  991. &result.tz_hour,
  992. &result.tz_min);
  993. }
  994. }
  995. else
  996. {
  997. // Original data without mini second
  998. if(strstr((char*)data, "Z") != NULL)
  999. {
  1000. // Original data with Z
  1001. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1002. &result.year,
  1003. &result.month,
  1004. &result.mday,
  1005. &result.hour,
  1006. &result.min,
  1007. &result.sec);
  1008. }
  1009. else
  1010. {
  1011. // Original data without Z
  1012. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1013. &result.year,
  1014. &result.month,
  1015. &result.mday,
  1016. &result.hour,
  1017. &result.min,
  1018. &result.sec,
  1019. &result.tz_hour,
  1020. &result.tz_min);
  1021. }
  1022. }
  1023. tmOrg.tm_year = result.year - 1900;
  1024. tmOrg.tm_mon = result.month - 1;
  1025. tmOrg.tm_mday = result.mday;
  1026. tmOrg.tm_hour = result.hour;
  1027. tmOrg.tm_min = result.min;
  1028. tmOrg.tm_sec = result.sec;
  1029. tmOrg.tm_gmtoff = 0;
  1030. tbTarget.time = mktime(&tmOrg);
  1031. tbTarget.timezone = 0;
  1032. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1033. tmTarget = gmtime(&tbTarget.time);
  1034. 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);
  1035. //DEBUG_INFO(" org date time: %s\n", data);
  1036. //DEBUG_INFO("parse date time: %s\n", buf);
  1037. system(buf);
  1038. system("/sbin/hwclock -w --systohc");
  1039. if(result.scanedElement < 6)
  1040. result.result = FAIL;
  1041. return result.result;
  1042. }
  1043. //==========================================
  1044. // GetCompositeSchedule logic related function
  1045. //==========================================
  1046. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1047. {
  1048. //return milli-second
  1049. unsigned int StartTime,StopTime;
  1050. StartTime=(unsigned int)ST.time;
  1051. StopTime=(unsigned int)ET.time;
  1052. return (StopTime-StartTime);
  1053. }
  1054. int DiffTimebWithNowSec(struct timeb ST)
  1055. {
  1056. //return milli-second
  1057. struct timeb ET;
  1058. unsigned int StartTime,StopTime;
  1059. ftime(&ET);
  1060. StartTime=(unsigned int)ST.time;
  1061. StopTime=(unsigned int)ET.time;
  1062. return (StopTime-StartTime);
  1063. }
  1064. int getStartStop(uint8_t *start, uint8_t *stop)
  1065. {
  1066. int result = -1;
  1067. struct tm tmStart;
  1068. struct timeb tbStart;
  1069. struct tm tmStop;
  1070. struct timeb tbStop;
  1071. if((sscanf((char*)start, "%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) &&
  1072. (sscanf((char*)stop, "%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))
  1073. {
  1074. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  1075. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  1076. tmStart.tm_year -= 1900;
  1077. tmStart.tm_mon -= 1;
  1078. tbStart.time = mktime(&tmStart);
  1079. tbStart.millitm = 0;
  1080. tmStop.tm_year -= 1900;
  1081. tmStop.tm_mon -= 1;
  1082. tbStop.time = mktime(&tmStop);
  1083. tbStop.millitm = 0;
  1084. result = DiffTimebSec(tbStart, tbStop);
  1085. //DEBUG_INFO("getStartStop(): %d\n", result);
  1086. }
  1087. else
  1088. {
  1089. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1090. }
  1091. return result;
  1092. }
  1093. int isOvertNow(uint8_t *start)
  1094. {
  1095. int result = NO;
  1096. struct tm tmStart;
  1097. struct timeb tbStart;
  1098. if((sscanf((char*)start, "%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))
  1099. {
  1100. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  1101. tmStart.tm_year -= 1900;
  1102. tmStart.tm_mon -= 1;
  1103. tbStart.time = mktime(&tmStart);
  1104. tbStart.millitm = 0;
  1105. if(DiffTimebWithNowSec(tbStart) <= 0)
  1106. result = NO;
  1107. else
  1108. result = YES;
  1109. }
  1110. else
  1111. {
  1112. DEBUG_WARN("Start date parsing error.\n");
  1113. }
  1114. return result;
  1115. }
  1116. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1117. {
  1118. int result = -1;
  1119. struct tm tmStart;
  1120. struct timeb tbStart;
  1121. struct tm tmStop;
  1122. struct timeb tbStop;
  1123. if((sscanf((char*)start, "%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) &&
  1124. (sscanf((char*)stop, "%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))
  1125. {
  1126. tmStart.tm_year -= 1900;
  1127. tmStart.tm_mon -= 1;
  1128. tbStart.time = mktime(&tmStart);
  1129. tbStart.millitm = 0;
  1130. tmStop.tm_year -= 1900;
  1131. tmStop.tm_mon -= 1;
  1132. tbStop.time = mktime(&tmStop);
  1133. tbStop.millitm = 0;
  1134. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1135. }
  1136. return result;
  1137. }
  1138. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1139. {
  1140. FILE *fp;
  1141. char profileFileName[128];
  1142. char *line = NULL;
  1143. size_t len = 0;
  1144. time_t CurrentTime;
  1145. struct tm *tmComposite;
  1146. struct StructChargingProfile maxProfile;
  1147. uint8_t limitMax=0;
  1148. int compositePeriodIdx = 0;
  1149. CurrentTime = time(NULL);
  1150. tmComposite=localtime(&CurrentTime);
  1151. 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);
  1152. if(isUnitA)
  1153. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1154. else
  1155. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1156. compositeProfile->ChargingSchedule.Duration = durationReq;
  1157. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1158. {
  1159. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1160. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1161. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1162. }
  1163. compositeProfile->ChargingProfileId = 0;
  1164. compositeProfile->StackLevel = 99 ;
  1165. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1166. maxProfile.ChargingProfileId = -1;
  1167. maxProfile.ChargingSchedule.Duration = -1;
  1168. system("rm -f /tmp/*.json");
  1169. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1170. // Search max profile
  1171. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1172. if((access(profileFileName, F_OK))!=-1)
  1173. {
  1174. fp = fopen(profileFileName, "r");
  1175. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1176. {
  1177. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1178. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1179. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1180. }
  1181. maxProfile.ChargingProfileId = -1;
  1182. maxProfile.StackLevel = -1;
  1183. while(getline(&line, &len, fp) != -1)
  1184. {
  1185. json_object *obj = NULL;
  1186. obj = json_tokener_parse(line);
  1187. if(is_error(obj))
  1188. {
  1189. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1190. }
  1191. else
  1192. {
  1193. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1194. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1195. )
  1196. {
  1197. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1198. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1199. )
  1200. {
  1201. struct tm tmFrom, tmTo;
  1202. struct timeb tbFrom, tbTo;
  1203. 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) &&
  1204. (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))
  1205. {
  1206. tmFrom.tm_year -= 1900;
  1207. tmFrom.tm_mon -= 1;
  1208. tbFrom.time = mktime(&tmFrom);
  1209. tmTo.tm_year -= 1900;
  1210. tmTo.tm_mon -= 1;
  1211. tbTo.time = mktime(&tmTo);
  1212. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1213. {
  1214. if(maxProfile.ChargingProfileId == -1)
  1215. DEBUG_INFO("MaxProfile found.\n");
  1216. else
  1217. DEBUG_INFO("MaxProfile updated.\n");
  1218. // Required item
  1219. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1220. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1221. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1222. if(isUnitA)
  1223. {
  1224. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1225. 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++)
  1226. {
  1227. 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"));
  1228. 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?
  1229. 3:
  1230. 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")));
  1231. 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")));
  1232. }
  1233. }
  1234. else
  1235. {
  1236. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1237. 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++)
  1238. {
  1239. 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"));
  1240. 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?
  1241. 3:
  1242. 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")));
  1243. 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));
  1244. }
  1245. }
  1246. // Optional item
  1247. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1248. {
  1249. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1250. }
  1251. else
  1252. {
  1253. sprintf((char*)maxProfile.ValidFrom, " ");
  1254. }
  1255. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1256. {
  1257. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1258. }
  1259. else
  1260. {
  1261. sprintf((char*)maxProfile.ValidTo, " ");
  1262. }
  1263. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1264. {
  1265. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1266. }
  1267. else
  1268. {
  1269. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1270. }
  1271. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1272. {
  1273. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1274. }
  1275. else
  1276. {
  1277. maxProfile.TransactionId = -1;
  1278. }
  1279. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1280. {
  1281. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1282. }
  1283. else
  1284. {
  1285. maxProfile.ChargingSchedule.Duration = 86400;
  1286. }
  1287. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1288. {
  1289. 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")));
  1290. }
  1291. else
  1292. {
  1293. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1294. }
  1295. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1296. {
  1297. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1298. }
  1299. else
  1300. {
  1301. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1302. }
  1303. }
  1304. }
  1305. }
  1306. else
  1307. {
  1308. if(maxProfile.ChargingProfileId == -1)
  1309. DEBUG_INFO("MaxProfile found.\n");
  1310. else
  1311. DEBUG_INFO("MaxProfile updated.\n");
  1312. // Required item
  1313. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1314. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1315. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1316. if(isUnitA)
  1317. {
  1318. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1319. 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++)
  1320. {
  1321. 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"));
  1322. 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?
  1323. 3:
  1324. 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")));
  1325. 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")));
  1326. }
  1327. }
  1328. else
  1329. {
  1330. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1331. 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++)
  1332. {
  1333. 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"));
  1334. 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?
  1335. 3:
  1336. 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")));
  1337. 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));
  1338. }
  1339. }
  1340. // Optional item
  1341. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1342. {
  1343. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1344. }
  1345. else
  1346. {
  1347. sprintf((char*)maxProfile.ValidFrom, " ");
  1348. }
  1349. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1350. {
  1351. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1352. }
  1353. else
  1354. {
  1355. sprintf((char*)maxProfile.ValidTo, " ");
  1356. }
  1357. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1358. {
  1359. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1360. }
  1361. else
  1362. {
  1363. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1364. }
  1365. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1366. {
  1367. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1368. }
  1369. else
  1370. {
  1371. maxProfile.TransactionId = -1;
  1372. }
  1373. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1374. {
  1375. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1376. }
  1377. else
  1378. {
  1379. maxProfile.ChargingSchedule.Duration = 86400;
  1380. }
  1381. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1382. {
  1383. 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")));
  1384. }
  1385. else
  1386. {
  1387. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1388. }
  1389. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1390. {
  1391. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1392. }
  1393. else
  1394. {
  1395. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1396. }
  1397. }
  1398. }
  1399. }
  1400. json_object_put(obj);
  1401. }
  1402. fclose(fp);
  1403. /*
  1404. if(maxProfile.ChargingProfileId !=-1)
  1405. {
  1406. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1407. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1408. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1409. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1410. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1411. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1412. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1413. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1414. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1415. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1416. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1417. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1418. {
  1419. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1420. {
  1421. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1422. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1423. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1424. }
  1425. }
  1426. }
  1427. else
  1428. DEBUG_INFO("MaxProfile not found.\n");
  1429. DEBUG_INFO("------------------------------------\n");*/
  1430. }
  1431. if(maxProfile.ChargingProfileId != -1)
  1432. {
  1433. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1434. {
  1435. if(maxProfile.ChargingSchedule.Duration != -1)
  1436. {
  1437. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1438. 0:
  1439. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1440. }
  1441. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1442. {
  1443. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1444. {
  1445. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1446. 0:
  1447. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1448. if(idxPeriod > 0)
  1449. {
  1450. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1451. {
  1452. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1453. }
  1454. }
  1455. }
  1456. }
  1457. }
  1458. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1459. {
  1460. if(maxProfile.ChargingSchedule.Duration != -1)
  1461. {
  1462. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1463. }
  1464. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1465. {
  1466. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1467. {
  1468. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1469. if(idxPeriod > 0)
  1470. {
  1471. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1472. {
  1473. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1474. }
  1475. }
  1476. }
  1477. }
  1478. }
  1479. else
  1480. {
  1481. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1482. {
  1483. if(maxProfile.ChargingSchedule.Duration != -1)
  1484. {
  1485. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1486. 0:
  1487. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1488. }
  1489. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1490. {
  1491. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1492. {
  1493. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1494. 0:
  1495. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1496. if(idxPeriod > 0)
  1497. {
  1498. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1499. {
  1500. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1501. }
  1502. }
  1503. }
  1504. }
  1505. }
  1506. else
  1507. {
  1508. if(maxProfile.ChargingSchedule.Duration != -1)
  1509. {
  1510. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1511. 0:
  1512. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1513. }
  1514. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1515. {
  1516. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1517. {
  1518. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1519. 0:
  1520. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1521. if(idxPeriod > 0)
  1522. {
  1523. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1524. {
  1525. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1526. }
  1527. }
  1528. }
  1529. }
  1530. }
  1531. }
  1532. /*
  1533. DEBUG_INFO("MaxProfile after align.\n");
  1534. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1535. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1536. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1537. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1538. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1539. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1540. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1541. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1542. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1543. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1544. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1545. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1546. {
  1547. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1548. {
  1549. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1550. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1551. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1552. }
  1553. }
  1554. DEBUG_INFO("------------------------------------\n");*/
  1555. }
  1556. // Find each profile period quantity
  1557. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1558. {
  1559. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1560. limitMax = idx+1;
  1561. }
  1562. if(maxProfile.ChargingProfileId != -1)
  1563. {
  1564. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1565. {
  1566. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1567. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1568. (maxProfile.ChargingSchedule.Duration > 0))
  1569. {
  1570. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1571. {
  1572. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1573. compositePeriodIdx++;
  1574. }
  1575. else
  1576. {
  1577. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1578. }
  1579. }
  1580. }
  1581. }
  1582. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1583. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1584. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1585. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1586. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1587. {
  1588. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1589. {
  1590. compositeProfile->ChargingProfileId = 1;
  1591. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1592. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1593. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1594. }
  1595. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1596. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1597. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1598. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1599. }
  1600. if(line)
  1601. free(line);
  1602. }
  1603. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1604. {
  1605. FILE *fp;
  1606. char profileFileName[128];
  1607. char *line = NULL;
  1608. size_t len = 0;
  1609. time_t CurrentTime;
  1610. struct tm *tmComposite;
  1611. struct StructChargingProfile maxProfile;
  1612. struct StructChargingProfile defaultTxProfile;
  1613. struct StructChargingProfile txProfile;
  1614. struct StructChargingSchedulePeriod tmpPeriod;
  1615. uint8_t limitMax=0;
  1616. uint8_t limitDef=0;
  1617. uint8_t limitTx=0;
  1618. int compositePeriodIdx = 0;
  1619. CurrentTime = time(NULL);
  1620. tmComposite=localtime(&CurrentTime);
  1621. 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);
  1622. if(isUnitA)
  1623. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1624. else
  1625. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1626. compositeProfile->ChargingSchedule.Duration = durationReq;
  1627. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1628. {
  1629. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1630. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1631. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1632. }
  1633. compositeProfile->ChargingProfileId = 0;
  1634. compositeProfile->StackLevel = 99 ;
  1635. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1636. maxProfile.ChargingProfileId = -1;
  1637. defaultTxProfile.ChargingProfileId = -1;
  1638. txProfile.ChargingProfileId = -1;
  1639. maxProfile.ChargingSchedule.Duration = -1;
  1640. defaultTxProfile.ChargingSchedule.Duration = -1;
  1641. txProfile.ChargingSchedule.Duration = -1;
  1642. system("rm -f /tmp/*.json");
  1643. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1644. /*
  1645. * Search valid charging profile
  1646. */
  1647. //DEBUG_INFO("====================================\n");
  1648. // Search tx profile
  1649. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1650. if((access(profileFileName, F_OK))!=-1)
  1651. {
  1652. fp = fopen(profileFileName, "r");
  1653. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1654. {
  1655. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1656. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1657. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1658. }
  1659. txProfile.ChargingProfileId = -1;
  1660. txProfile.StackLevel = -1;
  1661. while(getline(&line, &len, fp) != -1)
  1662. {
  1663. json_object *obj = NULL;
  1664. obj = json_tokener_parse(line);
  1665. if(is_error(obj))
  1666. {
  1667. DEBUG_ERROR("Parse txProfile from file error.\n");
  1668. }
  1669. else
  1670. {
  1671. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1672. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1673. )
  1674. {
  1675. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1676. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1677. )
  1678. {
  1679. struct tm tmFrom, tmTo;
  1680. struct timeb tbFrom, tbTo;
  1681. 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) &&
  1682. (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))
  1683. {
  1684. tmFrom.tm_year -= 1900;
  1685. tmFrom.tm_mon -= 1;
  1686. tbFrom.time = mktime(&tmFrom);
  1687. tmTo.tm_year -= 1900;
  1688. tmTo.tm_mon -= 1;
  1689. tbTo.time = mktime(&tmTo);
  1690. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1691. {
  1692. if(txProfile.ChargingProfileId == -1)
  1693. DEBUG_INFO("TxProfile found.\n");
  1694. else
  1695. DEBUG_INFO("TxProfile updated.\n");
  1696. // Required item
  1697. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1698. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1699. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1700. if(isUnitA)
  1701. {
  1702. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1703. 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++)
  1704. {
  1705. 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"));
  1706. 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?
  1707. 3:
  1708. 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")));
  1709. 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")));
  1710. }
  1711. }
  1712. else
  1713. {
  1714. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1715. 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++)
  1716. {
  1717. 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"));
  1718. 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?
  1719. 3:
  1720. 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")));
  1721. 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));
  1722. }
  1723. }
  1724. // Optional item
  1725. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1726. {
  1727. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1728. }
  1729. else
  1730. {
  1731. sprintf((char*)txProfile.ValidFrom, " ");
  1732. }
  1733. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1734. {
  1735. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1736. }
  1737. else
  1738. {
  1739. sprintf((char*)txProfile.ValidTo, " ");
  1740. }
  1741. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1742. {
  1743. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1744. }
  1745. else
  1746. {
  1747. sprintf((char*)txProfile.RecurrencyKind, " ");
  1748. }
  1749. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1750. {
  1751. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1752. }
  1753. else
  1754. {
  1755. txProfile.TransactionId = -1;
  1756. }
  1757. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1758. {
  1759. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1760. }
  1761. else
  1762. {
  1763. txProfile.ChargingSchedule.Duration = 86400;
  1764. }
  1765. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1766. {
  1767. 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")));
  1768. }
  1769. else
  1770. {
  1771. 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));
  1772. }
  1773. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1774. {
  1775. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1776. }
  1777. else
  1778. {
  1779. txProfile.ChargingSchedule.MinChargingRate = -1;
  1780. }
  1781. }
  1782. }
  1783. }
  1784. else
  1785. {
  1786. if(txProfile.ChargingProfileId == -1)
  1787. DEBUG_INFO("TxProfile found.\n");
  1788. else
  1789. DEBUG_INFO("TxProfile updated.\n");
  1790. // Required item
  1791. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1792. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1793. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1794. if(isUnitA)
  1795. {
  1796. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1797. 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++)
  1798. {
  1799. 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"));
  1800. 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?
  1801. 3:
  1802. 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")));
  1803. 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")));
  1804. }
  1805. }
  1806. else
  1807. {
  1808. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1809. 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++)
  1810. {
  1811. 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"));
  1812. 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?
  1813. 3:
  1814. 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")));
  1815. 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));
  1816. }
  1817. }
  1818. // Optional item
  1819. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1820. {
  1821. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1822. }
  1823. else
  1824. {
  1825. sprintf((char*)txProfile.ValidFrom, " ");
  1826. }
  1827. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1828. {
  1829. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1830. }
  1831. else
  1832. {
  1833. sprintf((char*)txProfile.ValidTo, " ");
  1834. }
  1835. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1836. {
  1837. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1838. }
  1839. else
  1840. {
  1841. sprintf((char*)txProfile.RecurrencyKind, " ");
  1842. }
  1843. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1844. {
  1845. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1846. }
  1847. else
  1848. {
  1849. txProfile.TransactionId = -1;
  1850. }
  1851. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1852. {
  1853. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1854. }
  1855. else
  1856. {
  1857. txProfile.ChargingSchedule.Duration = 86400;
  1858. }
  1859. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1860. {
  1861. 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")));
  1862. }
  1863. else
  1864. {
  1865. 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));
  1866. }
  1867. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1868. {
  1869. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1870. }
  1871. else
  1872. {
  1873. txProfile.ChargingSchedule.MinChargingRate = -1;
  1874. }
  1875. }
  1876. }
  1877. }
  1878. json_object_put(obj);
  1879. }
  1880. fclose(fp);
  1881. /*
  1882. if(txProfile.ChargingProfileId != -1)
  1883. {
  1884. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1885. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1886. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1887. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1888. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1889. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1890. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1891. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1892. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1893. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1894. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1895. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1896. {
  1897. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1898. {
  1899. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1900. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1901. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1902. }
  1903. }
  1904. }
  1905. else
  1906. DEBUG_INFO("TxProfile not found.\n");*/
  1907. }
  1908. // Search default tx profile
  1909. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1910. if((access(profileFileName, F_OK))==-1)
  1911. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1912. if((access(profileFileName, F_OK))!=-1)
  1913. {
  1914. fp = fopen(profileFileName, "r");
  1915. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1916. {
  1917. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1918. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1919. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1920. }
  1921. defaultTxProfile.ChargingProfileId = -1;
  1922. defaultTxProfile.StackLevel = -1;
  1923. while(getline(&line, &len, fp) != -1)
  1924. {
  1925. json_object *obj = NULL;
  1926. obj = json_tokener_parse(line);
  1927. if(is_error(obj))
  1928. {
  1929. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1930. }
  1931. else
  1932. {
  1933. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1934. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1935. )
  1936. {
  1937. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1938. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1939. )
  1940. {
  1941. struct tm tmFrom, tmTo;
  1942. struct timeb tbFrom, tbTo;
  1943. 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) &&
  1944. (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))
  1945. {
  1946. tmFrom.tm_year -= 1900;
  1947. tmFrom.tm_mon -= 1;
  1948. tbFrom.time = mktime(&tmFrom);
  1949. tmTo.tm_year -= 1900;
  1950. tmTo.tm_mon -= 1;
  1951. tbTo.time = mktime(&tmTo);
  1952. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1953. {
  1954. if(defaultTxProfile.ChargingProfileId == -1)
  1955. DEBUG_INFO("TxDefaultProfile found.\n");
  1956. else
  1957. DEBUG_INFO("TxDefaultProfile updated.\n");
  1958. // Required item
  1959. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1960. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1961. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1962. if(isUnitA)
  1963. {
  1964. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1965. 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++)
  1966. {
  1967. 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"));
  1968. 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?
  1969. 3:
  1970. 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")));
  1971. 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")));
  1972. }
  1973. }
  1974. else
  1975. {
  1976. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1977. 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++)
  1978. {
  1979. 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"));
  1980. 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?
  1981. 3:
  1982. 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")));
  1983. 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));
  1984. }
  1985. }
  1986. // Optional item
  1987. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1988. {
  1989. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1990. }
  1991. else
  1992. {
  1993. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1994. }
  1995. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1996. {
  1997. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1998. }
  1999. else
  2000. {
  2001. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2002. }
  2003. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2004. {
  2005. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2006. }
  2007. else
  2008. {
  2009. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2010. }
  2011. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2012. {
  2013. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2014. }
  2015. else
  2016. {
  2017. defaultTxProfile.TransactionId = -1;
  2018. }
  2019. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2020. {
  2021. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2022. }
  2023. else
  2024. {
  2025. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2026. }
  2027. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2028. {
  2029. 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")));
  2030. }
  2031. else
  2032. {
  2033. 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));
  2034. }
  2035. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2036. {
  2037. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2038. }
  2039. else
  2040. {
  2041. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2042. }
  2043. }
  2044. }
  2045. }
  2046. else
  2047. {
  2048. if(defaultTxProfile.ChargingProfileId == -1)
  2049. DEBUG_INFO("TxDefaultProfile found.\n");
  2050. else
  2051. DEBUG_INFO("TxDefaultProfile updated.\n");
  2052. // Required item
  2053. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2054. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2055. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2056. if(isUnitA)
  2057. {
  2058. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2059. 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++)
  2060. {
  2061. 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"));
  2062. 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?
  2063. 3:
  2064. 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")));
  2065. 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")));
  2066. }
  2067. }
  2068. else
  2069. {
  2070. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2071. 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++)
  2072. {
  2073. 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"));
  2074. 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?
  2075. 3:
  2076. 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")));
  2077. 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));
  2078. }
  2079. }
  2080. // Optional item
  2081. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2082. {
  2083. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2084. }
  2085. else
  2086. {
  2087. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2088. }
  2089. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2090. {
  2091. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2092. }
  2093. else
  2094. {
  2095. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2096. }
  2097. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2098. {
  2099. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2100. }
  2101. else
  2102. {
  2103. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2104. }
  2105. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2106. {
  2107. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2108. }
  2109. else
  2110. {
  2111. defaultTxProfile.TransactionId = -1;
  2112. }
  2113. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2114. {
  2115. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2116. }
  2117. else
  2118. {
  2119. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2120. }
  2121. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2122. {
  2123. 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")));
  2124. }
  2125. else
  2126. {
  2127. 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));
  2128. }
  2129. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2130. {
  2131. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2132. }
  2133. else
  2134. {
  2135. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2136. }
  2137. }
  2138. }
  2139. }
  2140. json_object_put(obj);
  2141. }
  2142. fclose(fp);
  2143. /*
  2144. if(defaultTxProfile.ChargingProfileId != -1)
  2145. {
  2146. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2147. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2148. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2149. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2150. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2151. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2152. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2153. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2154. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2155. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2156. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2157. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2158. {
  2159. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2160. {
  2161. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2162. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2163. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2164. }
  2165. }
  2166. }
  2167. else
  2168. DEBUG_INFO("TxDefaultProfile not found.\n");
  2169. DEBUG_INFO("------------------------------------\n");*/
  2170. }
  2171. // Search max profile
  2172. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2173. if((access(profileFileName, F_OK))!=-1)
  2174. {
  2175. fp = fopen(profileFileName, "r");
  2176. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2177. {
  2178. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2179. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2180. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2181. }
  2182. maxProfile.ChargingProfileId = -1;
  2183. maxProfile.StackLevel = -1;
  2184. while(getline(&line, &len, fp) != -1)
  2185. {
  2186. json_object *obj = NULL;
  2187. obj = json_tokener_parse(line);
  2188. if(is_error(obj))
  2189. {
  2190. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2191. }
  2192. else
  2193. {
  2194. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  2195. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2196. )
  2197. {
  2198. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2199. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2200. )
  2201. {
  2202. struct tm tmFrom, tmTo;
  2203. struct timeb tbFrom, tbTo;
  2204. 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) &&
  2205. (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))
  2206. {
  2207. tmFrom.tm_year -= 1900;
  2208. tmFrom.tm_mon -= 1;
  2209. tbFrom.time = mktime(&tmFrom);
  2210. tmTo.tm_year -= 1900;
  2211. tmTo.tm_mon -= 1;
  2212. tbTo.time = mktime(&tmTo);
  2213. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2214. {
  2215. if(maxProfile.ChargingProfileId == -1)
  2216. DEBUG_INFO("MaxProfile found.\n");
  2217. else
  2218. DEBUG_INFO("MaxProfile updated.\n");
  2219. // Required item
  2220. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2221. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2222. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2223. if(isUnitA)
  2224. {
  2225. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2226. 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++)
  2227. {
  2228. 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"));
  2229. 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?
  2230. 3:
  2231. 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")));
  2232. 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")));
  2233. }
  2234. }
  2235. else
  2236. {
  2237. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2238. 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++)
  2239. {
  2240. 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"));
  2241. 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?
  2242. 3:
  2243. 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")));
  2244. 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));
  2245. }
  2246. }
  2247. // Optional item
  2248. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2249. {
  2250. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2251. }
  2252. else
  2253. {
  2254. sprintf((char*)maxProfile.ValidFrom, " ");
  2255. }
  2256. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2257. {
  2258. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2259. }
  2260. else
  2261. {
  2262. sprintf((char*)maxProfile.ValidTo, " ");
  2263. }
  2264. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2265. {
  2266. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2267. }
  2268. else
  2269. {
  2270. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2271. }
  2272. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2273. {
  2274. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2275. }
  2276. else
  2277. {
  2278. maxProfile.TransactionId = -1;
  2279. }
  2280. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2281. {
  2282. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2283. }
  2284. else
  2285. {
  2286. maxProfile.ChargingSchedule.Duration = 86400;
  2287. }
  2288. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2289. {
  2290. 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")));
  2291. }
  2292. else
  2293. {
  2294. 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));
  2295. }
  2296. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2297. {
  2298. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2299. }
  2300. else
  2301. {
  2302. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2303. }
  2304. }
  2305. }
  2306. }
  2307. else
  2308. {
  2309. if(maxProfile.ChargingProfileId == -1)
  2310. DEBUG_INFO("MaxProfile found.\n");
  2311. else
  2312. DEBUG_INFO("MaxProfile updated.\n");
  2313. // Required item
  2314. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2315. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2316. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2317. if(isUnitA)
  2318. {
  2319. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2320. 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++)
  2321. {
  2322. 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"));
  2323. 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?
  2324. 3:
  2325. 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")));
  2326. 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")));
  2327. }
  2328. }
  2329. else
  2330. {
  2331. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2332. 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++)
  2333. {
  2334. 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"));
  2335. 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?
  2336. 3:
  2337. 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")));
  2338. 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));
  2339. }
  2340. }
  2341. // Optional item
  2342. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2343. {
  2344. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2345. }
  2346. else
  2347. {
  2348. sprintf((char*)maxProfile.ValidFrom, " ");
  2349. }
  2350. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2351. {
  2352. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2353. }
  2354. else
  2355. {
  2356. sprintf((char*)maxProfile.ValidTo, " ");
  2357. }
  2358. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2359. {
  2360. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2361. }
  2362. else
  2363. {
  2364. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2365. }
  2366. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2367. {
  2368. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2369. }
  2370. else
  2371. {
  2372. maxProfile.TransactionId = -1;
  2373. }
  2374. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2375. {
  2376. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2377. }
  2378. else
  2379. {
  2380. maxProfile.ChargingSchedule.Duration = 86400;
  2381. }
  2382. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2383. {
  2384. 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")));
  2385. }
  2386. else
  2387. {
  2388. 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));
  2389. }
  2390. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2391. {
  2392. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2393. }
  2394. else
  2395. {
  2396. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2397. }
  2398. }
  2399. }
  2400. }
  2401. json_object_put(obj);
  2402. }
  2403. fclose(fp);
  2404. /*
  2405. if(maxProfile.ChargingProfileId !=-1)
  2406. {
  2407. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2408. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2409. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2410. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2411. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2412. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2413. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2414. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2415. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2416. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2417. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2418. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2419. {
  2420. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2421. {
  2422. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2423. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2424. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2425. }
  2426. }
  2427. }
  2428. else
  2429. DEBUG_INFO("MaxProfile not found.\n");
  2430. DEBUG_INFO("------------------------------------\n");*/
  2431. }
  2432. /*
  2433. * Align found profile start schedule & periods
  2434. */
  2435. //DEBUG_INFO("====================================\n");
  2436. /*
  2437. // For local test usage, force modify found profile start schedule info
  2438. 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);
  2439. 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);
  2440. 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);
  2441. */
  2442. if(txProfile.ChargingProfileId != -1)
  2443. {
  2444. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2445. {
  2446. if(txProfile.ChargingSchedule.Duration != -1)
  2447. {
  2448. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2449. 0:
  2450. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2451. }
  2452. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2453. {
  2454. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2455. {
  2456. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2457. 0:
  2458. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2459. if(idxPeriod > 0)
  2460. {
  2461. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2462. {
  2463. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2464. }
  2465. }
  2466. }
  2467. }
  2468. }
  2469. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2470. {
  2471. if(txProfile.ChargingSchedule.Duration != -1)
  2472. {
  2473. 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?
  2474. 0:
  2475. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2476. }
  2477. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2478. {
  2479. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2480. {
  2481. 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?
  2482. 0:
  2483. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2484. if(idxPeriod > 0)
  2485. {
  2486. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2487. {
  2488. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2489. }
  2490. }
  2491. }
  2492. }
  2493. }
  2494. else
  2495. {
  2496. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2497. {
  2498. if(txProfile.ChargingSchedule.Duration != -1)
  2499. {
  2500. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2501. 0:
  2502. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2503. }
  2504. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2505. {
  2506. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2507. {
  2508. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2509. 0:
  2510. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2511. if(idxPeriod > 0)
  2512. {
  2513. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2514. {
  2515. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2516. }
  2517. }
  2518. }
  2519. }
  2520. }
  2521. else
  2522. {
  2523. if(txProfile.ChargingSchedule.Duration != -1)
  2524. {
  2525. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2526. 0:
  2527. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2528. }
  2529. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2530. {
  2531. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2532. {
  2533. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2534. 0:
  2535. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2536. if(idxPeriod > 0)
  2537. {
  2538. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2539. {
  2540. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2541. }
  2542. }
  2543. }
  2544. }
  2545. }
  2546. }
  2547. /*
  2548. DEBUG_INFO("txProfile after align.\n");
  2549. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2550. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2551. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2552. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2553. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2554. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2555. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  2556. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2557. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2558. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2559. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2560. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2561. {
  2562. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2563. {
  2564. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2565. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2566. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2567. }
  2568. }*/
  2569. }
  2570. if(defaultTxProfile.ChargingProfileId != -1)
  2571. {
  2572. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2573. {
  2574. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2575. {
  2576. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2577. 0:
  2578. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2579. }
  2580. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2581. {
  2582. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2583. {
  2584. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2585. 0:
  2586. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2587. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2588. {
  2589. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2590. }
  2591. if(idxPeriod > 0)
  2592. {
  2593. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2594. {
  2595. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2596. }
  2597. }
  2598. }
  2599. }
  2600. }
  2601. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2602. {
  2603. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2604. {
  2605. 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?
  2606. 0:
  2607. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2608. }
  2609. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2610. {
  2611. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2612. {
  2613. 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?
  2614. 0:
  2615. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2616. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2617. {
  2618. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2619. }
  2620. if(idxPeriod > 0)
  2621. {
  2622. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2623. {
  2624. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2625. }
  2626. }
  2627. }
  2628. }
  2629. }
  2630. else
  2631. {
  2632. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2633. {
  2634. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2635. {
  2636. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2637. 0:
  2638. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2639. }
  2640. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2641. {
  2642. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2643. {
  2644. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2645. 0:
  2646. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2647. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2648. {
  2649. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2650. }
  2651. if(idxPeriod > 0)
  2652. {
  2653. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2654. {
  2655. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2656. }
  2657. }
  2658. }
  2659. }
  2660. }
  2661. else
  2662. {
  2663. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2664. {
  2665. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2666. 0:
  2667. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2668. }
  2669. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2670. {
  2671. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2672. {
  2673. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2674. 0:
  2675. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2676. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2677. {
  2678. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2679. }
  2680. if(idxPeriod > 0)
  2681. {
  2682. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2683. {
  2684. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2685. }
  2686. }
  2687. }
  2688. }
  2689. }
  2690. }
  2691. /*
  2692. DEBUG_INFO("defaultTxProfile after align.\n");
  2693. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2694. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2695. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2696. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2697. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2698. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2699. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2700. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2701. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2702. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2703. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2704. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2705. {
  2706. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2707. {
  2708. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2709. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2710. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2711. }
  2712. }
  2713. DEBUG_INFO("------------------------------------\n");*/
  2714. }
  2715. if(maxProfile.ChargingProfileId != -1)
  2716. {
  2717. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2718. {
  2719. if(maxProfile.ChargingSchedule.Duration != -1)
  2720. {
  2721. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2722. 0:
  2723. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2724. }
  2725. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2726. {
  2727. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2728. {
  2729. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2730. 0:
  2731. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2732. if(idxPeriod > 0)
  2733. {
  2734. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2735. {
  2736. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2737. }
  2738. }
  2739. }
  2740. }
  2741. }
  2742. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2743. {
  2744. if(maxProfile.ChargingSchedule.Duration != -1)
  2745. {
  2746. 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?
  2747. 0:
  2748. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2749. }
  2750. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2751. {
  2752. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2753. {
  2754. 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?
  2755. 0:
  2756. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2757. if(idxPeriod > 0)
  2758. {
  2759. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2760. {
  2761. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2762. }
  2763. }
  2764. }
  2765. }
  2766. }
  2767. else
  2768. {
  2769. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2770. {
  2771. if(maxProfile.ChargingSchedule.Duration != -1)
  2772. {
  2773. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2774. 0:
  2775. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2776. }
  2777. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2778. {
  2779. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2780. {
  2781. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2782. 0:
  2783. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2784. if(idxPeriod > 0)
  2785. {
  2786. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2787. {
  2788. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2789. }
  2790. }
  2791. }
  2792. }
  2793. }
  2794. else
  2795. {
  2796. if(maxProfile.ChargingSchedule.Duration != -1)
  2797. {
  2798. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2799. 0:
  2800. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2801. }
  2802. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2803. {
  2804. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2805. {
  2806. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2807. 0:
  2808. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2809. if(idxPeriod > 0)
  2810. {
  2811. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2812. {
  2813. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2814. }
  2815. }
  2816. }
  2817. }
  2818. }
  2819. }
  2820. /*
  2821. DEBUG_INFO("MaxProfile after align.\n");
  2822. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2823. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2824. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2825. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2826. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2827. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2828. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2829. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2830. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2831. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2832. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2833. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2834. {
  2835. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2836. {
  2837. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2838. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2839. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2840. }
  2841. }
  2842. DEBUG_INFO("------------------------------------\n");*/
  2843. }
  2844. /*
  2845. * Merge to conposite schedule
  2846. */
  2847. //DEBUG_INFO("====================================\n");
  2848. // Find each profile period quantity
  2849. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2850. {
  2851. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2852. limitMax = idx+1;
  2853. }
  2854. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2855. {
  2856. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2857. limitDef = idx+1;
  2858. }
  2859. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2860. {
  2861. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2862. limitTx = idx+1;
  2863. }
  2864. // TxProfile found, composite schedule based on it
  2865. if(txProfile.ChargingProfileId != -1)
  2866. {
  2867. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2868. {
  2869. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2870. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2871. (txProfile.ChargingSchedule.Duration > 0))
  2872. {
  2873. if(maxProfile.ChargingProfileId != -1)
  2874. {
  2875. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2876. {
  2877. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2878. {
  2879. if((maxProfile.ChargingSchedule.Duration > 0))
  2880. {
  2881. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2882. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2883. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2884. }
  2885. else
  2886. {
  2887. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2888. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2889. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2890. }
  2891. }
  2892. if(idxMaxPeriod == (limitMax-1))
  2893. {
  2894. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2895. {
  2896. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2897. {
  2898. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2899. compositePeriodIdx++;
  2900. }
  2901. else
  2902. {
  2903. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2904. }
  2905. }
  2906. }
  2907. }
  2908. }
  2909. else
  2910. {
  2911. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2912. {
  2913. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2914. compositePeriodIdx++;
  2915. }
  2916. else
  2917. {
  2918. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2919. }
  2920. }
  2921. }
  2922. if(idxTxPeriod == (limitTx-1))
  2923. {
  2924. if(defaultTxProfile.ChargingProfileId != -1)
  2925. {
  2926. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2927. {
  2928. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2929. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2930. (defaultTxProfile.ChargingSchedule.Duration>0))
  2931. {
  2932. if(maxProfile.ChargingProfileId != -1)
  2933. {
  2934. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2935. {
  2936. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2937. {
  2938. if((maxProfile.ChargingSchedule.Duration > 0))
  2939. {
  2940. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2941. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2942. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2943. }
  2944. else
  2945. {
  2946. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2947. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2948. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2949. }
  2950. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2951. {
  2952. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2953. {
  2954. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2955. compositePeriodIdx++;
  2956. }
  2957. else
  2958. {
  2959. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2960. }
  2961. }
  2962. // Delete duplicate period
  2963. if(compositePeriodIdx > 1)
  2964. {
  2965. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2966. {
  2967. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2968. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2969. compositePeriodIdx -= 1;
  2970. }
  2971. }
  2972. }
  2973. else
  2974. break;
  2975. }
  2976. }
  2977. else
  2978. {
  2979. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2980. {
  2981. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2982. compositePeriodIdx++;
  2983. }
  2984. else
  2985. {
  2986. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2987. }
  2988. }
  2989. }
  2990. }
  2991. }
  2992. }
  2993. }
  2994. }
  2995. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2996. else if(defaultTxProfile.ChargingProfileId != -1)
  2997. {
  2998. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2999. {
  3000. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3001. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3002. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3003. {
  3004. if(maxProfile.ChargingProfileId != -1)
  3005. {
  3006. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3007. {
  3008. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3009. {
  3010. if((maxProfile.ChargingSchedule.Duration > 0))
  3011. {
  3012. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3013. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3014. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3015. }
  3016. else
  3017. {
  3018. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3019. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3020. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3021. }
  3022. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3023. {
  3024. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3025. {
  3026. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3027. compositePeriodIdx++;
  3028. }
  3029. else
  3030. {
  3031. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3032. }
  3033. }
  3034. // Delete duplicate period
  3035. if(compositePeriodIdx > 1)
  3036. {
  3037. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3038. {
  3039. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3040. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3041. compositePeriodIdx -= 1;
  3042. }
  3043. }
  3044. }
  3045. else
  3046. break;
  3047. }
  3048. }
  3049. else
  3050. {
  3051. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3052. {
  3053. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3054. compositePeriodIdx++;
  3055. }
  3056. else
  3057. {
  3058. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3059. }
  3060. }
  3061. }
  3062. }
  3063. }
  3064. // Fill other period by MaxProfile
  3065. if(maxProfile.ChargingProfileId != -1)
  3066. {
  3067. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3068. {
  3069. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3070. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3071. (maxProfile.ChargingSchedule.Duration > 0))
  3072. {
  3073. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  3074. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  3075. {
  3076. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  3077. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  3078. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3079. }
  3080. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  3081. {
  3082. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  3083. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3084. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3085. }
  3086. if(tmpPeriod.Limit != -1)
  3087. {
  3088. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3089. {
  3090. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3091. {
  3092. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3093. compositePeriodIdx++;
  3094. }
  3095. else
  3096. {
  3097. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3098. }
  3099. }
  3100. // Delete duplicate period
  3101. if(compositePeriodIdx > 1)
  3102. {
  3103. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3104. {
  3105. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3106. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3107. compositePeriodIdx -= 1;
  3108. }
  3109. }
  3110. }
  3111. }
  3112. }
  3113. }
  3114. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3115. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3116. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3117. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3118. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3119. {
  3120. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3121. {
  3122. compositeProfile->ChargingProfileId = 1;
  3123. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3124. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3125. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3126. }
  3127. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3128. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3129. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3130. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3131. }
  3132. if(line)
  3133. free(line);
  3134. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3135. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3136. }
  3137. //==========================================
  3138. // Init all share memory
  3139. //==========================================
  3140. int InitShareMemory()
  3141. {
  3142. int result = PASS;
  3143. int MeterSMId;
  3144. //creat ShmSysConfigAndInfo
  3145. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3146. {
  3147. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3148. result = FAIL;
  3149. }
  3150. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3151. {
  3152. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3153. result = FAIL;
  3154. }
  3155. else
  3156. {}
  3157. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3158. {
  3159. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3160. result = FAIL;
  3161. }
  3162. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3163. {
  3164. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3165. result = FAIL;
  3166. }
  3167. else
  3168. {}
  3169. //creat ShmPsuData
  3170. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3171. {
  3172. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3173. result = FAIL;
  3174. }
  3175. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3176. {
  3177. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3178. result = FAIL;
  3179. }
  3180. else
  3181. {}
  3182. //creat ShmOCPP16Data
  3183. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3184. {
  3185. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3186. result = FAIL;
  3187. }
  3188. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3189. {
  3190. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3191. result = FAIL;
  3192. }
  3193. else
  3194. {}
  3195. /****************************** For Initial Settings************************************************/
  3196. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3197. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3198. // allocate Configuration memory address
  3199. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3200. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3201. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3202. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3203. //offline MeterValue Interval
  3204. TempMeterValueInterval = 0;
  3205. return result;
  3206. }
  3207. int ProcessShareMemory()
  3208. {
  3209. if(InitShareMemory() == FAIL)
  3210. {
  3211. DEBUG_ERROR("InitShareMemory NG\n");
  3212. if(ShmStatusCodeData!=NULL)
  3213. {
  3214. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3215. }
  3216. sleep(5);
  3217. return FAIL;
  3218. }
  3219. return PASS;
  3220. }
  3221. void CheckSystemValue(void)
  3222. {
  3223. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3224. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3225. char filenmae[100]={0};
  3226. char str[100]={0};
  3227. int tempIndex = 0;
  3228. //===============================
  3229. // send Heartbeat
  3230. //===============================
  3231. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3232. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  3233. {
  3234. clientTime.Heartbeat=time((time_t*)NULL);
  3235. if(server_sign == TRUE)
  3236. {
  3237. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3238. }
  3239. else
  3240. {
  3241. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  3242. }
  3243. }
  3244. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3245. {
  3246. //parameter for test
  3247. sendHeartbeatRequest(0);
  3248. //==============================================
  3249. // Reset Waiting Time
  3250. //==============================================
  3251. HeartBeatWithNOResponse += 1;
  3252. }
  3253. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3254. {
  3255. //==========================================
  3256. // csu trigger DataTransferReq
  3257. //==========================================
  3258. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  3259. {
  3260. sendDataTransferRequest(gun_index);
  3261. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  3262. }
  3263. //===============================
  3264. // CSU Trigger Authorize Request
  3265. //===============================
  3266. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3267. {
  3268. sendAuthorizeRequest(0);
  3269. authorizeRetryTimes = authorizeRetryTimes + 1;
  3270. if(authorizeRetryTimes < 3)
  3271. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3272. }
  3273. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3274. {
  3275. authorizeRetryTimes = 0;
  3276. SetOcppConnStatus(FALSE);
  3277. server_sign = FALSE;
  3278. }
  3279. 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))
  3280. {
  3281. sendAuthorizeRequest(0);
  3282. }
  3283. //==============================================
  3284. // Charger start transaction
  3285. //==============================================
  3286. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3287. {
  3288. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3289. sendStartTransactionRequest(gun_index);
  3290. clientTime.StartTransaction = time((time_t*)NULL);
  3291. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3292. storeTempStopTransaction(gun_index);
  3293. }
  3294. //==============================================
  3295. // Charger stop transaction
  3296. //==============================================
  3297. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3298. {
  3299. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3300. sendStopTransactionRequest(gun_index);
  3301. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  3302. clientTime.StopTransaction = time((time_t*)NULL);
  3303. }
  3304. //==============================================
  3305. // Charger status report
  3306. //==============================================
  3307. //--- Check Mode Change ---//
  3308. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3309. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3310. {
  3311. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3312. {
  3313. tempIndex = ((gun_index==2) ? 1: 0);
  3314. }
  3315. else
  3316. {
  3317. tempIndex = gun_index;
  3318. }
  3319. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3320. {
  3321. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3322. {
  3323. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3324. {
  3325. // Sent unplug message for California pricing logic
  3326. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3327. {
  3328. uint8_t ts[20];
  3329. getNowDatetime(ts);
  3330. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3331. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3332. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3333. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3334. }
  3335. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3336. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3337. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3338. }
  3339. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3340. {
  3341. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3342. if((access(filenmae,F_OK))!=-1)
  3343. {
  3344. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3345. sprintf(str,"rm -f %s",filenmae);
  3346. system(str);
  3347. }
  3348. }
  3349. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3350. #if 1 // for TempStopTransaction
  3351. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3352. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3353. {
  3354. checkTempStopTransaction(gun_index);
  3355. }
  3356. #endif
  3357. }
  3358. }
  3359. }
  3360. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3361. {
  3362. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3363. {
  3364. tempIndex = ((gun_index==2) ? 1: 0);
  3365. }
  3366. else
  3367. {
  3368. tempIndex = gun_index;
  3369. }
  3370. for (int index = 0; index < CCS_QUANTITY; index++)
  3371. {
  3372. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3373. {
  3374. if((SystemInitial > 0) || (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]*/ )
  3375. {
  3376. // Sent unplug message for California pricing logic
  3377. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3378. {
  3379. uint8_t ts[20];
  3380. getNowDatetime(ts);
  3381. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3382. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3383. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3384. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3385. }
  3386. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3387. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3388. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3389. }
  3390. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3391. {
  3392. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3393. if((access(filenmae,F_OK))!=-1)
  3394. {
  3395. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3396. sprintf(str,"rm -f %s",filenmae);
  3397. system(str);
  3398. }
  3399. }
  3400. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3401. #if 1 // for TempStopTransaction
  3402. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3403. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3404. {
  3405. checkTempStopTransaction(gun_index);
  3406. }
  3407. #endif
  3408. }
  3409. }
  3410. }
  3411. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3412. {
  3413. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3414. {
  3415. tempIndex = ((gun_index==2) ? 1: 0);
  3416. }
  3417. else
  3418. {
  3419. tempIndex = gun_index;
  3420. }
  3421. for (int index = 0; index < GB_QUANTITY; index++)
  3422. {
  3423. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3424. {
  3425. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3426. {
  3427. // Sent unplug message for California pricing logic
  3428. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3429. {
  3430. uint8_t ts[20];
  3431. getNowDatetime(ts);
  3432. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3433. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3434. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3435. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3436. }
  3437. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3438. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3439. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3440. }
  3441. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3442. {
  3443. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3444. if((access(filenmae,F_OK))!=-1)
  3445. {
  3446. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3447. sprintf(str,"rm -f %s",filenmae);
  3448. system(str);
  3449. }
  3450. }
  3451. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3452. #if 1 // for TempStopTransaction
  3453. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3454. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3455. {
  3456. checkTempStopTransaction(gun_index);
  3457. }
  3458. #endif
  3459. }
  3460. }
  3461. }
  3462. else if(gunType[gun_index] == GUN_TYPE_DO)
  3463. {
  3464. tempIndex = gun_index;
  3465. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3466. {
  3467. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3468. {
  3469. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3470. {
  3471. // Sent unplug message for California pricing logic
  3472. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3473. {
  3474. uint8_t ts[20];
  3475. getNowDatetime(ts);
  3476. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3477. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3478. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3479. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3480. }
  3481. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3482. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3483. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3484. }
  3485. 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_PREPARING))) // complete
  3486. {
  3487. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3488. if((access(filenmae,F_OK))!=-1)
  3489. {
  3490. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3491. sprintf(str,"rm -f %s",filenmae);
  3492. system(str);
  3493. }
  3494. }
  3495. 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);
  3496. #if 1 // for TempStopTransaction
  3497. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3498. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3499. {
  3500. checkTempStopTransaction(gun_index);
  3501. }
  3502. #endif
  3503. }
  3504. }
  3505. }
  3506. else
  3507. {
  3508. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3509. {
  3510. tempIndex = 2;
  3511. }
  3512. else
  3513. {
  3514. tempIndex = gun_index;
  3515. }
  3516. for (int index = 0; index < AC_QUANTITY; index++)
  3517. {
  3518. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3519. {
  3520. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3521. {
  3522. // Sent unplug message for California pricing logic
  3523. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  3524. {
  3525. uint8_t ts[20];
  3526. getNowDatetime(ts);
  3527. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3528. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3529. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3530. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3531. }
  3532. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3533. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3534. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3535. }
  3536. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3537. {
  3538. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3539. if((access(filenmae,F_OK))!=-1)
  3540. {
  3541. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3542. sprintf(str,"rm -f %s",filenmae);
  3543. system(str);
  3544. }
  3545. }
  3546. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3547. #if 1 // for TempStopTransaction
  3548. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3549. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3550. {
  3551. checkTempStopTransaction(gun_index);
  3552. }
  3553. #endif
  3554. }
  3555. }// END
  3556. }
  3557. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  3558. (
  3559. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3560. )
  3561. )
  3562. {
  3563. if(SystemInitial > 0)
  3564. SystemInitial -= 1;
  3565. sendStatusNotificationRequest(gun_index);
  3566. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  3567. }
  3568. //==============================================
  3569. // CSU Trigger Smart Charging Profilw
  3570. //==============================================
  3571. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3572. {
  3573. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  3574. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3575. }
  3576. //==============================================
  3577. // Meter report
  3578. //==============================================
  3579. // Trigger MeterValue
  3580. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3581. {
  3582. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3583. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3584. }
  3585. // ClockAlign MeterValue
  3586. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3587. {
  3588. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3589. {
  3590. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3591. {
  3592. tempIndex = ((gun_index==2) ? 1: 0);
  3593. }
  3594. else
  3595. {
  3596. tempIndex = gun_index;
  3597. }
  3598. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3599. {
  3600. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3601. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3602. {
  3603. reqClockAlignMeter[gun_index] = 1;
  3604. }
  3605. }// End for CHAdeMO
  3606. }
  3607. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3608. {
  3609. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3610. {
  3611. tempIndex = ((gun_index==2) ? 1: 0);
  3612. }
  3613. else
  3614. {
  3615. tempIndex = gun_index;
  3616. }
  3617. for (int index = 0; index < CCS_QUANTITY; index++)
  3618. {
  3619. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3620. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3621. {
  3622. reqClockAlignMeter[gun_index] = 1;
  3623. }
  3624. } // End for CCS
  3625. }
  3626. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3627. {
  3628. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3629. {
  3630. tempIndex = ((gun_index==2) ? 1: 0);
  3631. }
  3632. else
  3633. {
  3634. tempIndex = gun_index;
  3635. }
  3636. for (int index = 0; index < GB_QUANTITY; index++)
  3637. {
  3638. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3639. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3640. {
  3641. reqClockAlignMeter[gun_index] = 1;
  3642. }
  3643. }// End for GB
  3644. }
  3645. else if(gunType[gun_index] == GUN_TYPE_DO)
  3646. {
  3647. tempIndex = gun_index;
  3648. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3649. {
  3650. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3651. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3652. {
  3653. reqClockAlignMeter[gun_index] = 1;
  3654. }
  3655. }
  3656. }
  3657. else
  3658. {
  3659. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3660. {
  3661. tempIndex = 2;
  3662. }
  3663. else
  3664. {
  3665. tempIndex = gun_index;
  3666. }
  3667. for (int index = 0; index < AC_QUANTITY; index++)
  3668. {
  3669. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3670. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3671. {
  3672. reqClockAlignMeter[gun_index] = 1;
  3673. }
  3674. }//End for AC
  3675. }
  3676. if(reqClockAlignMeter[gun_index] == 1)
  3677. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3678. }
  3679. // Sample period MeterValue
  3680. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>10?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):10))))
  3681. {
  3682. //check Transaction active
  3683. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3684. {
  3685. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3686. {
  3687. tempIndex = ((gun_index==2) ? 1: 0);
  3688. }
  3689. else
  3690. {
  3691. tempIndex = gun_index;
  3692. }
  3693. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3694. {
  3695. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3696. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3697. {
  3698. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3699. {
  3700. reqSampleMeter[gun_index] = 1;
  3701. }
  3702. }
  3703. }// End for CHAdeMO
  3704. }
  3705. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3706. {
  3707. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3708. {
  3709. tempIndex = ((gun_index==2) ? 1: 0);
  3710. }
  3711. else
  3712. {
  3713. tempIndex = gun_index;
  3714. }
  3715. for (int index = 0; index < CCS_QUANTITY; index++)
  3716. {
  3717. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3718. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3719. {
  3720. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3721. {
  3722. reqSampleMeter[gun_index] = 1;
  3723. }
  3724. }
  3725. } // End for CCS
  3726. }
  3727. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3728. {
  3729. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3730. {
  3731. tempIndex = ((gun_index==2) ? 1: 0);
  3732. }
  3733. else
  3734. {
  3735. tempIndex = gun_index;
  3736. }
  3737. for (int index = 0; index < GB_QUANTITY; index++)
  3738. {
  3739. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3740. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3741. {
  3742. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3743. {
  3744. reqSampleMeter[gun_index] = 1;
  3745. }
  3746. }
  3747. }// End for GB
  3748. }
  3749. else if(gunType[gun_index] == GUN_TYPE_DO)
  3750. {
  3751. tempIndex = gun_index;
  3752. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3753. {
  3754. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3755. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3756. {
  3757. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3758. {
  3759. reqSampleMeter[gun_index] = 1;
  3760. }
  3761. }
  3762. }
  3763. }
  3764. else
  3765. {
  3766. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3767. {
  3768. tempIndex = 2;
  3769. }
  3770. else
  3771. {
  3772. tempIndex = gun_index;
  3773. }
  3774. for (int index = 0; index < AC_QUANTITY; index++)
  3775. {
  3776. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3777. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3778. {
  3779. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3780. {
  3781. reqSampleMeter[gun_index] = 1;
  3782. }
  3783. }
  3784. }//End for AC
  3785. }
  3786. if(reqSampleMeter[gun_index] == 1)
  3787. {
  3788. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3789. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3790. storeTempStopTransaction(gun_index);
  3791. }
  3792. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3793. }
  3794. //==============================================
  3795. // Check Connector reserved
  3796. //==============================================
  3797. //===============================
  3798. // Check if Reserve is expired
  3799. //===============================
  3800. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3801. {
  3802. double diff_t;
  3803. struct tm tp;
  3804. // current time
  3805. time_t t = time(NULL);
  3806. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3807. tp.tm_isdst = -1;
  3808. time_t utc = mktime(&tp);
  3809. diff_t = difftime(utc, t);
  3810. if(diff_t <= 0)
  3811. {
  3812. DEBUG_INFO("reserve expired.\n");
  3813. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3814. }
  3815. }//END OF Check if Reserve is expired
  3816. //==========================================
  3817. // csu trigger FirmwareStatusNotificationReq
  3818. //==========================================
  3819. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3820. {
  3821. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3822. }
  3823. //==========================================
  3824. // csu trigger DiagnosticsStatusNotificationReq
  3825. //==========================================
  3826. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3827. {
  3828. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3829. }
  3830. //==========================================
  3831. // csu trigger CancelReservationConf
  3832. //==========================================
  3833. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3834. {
  3835. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3836. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3837. }
  3838. //==========================================
  3839. // csu trigger ChangeAvailabilityConf
  3840. //==========================================
  3841. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3842. {
  3843. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3844. }
  3845. //==========================================
  3846. // csu trigger UnlockConnectorConf
  3847. //==========================================
  3848. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3849. {
  3850. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3851. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3852. }
  3853. //==========================================
  3854. // csu trigger ReserveNowConf
  3855. //==========================================
  3856. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3857. {
  3858. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3859. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3860. }
  3861. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3862. {
  3863. sendSignCertificateRequest();
  3864. }
  3865. }
  3866. }
  3867. //==========================================
  3868. // send request routine
  3869. //==========================================
  3870. int sendAuthorizeRequest(int gun_index)
  3871. {
  3872. mtrace();
  3873. int result = FAIL;
  3874. char message[100]={0};
  3875. char guid[37];
  3876. char tempdata[65]={0};
  3877. DEBUG_INFO("sendAuthorizeRequest...\n");
  3878. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3879. //Local Authorize
  3880. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3881. {
  3882. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3883. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3884. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3885. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3886. result = PASS;
  3887. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3888. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3889. authorizeRetryTimes = 0;
  3890. return result;
  3891. }
  3892. 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))||
  3893. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3894. {
  3895. // Query from cache
  3896. DEBUG_INFO("Authorize from cache.\n");
  3897. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3898. // Query from list
  3899. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3900. {
  3901. DEBUG_INFO("Authorize from list.\n");
  3902. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3903. }
  3904. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3905. {
  3906. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3907. {
  3908. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3909. }
  3910. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3911. {
  3912. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  3913. }
  3914. if(!GetOcppConnStatus())
  3915. {
  3916. DEBUG_INFO("off-line Local Authorization Fail.\n");
  3917. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3918. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3919. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3920. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3921. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3922. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3923. authorizeRetryTimes = 0;
  3924. return result;
  3925. }
  3926. }
  3927. else
  3928. {
  3929. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3930. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3931. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3932. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3933. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  3934. else
  3935. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3936. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3937. result = PASS;
  3938. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3939. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3940. authorizeRetryTimes = 0;
  3941. return result;
  3942. }
  3943. }
  3944. //initialize struct Authorize
  3945. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  3946. //get data from shared memory
  3947. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3948. random_uuid(guid);
  3949. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  3950. LWS_Send(message);
  3951. sprintf(tempdata, "Authorize,%d", gun_index);
  3952. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3953. {
  3954. result = PASS;
  3955. DEBUG_INFO("Authorize mapItem pass\n");
  3956. }
  3957. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3958. return result;
  3959. }
  3960. int sendBootNotificationRequest(void)
  3961. {
  3962. mtrace();
  3963. int result = FAIL;
  3964. char message[500]={0}, payload[700]={0};
  3965. char guid[37]={0};
  3966. char tempdata[65]={0};
  3967. // Fill BootNotification fields
  3968. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  3969. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3970. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3971. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3972. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3973. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3974. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3975. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3976. ShmOCPP16Data->ChargeBoxId
  3977. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3978. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3979. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3980. ,ShmOCPP16Data->BootNotification.CpFwVersion
  3981. ,ShmOCPP16Data->BootNotification.CpIccid
  3982. ,ShmOCPP16Data->BootNotification.CpImsi);
  3983. random_uuid(guid);
  3984. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3985. LWS_Send(message);
  3986. sprintf(tempdata, "BootNotification,0");
  3987. 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*/)
  3988. {
  3989. result = PASS;
  3990. }
  3991. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3992. strcpy(queuedata,message);
  3993. return result;
  3994. }
  3995. int sendDataTransferRequest(int gun_index)
  3996. {
  3997. mtrace();
  3998. char message[1000]={0};
  3999. char guid[37]={0};
  4000. char tempdata[65]={0};
  4001. int result = FAIL;
  4002. random_uuid(guid);
  4003. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4004. MESSAGE_TYPE_CALL,
  4005. guid,
  4006. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4007. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4008. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4009. LWS_Send(message);
  4010. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4011. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4012. {
  4013. result = PASS;
  4014. DEBUG_INFO("DataTransfer mapItem pass\n");
  4015. }
  4016. return result;
  4017. }
  4018. int sendDiagnosticsStatusNotificationRequest(char *status)
  4019. {
  4020. mtrace();
  4021. int result = FAIL;
  4022. char message[110]={0};
  4023. char guid[37]={0};
  4024. char tempdata[65]={0};
  4025. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4026. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4027. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4028. random_uuid(guid);
  4029. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4030. LWS_SendNow(message);
  4031. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4032. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4033. {
  4034. result = PASS;
  4035. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4036. }
  4037. //#ifdef SystemLogMessage
  4038. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4039. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4040. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4041. //#endif
  4042. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4043. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4044. //record status
  4045. if(strcmp(status,"Idle")==0)
  4046. {
  4047. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4048. }
  4049. else if(strcmp(status,"Uploaded")==0)
  4050. {
  4051. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4052. }
  4053. else if(strcmp(status,"UploadFailed")==0)
  4054. {
  4055. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4056. }
  4057. else if(strcmp(status,"Uploading")==0)
  4058. {
  4059. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4060. }
  4061. return result;
  4062. }
  4063. int sendFirmwareStatusNotificationRequest(char *status)
  4064. {
  4065. mtrace();
  4066. int result = FAIL;
  4067. char message[110]={0};
  4068. char guid[37]={0};
  4069. char tempdata[65]={0};
  4070. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4071. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4072. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4073. random_uuid(guid);
  4074. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4075. LWS_SendNow(message);
  4076. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4077. 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*/)
  4078. {
  4079. result = PASS;
  4080. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4081. }
  4082. //#ifdef SystemLogMessage
  4083. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4084. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4085. //#endif
  4086. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4087. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4088. //record status
  4089. if(strcmp(status,"Downloaded")==0)
  4090. {
  4091. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4092. }
  4093. else if(strcmp(status,"DownloadFailed")==0)
  4094. {
  4095. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4096. }
  4097. else if(strcmp(status,"Downloading")==0)
  4098. {
  4099. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4100. }
  4101. else if(strcmp(status,"Idle")==0)
  4102. {
  4103. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4104. }
  4105. else if(strcmp(status,"InstallationFailed")==0)
  4106. {
  4107. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4108. }
  4109. else if(strcmp(status,"Installing")==0)
  4110. {
  4111. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4112. }
  4113. else if(strcmp(status,"Installed")==0)
  4114. {
  4115. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4116. }
  4117. return result;
  4118. }
  4119. int sendHeartbeatRequest(int gun_index)
  4120. {
  4121. mtrace();
  4122. int result = FAIL;
  4123. char message[80]={0};
  4124. char guid[37]={0};
  4125. char tempdata[65]={0};
  4126. random_uuid(guid);
  4127. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4128. , MESSAGE_TYPE_CALL
  4129. , guid );
  4130. LWS_Send(message);
  4131. sprintf(tempdata, "Heartbeat,%d", 0);
  4132. 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*/)
  4133. {
  4134. result = PASS;
  4135. }
  4136. return result;
  4137. }
  4138. int sendStartTransactionRequest(int gun_index)
  4139. {
  4140. mtrace();
  4141. int result = FAIL;
  4142. char message[250]={0};
  4143. char guid[37]={0};
  4144. struct timeval tmnow;
  4145. struct tm *tm;
  4146. char buf[28];//, usec_buf[6];
  4147. char tempdata[65]={0};
  4148. int tempIndex = 0;
  4149. DEBUG_INFO("sendStartTransactionRequest...\n");
  4150. gettimeofday(&tmnow, NULL);
  4151. time_t t;
  4152. t = time(NULL);
  4153. /*UTC time and date*/
  4154. tm = gmtime(&t);
  4155. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4156. #if 0 // remove temporally
  4157. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4158. strcat(buf,".");
  4159. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4160. strcat(buf,usec_buf);
  4161. #endif
  4162. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4163. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4164. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4165. // clear StartTransaction Response
  4166. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4167. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4168. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4169. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4170. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  4171. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4172. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4173. {
  4174. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4175. {
  4176. tempIndex = ((gun_index==2) ? 1: 0);
  4177. }
  4178. else
  4179. {
  4180. tempIndex = gun_index;
  4181. }
  4182. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4183. {
  4184. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4185. {
  4186. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4187. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4188. }
  4189. }
  4190. }
  4191. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4192. {
  4193. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4194. {
  4195. tempIndex = ((gun_index==2) ? 1: 0);
  4196. }
  4197. else
  4198. {
  4199. tempIndex = gun_index;
  4200. }
  4201. for (int index = 0; index < CCS_QUANTITY; index++)
  4202. {
  4203. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4204. {
  4205. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4206. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4207. }
  4208. }
  4209. }
  4210. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4211. {
  4212. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4213. {
  4214. tempIndex = ((gun_index==2) ? 1: 0);
  4215. }
  4216. else
  4217. {
  4218. tempIndex = gun_index;
  4219. }
  4220. for (int index = 0; index < GB_QUANTITY; index++)
  4221. {
  4222. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4223. {
  4224. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4225. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4226. }
  4227. }
  4228. }
  4229. else if(gunType[gun_index] == GUN_TYPE_DO)
  4230. {
  4231. tempIndex = gun_index;
  4232. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4233. {
  4234. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4235. {
  4236. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4237. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4238. }
  4239. }
  4240. }
  4241. else
  4242. {
  4243. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4244. {
  4245. tempIndex = 2;
  4246. }
  4247. else
  4248. {
  4249. tempIndex = gun_index;
  4250. }
  4251. for (int index = 0; index < AC_QUANTITY; index++)
  4252. {
  4253. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4254. {
  4255. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4256. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4257. }
  4258. }
  4259. }
  4260. random_uuid(guid);
  4261. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4262. {
  4263. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4264. , gun_index +1
  4265. , MESSAGE_TYPE_CALL
  4266. , guid
  4267. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4268. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4269. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4270. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4271. }
  4272. else
  4273. {
  4274. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4275. , gun_index +1
  4276. , MESSAGE_TYPE_CALL
  4277. , guid
  4278. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4279. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4280. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4281. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  4282. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4283. }
  4284. #if 1
  4285. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4286. 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*/)
  4287. {
  4288. result = PASS;
  4289. }
  4290. #endif
  4291. strcpy(queuedata, message);
  4292. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4293. OCPP_insert_transaction_msg(YES, queuedata);
  4294. return result;
  4295. }
  4296. int sendStatusNotificationRequest(int gun_index)
  4297. {
  4298. mtrace();
  4299. int result = FAIL;
  4300. char message[600]={0};
  4301. char guid[37];
  4302. int currentStatus = 0;
  4303. struct timeval tmnow;
  4304. struct tm *tm;
  4305. char buf[28];//, usec_buf[6];
  4306. char tempdata[65]={0};
  4307. int tempIndex = 0;
  4308. uint8_t isStateChanged = TRUE;
  4309. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4310. gettimeofday(&tmnow, NULL);
  4311. time_t t;
  4312. t = time(NULL);
  4313. /*UTC time and date*/
  4314. tm = gmtime(&t);
  4315. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4316. #if 0 // remove temporally
  4317. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4318. strcat(buf,".");
  4319. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4320. strcat(buf,usec_buf);
  4321. #endif
  4322. //printf("%s",buf);
  4323. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4324. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4325. // it's option
  4326. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  4327. /*
  4328. enum _SYSTEM_STATUS
  4329. {
  4330. S_BOOTING = 0,
  4331. S_IDLE, = 1
  4332. S_AUTHORIZING, =2
  4333. S_REASSIGN_CHECK, =3
  4334. S_REASSIGN, =4
  4335. S_PRECHARGE, =5
  4336. S_PREPARING_FOR_EV, =6
  4337. S_PREPARING_FOR_EVSE, =7
  4338. S_CHARGING, =8
  4339. S_TERMINATING, =9
  4340. S_COMPLETE, =10
  4341. S_ALARM, =11
  4342. S_FAULT =12
  4343. }
  4344. */
  4345. //check Transaction active
  4346. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4347. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4348. {
  4349. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4350. {
  4351. tempIndex = ((gun_index==2) ? 1: 0);
  4352. }
  4353. else
  4354. {
  4355. tempIndex = gun_index;
  4356. }
  4357. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4358. {
  4359. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4360. {
  4361. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4362. {
  4363. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4364. {
  4365. currentStatus = Preparing; //OCPP Status: Preparing
  4366. }
  4367. else
  4368. {
  4369. currentStatus = Available; //OCPP Status: Available
  4370. }
  4371. }
  4372. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4373. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4374. ) //S_PRECHARGE
  4375. {
  4376. currentStatus = Preparing; //OCPP Status: Preparing
  4377. }
  4378. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4379. {
  4380. currentStatus = Charging; //OCPP Status: Charging
  4381. }
  4382. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4383. {
  4384. currentStatus = Finishing; //OCPP Status: Finishing
  4385. }
  4386. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4387. {
  4388. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4389. }
  4390. 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
  4391. {
  4392. currentStatus = Unavailable; //OCPP Status: Unavailable
  4393. }
  4394. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4395. {
  4396. currentStatus = Faulted; //OCPP Status: Faulted
  4397. }
  4398. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4399. {
  4400. currentStatus = Reserved; //OCPP Status: Reserved
  4401. }
  4402. } //end of the same index
  4403. }//end of for CHAdeMO_QUANTITY
  4404. }
  4405. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4406. {
  4407. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4408. {
  4409. tempIndex = ((gun_index==2) ? 1: 0);
  4410. }
  4411. else
  4412. {
  4413. tempIndex = gun_index;
  4414. }
  4415. for (int index = 0; index < CCS_QUANTITY; index++)
  4416. {
  4417. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4418. {
  4419. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4420. {
  4421. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4422. {
  4423. currentStatus = Preparing; //OCPP Status: Preparing
  4424. }
  4425. else
  4426. {
  4427. currentStatus = Available; //OCPP Status: Available
  4428. }
  4429. }
  4430. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4431. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4432. ) //S_PRECHARGE
  4433. {
  4434. currentStatus = Preparing; //OCPP Status: Preparing
  4435. }
  4436. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4437. {
  4438. currentStatus = Charging; //OCPP Status: Charging
  4439. }
  4440. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4441. {
  4442. currentStatus = Finishing; //OCPP Status: Finishing
  4443. }
  4444. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4445. {
  4446. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4447. }
  4448. 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
  4449. {
  4450. currentStatus = Unavailable; //OCPP Status : Unavailable
  4451. }
  4452. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4453. {
  4454. currentStatus = Faulted; //OCPP Status: Faulted
  4455. }
  4456. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4457. {
  4458. currentStatus = Reserved; //OCPP Status: Reserved
  4459. }
  4460. } //end of the same index
  4461. } // end of for CCS_QUANTITY
  4462. }
  4463. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4464. {
  4465. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4466. {
  4467. tempIndex = ((gun_index==2) ? 1: 0);
  4468. }
  4469. else
  4470. {
  4471. tempIndex = gun_index;
  4472. }
  4473. for (int index = 0; index < GB_QUANTITY; index++)
  4474. {
  4475. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4476. {
  4477. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4478. {
  4479. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4480. {
  4481. currentStatus = Preparing; //OCPP Status: Preparing
  4482. }
  4483. else
  4484. {
  4485. currentStatus = Available; //OCPP Status: Available
  4486. }
  4487. }
  4488. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4489. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4490. ) //S_PRECHARGE
  4491. {
  4492. currentStatus = Preparing; //OCPP Status: Preparing
  4493. }
  4494. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4495. {
  4496. currentStatus = Charging; //OCPP Status: Charging
  4497. }
  4498. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4499. {
  4500. currentStatus = Finishing; //OCPP Status: Finishing
  4501. }
  4502. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4503. {
  4504. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4505. }
  4506. 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
  4507. {
  4508. currentStatus = Unavailable; //OCPP Status: Unavailable
  4509. }
  4510. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4511. {
  4512. currentStatus = Faulted; //OCPP Status: Faulted
  4513. }
  4514. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4515. {
  4516. currentStatus = Reserved; //OCPP Status: Reserved
  4517. }
  4518. } //end of the same index
  4519. } // end of for GB_QUANTITY
  4520. }
  4521. else if(gunType[gun_index] == GUN_TYPE_DO)
  4522. {
  4523. tempIndex = gun_index;
  4524. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4525. {
  4526. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4527. {
  4528. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4529. {
  4530. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4531. {
  4532. currentStatus = Preparing; //OCPP Status: Preparing
  4533. }
  4534. else
  4535. {
  4536. currentStatus = Available; //OCPP Status: Available
  4537. }
  4538. }
  4539. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4540. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4541. ) //S_PRECHARGE
  4542. {
  4543. currentStatus = Preparing; //OCPP Status: Preparing
  4544. }
  4545. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4546. {
  4547. currentStatus = Charging; //OCPP Status: Charging
  4548. }
  4549. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4550. {
  4551. currentStatus = Finishing; //OCPP Status: Finishing
  4552. }
  4553. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4554. {
  4555. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4556. }
  4557. 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
  4558. {
  4559. currentStatus = Unavailable; //OCPP Status: Unavailable
  4560. }
  4561. 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
  4562. {
  4563. currentStatus = Faulted; //OCPP Status: Faulted
  4564. }
  4565. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4566. {
  4567. currentStatus = Reserved; //OCPP Status: Reserved
  4568. }
  4569. } //end of the same index
  4570. }
  4571. }
  4572. else
  4573. {
  4574. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4575. {
  4576. tempIndex = 2;
  4577. }
  4578. else
  4579. {
  4580. tempIndex = gun_index;
  4581. }
  4582. for (int index = 0; index < AC_QUANTITY; index++)
  4583. {
  4584. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4585. {
  4586. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4587. {
  4588. 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))
  4589. {
  4590. currentStatus = Preparing; //OCPP Status: Preparing
  4591. }
  4592. else
  4593. {
  4594. currentStatus = Available; //OCPP Status: Available
  4595. }
  4596. }
  4597. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4598. {
  4599. currentStatus = Preparing; //OCPP Status: Preparing
  4600. }
  4601. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4602. {
  4603. currentStatus = Charging; //OCPP Status: Charging
  4604. }
  4605. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4606. {
  4607. currentStatus = Finishing; //OCPP Status: Finishing
  4608. }
  4609. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4610. {
  4611. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4612. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4613. else
  4614. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4615. }
  4616. 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
  4617. {
  4618. currentStatus = Unavailable; //OCPP Status: Unavailable
  4619. }
  4620. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4621. {
  4622. currentStatus = Faulted; //OCPP Status: Faulted
  4623. }
  4624. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4625. {
  4626. currentStatus = Reserved; //OCPP Status: Reserved
  4627. }
  4628. }//end of the same index
  4629. }//end of for AC_QUANTITY
  4630. }
  4631. //it's option
  4632. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4633. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4634. {
  4635. isStateChanged = FALSE;
  4636. }
  4637. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4638. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  4639. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4640. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4641. random_uuid(guid);
  4642. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4643. , MESSAGE_TYPE_CALL
  4644. , guid
  4645. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  4646. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  4647. , ShmOCPP16Data->StatusNotification[gun_index].Info
  4648. , ShmOCPP16Data->StatusNotification[gun_index].Status
  4649. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  4650. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  4651. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  4652. if((server_sign == TRUE) && isStateChanged)
  4653. {
  4654. LWS_Send(message);
  4655. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4656. 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*/)
  4657. {
  4658. //DEBUG_ERROR("statusNotification mapitem pass");
  4659. result = PASS;
  4660. }
  4661. }
  4662. else
  4663. {
  4664. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4665. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4666. result = PASS;
  4667. }
  4668. return result;
  4669. }
  4670. int sendStopTransactionRequest(int gun_index)
  4671. {
  4672. mtrace();
  4673. int result = FAIL;
  4674. //char message[1500]={0};
  4675. char guid[37]={0};
  4676. char tempdata[65]={0};
  4677. int tempIndex = 0;
  4678. char TempStopTransaction[256];
  4679. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  4680. //int idx_sample=0;
  4681. DEBUG_INFO("sendStopTransactionRequest \n");
  4682. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4683. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  4684. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4685. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4686. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4687. {
  4688. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4689. {
  4690. tempIndex = ((gun_index==2) ? 1: 0);
  4691. }
  4692. else
  4693. {
  4694. tempIndex = gun_index;
  4695. }
  4696. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4697. {
  4698. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4699. {
  4700. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4701. }
  4702. }// END OF CHAdeMO_QUANTITY
  4703. }
  4704. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4705. {
  4706. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4707. {
  4708. tempIndex = ((gun_index==2) ? 1: 0);
  4709. }
  4710. else
  4711. {
  4712. tempIndex = gun_index;
  4713. }
  4714. for (int index = 0; index < CCS_QUANTITY; index++)
  4715. {
  4716. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4717. {
  4718. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4719. }
  4720. }// END OF CCS_QUANTITY
  4721. }
  4722. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4723. {
  4724. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4725. {
  4726. tempIndex = ((gun_index==2) ? 1: 0);
  4727. }
  4728. else
  4729. {
  4730. tempIndex = gun_index;
  4731. }
  4732. for (int index = 0; index < GB_QUANTITY; index++)
  4733. {
  4734. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4735. {
  4736. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4737. }
  4738. }// END OF GB_QUANTITY
  4739. }
  4740. else if(gunType[gun_index] == GUN_TYPE_DO)
  4741. {
  4742. tempIndex = gun_index;
  4743. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4744. {
  4745. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4746. {
  4747. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4748. }
  4749. }// END OF GB_QUANTITY
  4750. }
  4751. else
  4752. {
  4753. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4754. {
  4755. tempIndex = 2;
  4756. }
  4757. else
  4758. {
  4759. tempIndex = gun_index;
  4760. }
  4761. for (int index = 0; index < AC_QUANTITY; index++)
  4762. {
  4763. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4764. {
  4765. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4766. }
  4767. }// END OF AC_QUANTITY
  4768. }
  4769. //====================================== Stop Transaction Time =====================================================
  4770. struct timeval tmnow;
  4771. struct tm *tm;
  4772. char buf[28];//, usec_buf[6];
  4773. gettimeofday(&tmnow, NULL);
  4774. time_t t;
  4775. t = time(NULL);
  4776. /*UTC time and date*/
  4777. tm = gmtime(&t);
  4778. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4779. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  4780. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4781. random_uuid(guid);
  4782. /***********************************transactionData******************************************************/
  4783. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4784. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4785. //=================================
  4786. // Transaction_Begin
  4787. //=================================
  4788. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4789. {
  4790. //============================================ Energy.Active.Import.Interval ================================
  4791. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4792. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4793. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4794. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  4795. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4796. 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))
  4797. {
  4798. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4799. }
  4800. else
  4801. {
  4802. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4803. }
  4804. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4805. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4806. }
  4807. //=================================
  4808. // Transaction_End
  4809. //=================================
  4810. // ================================= Current.Import L1 ===============================================
  4811. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4812. {
  4813. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4814. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4815. {
  4816. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4817. {
  4818. tempIndex = ((gun_index==2) ? 1: 0);
  4819. }
  4820. else
  4821. {
  4822. tempIndex = gun_index;
  4823. }
  4824. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4825. {
  4826. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4827. {
  4828. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4829. }
  4830. }// End of for CHAdeMO_QUANTITY
  4831. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4832. }
  4833. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4834. {
  4835. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4836. {
  4837. tempIndex = ((gun_index==2) ? 1: 0);
  4838. }
  4839. else
  4840. {
  4841. tempIndex = gun_index;
  4842. }
  4843. for (int index = 0; index < CCS_QUANTITY; index++)
  4844. {
  4845. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4846. {
  4847. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4848. }
  4849. }// End of for CCS_QUANTITY
  4850. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4851. }
  4852. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4853. {
  4854. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4855. {
  4856. tempIndex = ((gun_index==2) ? 1: 0);
  4857. }
  4858. else
  4859. {
  4860. tempIndex = gun_index;
  4861. }
  4862. for (int index = 0; index < GB_QUANTITY; index++)
  4863. {
  4864. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4865. {
  4866. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4867. }
  4868. }// End of for GB_QUANTITY
  4869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4870. }
  4871. else if(gunType[gun_index] == GUN_TYPE_DO)
  4872. {
  4873. tempIndex = gun_index;
  4874. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4875. {
  4876. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4877. {
  4878. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4879. }
  4880. }
  4881. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4882. }
  4883. else
  4884. {
  4885. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4886. {
  4887. tempIndex = 2;
  4888. }
  4889. else
  4890. {
  4891. tempIndex = gun_index;
  4892. }
  4893. for (int index = 0; index < AC_QUANTITY; index++)
  4894. {
  4895. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4896. {
  4897. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4898. }
  4899. }// End of for AC_QUANTITY
  4900. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4901. }
  4902. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4903. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4904. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4905. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4906. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4907. }
  4908. // ================================= Energy.Active.Import.Interval ==============================================
  4909. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4910. {
  4911. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4912. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4913. {
  4914. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4915. {
  4916. tempIndex = ((gun_index==2) ? 1: 0);
  4917. }
  4918. else
  4919. {
  4920. tempIndex = gun_index;
  4921. }
  4922. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4923. {
  4924. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4925. {
  4926. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4927. }
  4928. }// END OF CHAdeMO_QUANTITY
  4929. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4930. }
  4931. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4932. {
  4933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4934. {
  4935. tempIndex = ((gun_index==2) ? 1: 0);
  4936. }
  4937. else
  4938. {
  4939. tempIndex = gun_index;
  4940. }
  4941. for (int index = 0; index < CCS_QUANTITY; index++)
  4942. {
  4943. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4944. {
  4945. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4946. }
  4947. }// END OF CCS_QUANTITY
  4948. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4949. }
  4950. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4951. {
  4952. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4953. {
  4954. tempIndex = ((gun_index==2) ? 1: 0);
  4955. }
  4956. else
  4957. {
  4958. tempIndex = gun_index;
  4959. }
  4960. for (int index = 0; index < GB_QUANTITY; index++)
  4961. {
  4962. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4963. {
  4964. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4965. }
  4966. }// END OF GB_QUANTITY
  4967. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4968. }
  4969. else if(gunType[gun_index] == GUN_TYPE_DO)
  4970. {
  4971. tempIndex = gun_index;
  4972. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4973. {
  4974. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4975. {
  4976. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4977. }
  4978. }
  4979. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4980. }
  4981. else
  4982. {
  4983. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4984. {
  4985. tempIndex = 2;
  4986. }
  4987. else
  4988. {
  4989. tempIndex = gun_index;
  4990. }
  4991. for (int index = 0; index < AC_QUANTITY; index++)
  4992. {
  4993. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4994. {
  4995. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4996. }
  4997. }// END OF AC_QUANTITY
  4998. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4999. }
  5000. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5001. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5002. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5003. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5004. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5005. }
  5006. //=================================== Power.Active.Import ==================================================
  5007. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5008. {
  5009. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5010. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5011. {
  5012. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5013. {
  5014. tempIndex = ((gun_index==2) ? 1: 0);
  5015. }
  5016. else
  5017. {
  5018. tempIndex = gun_index;
  5019. }
  5020. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5021. {
  5022. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5023. {
  5024. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5025. }
  5026. } // End for CHAdeMO_QUANTITY
  5027. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5028. }
  5029. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5030. {
  5031. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5032. {
  5033. tempIndex = ((gun_index==2) ? 1: 0);
  5034. }
  5035. else
  5036. {
  5037. tempIndex = gun_index;
  5038. }
  5039. for (int index = 0; index < CCS_QUANTITY; index++)
  5040. {
  5041. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5042. {
  5043. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5044. }
  5045. } // END for CCS_QUANTITY
  5046. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5047. }
  5048. else if(gunType[gun_index] == GUN_TYPE_GBT)
  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 < GB_QUANTITY; index++)
  5059. {
  5060. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5061. {
  5062. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5063. }
  5064. }// END for GB_QUANTITY
  5065. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5066. }
  5067. else if(gunType[gun_index] == GUN_TYPE_DO)
  5068. {
  5069. tempIndex = gun_index;
  5070. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5071. {
  5072. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5073. {
  5074. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5075. }
  5076. }
  5077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5078. }
  5079. else
  5080. {
  5081. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5082. {
  5083. tempIndex = 2;
  5084. }
  5085. else
  5086. {
  5087. tempIndex = gun_index;
  5088. }
  5089. for (int index = 0; index < AC_QUANTITY; index++)
  5090. {
  5091. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5092. {
  5093. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5094. }
  5095. } // END for AC_QUANTITY
  5096. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5097. }
  5098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5103. }
  5104. //============================ Voltage L1 ====================================
  5105. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5106. {
  5107. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5108. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5109. {
  5110. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5111. {
  5112. tempIndex = ((gun_index==2) ? 1: 0);
  5113. }
  5114. else
  5115. {
  5116. tempIndex = gun_index;
  5117. }
  5118. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5119. {
  5120. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5121. {
  5122. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5123. }
  5124. } // END OF FOR CHAdeMO_QUANTITY
  5125. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5126. }
  5127. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5128. {
  5129. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5130. {
  5131. tempIndex = ((gun_index==2) ? 1: 0);
  5132. }
  5133. else
  5134. {
  5135. tempIndex = gun_index;
  5136. }
  5137. for (int index = 0; index < CCS_QUANTITY; index++)
  5138. {
  5139. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5140. {
  5141. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5142. }
  5143. } // END OF FOR CCS_QUANTITY
  5144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5145. }
  5146. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5147. {
  5148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5149. {
  5150. tempIndex = ((gun_index==2) ? 1: 0);
  5151. }
  5152. else
  5153. {
  5154. tempIndex = gun_index;
  5155. }
  5156. for (int index = 0; index < GB_QUANTITY; index++)
  5157. {
  5158. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5159. {
  5160. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5161. }
  5162. } // END OF FOR GB_QUANTITY
  5163. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5164. }
  5165. else if(gunType[gun_index] == GUN_TYPE_DO)
  5166. {
  5167. tempIndex = gun_index;
  5168. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5169. {
  5170. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5171. {
  5172. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5173. }
  5174. }
  5175. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5176. }
  5177. else
  5178. {
  5179. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5180. {
  5181. tempIndex = 2;
  5182. }
  5183. else
  5184. {
  5185. tempIndex = gun_index;
  5186. }
  5187. for (int index = 0; index < AC_QUANTITY; index++)
  5188. {
  5189. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5190. {
  5191. 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
  5192. }
  5193. } // END OF FOR AC_QUANTITY
  5194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5195. }
  5196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5201. }
  5202. //====================== End SoC ================================
  5203. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  5204. {
  5205. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5206. 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))
  5207. {
  5208. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5209. {
  5210. tempIndex = ((gun_index==2) ? 1: 0);
  5211. }
  5212. else
  5213. {
  5214. tempIndex = gun_index;
  5215. }
  5216. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5217. {
  5218. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5219. {
  5220. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5221. {
  5222. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5223. }
  5224. }
  5225. }
  5226. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5227. {
  5228. for (int index = 0; index < CCS_QUANTITY; index++)
  5229. {
  5230. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5231. {
  5232. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5233. }
  5234. }
  5235. }
  5236. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5237. {
  5238. for (int index = 0; index < GB_QUANTITY; index++)
  5239. {
  5240. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5241. {
  5242. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5243. }
  5244. }
  5245. }
  5246. else if(gunType[gun_index] == GUN_TYPE_DO)
  5247. {
  5248. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5249. {
  5250. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5251. {
  5252. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5253. }
  5254. }
  5255. }
  5256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5261. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5262. } // END FOR DC CASE
  5263. }
  5264. // ================================= Current.Import L2 ===============================================
  5265. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5266. {
  5267. // AC 3 phse L2 current
  5268. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5269. {
  5270. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5271. {
  5272. tempIndex = 2;
  5273. }
  5274. else
  5275. {
  5276. tempIndex = gun_index;
  5277. }
  5278. for (int index = 0; index < AC_QUANTITY; index++)
  5279. {
  5280. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5281. {
  5282. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5283. }
  5284. }// End of for AC_QUANTITY
  5285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5286. }
  5287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5289. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5290. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5291. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5292. }
  5293. // ================================= Current.Import L3 ===============================================
  5294. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5295. {
  5296. // AC 3 phse L3 current
  5297. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5298. {
  5299. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5300. {
  5301. tempIndex = 2;
  5302. }
  5303. else
  5304. {
  5305. tempIndex = gun_index;
  5306. }
  5307. for (int index = 0; index < AC_QUANTITY; index++)
  5308. {
  5309. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5310. {
  5311. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5312. }
  5313. }// End of for AC_QUANTITY
  5314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5315. }
  5316. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5317. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5318. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5319. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5320. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5321. }
  5322. //============================ Voltage L2 ====================================
  5323. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5324. {
  5325. // AC 3 phse L2 voltage
  5326. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5327. {
  5328. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5329. {
  5330. tempIndex = 2;
  5331. }
  5332. else
  5333. {
  5334. tempIndex = gun_index;
  5335. }
  5336. for (int index = 0; index < AC_QUANTITY; index++)
  5337. {
  5338. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5339. {
  5340. 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
  5341. }
  5342. } // END OF FOR AC_QUANTITY
  5343. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5344. }
  5345. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5346. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5347. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5348. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5349. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5350. }
  5351. //============================ Voltage L3 ====================================
  5352. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5353. {
  5354. // AC 3 phse L3 voltage
  5355. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5356. {
  5357. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5358. {
  5359. tempIndex = 2;
  5360. }
  5361. else
  5362. {
  5363. tempIndex = gun_index;
  5364. }
  5365. for (int index = 0; index < AC_QUANTITY; index++)
  5366. {
  5367. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5368. {
  5369. 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
  5370. }
  5371. } // END OF FOR AC_QUANTITY
  5372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5373. }
  5374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5376. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5377. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5378. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5379. }
  5380. //====================== Start SoC ================================
  5381. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  5382. {
  5383. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5384. 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))
  5385. {
  5386. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5387. {
  5388. tempIndex = ((gun_index==2) ? 1: 0);
  5389. }
  5390. else
  5391. {
  5392. tempIndex = gun_index;
  5393. }
  5394. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5395. {
  5396. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5397. {
  5398. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5399. {
  5400. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5401. }
  5402. }
  5403. }
  5404. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5405. {
  5406. for (int index = 0; index < CCS_QUANTITY; index++)
  5407. {
  5408. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5409. {
  5410. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5411. }
  5412. }
  5413. }
  5414. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5415. {
  5416. for (int index = 0; index < GB_QUANTITY; index++)
  5417. {
  5418. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5419. {
  5420. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5421. }
  5422. }
  5423. }
  5424. else if(gunType[gun_index] == GUN_TYPE_DO)
  5425. {
  5426. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5427. {
  5428. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5429. {
  5430. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5431. }
  5432. }
  5433. }
  5434. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5435. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5436. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5437. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5438. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5439. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5440. } // END FOR DC CASE
  5441. }
  5442. //================================================ Message create ====================================================
  5443. json_object *StopTransaction = json_object_new_object();
  5444. json_object *transactionDatas = json_object_new_array();
  5445. json_object *sampledValues = json_object_new_array();
  5446. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  5447. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  5448. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  5449. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  5450. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  5451. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  5452. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  5453. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  5454. {
  5455. json_object *transactionData = json_object_new_object();
  5456. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5457. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5458. {
  5459. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5460. {
  5461. json_object *sampledValue = json_object_new_object();
  5462. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5463. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5464. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5465. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5466. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5467. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5468. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5469. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5470. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5471. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5472. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5473. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5474. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5475. json_object_array_add(sampledValues, sampledValue);
  5476. }
  5477. }
  5478. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5479. json_object_array_add(transactionDatas, transactionData);
  5480. }
  5481. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5482. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5483. ,MESSAGE_TYPE_CALL
  5484. ,guid
  5485. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5486. json_object_put(StopTransaction);
  5487. #if 1 // for TempStopTransaction
  5488. //Delete TempStopTransaction
  5489. if((access(TempStopTransaction,F_OK))!=-1)
  5490. {
  5491. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5492. }
  5493. #endif
  5494. #if 1
  5495. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5496. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5497. {
  5498. result = PASS;
  5499. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5500. }
  5501. #endif
  5502. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5503. OCPP_insert_transaction_msg(NO, queuedata);
  5504. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5505. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  5506. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  5507. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5508. {
  5509. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  5510. }
  5511. //for test
  5512. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5513. return result;
  5514. }
  5515. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5516. {
  5517. mtrace();
  5518. int result = FAIL;
  5519. char guid[37]={0};
  5520. char tempdata[65]={0};
  5521. int tempIndex = 0;
  5522. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5523. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5524. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5525. //set value
  5526. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5527. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEV") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEVSE") != NULL) )?
  5528. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  5529. -1);
  5530. random_uuid(guid);
  5531. //UTC Date time
  5532. struct timeval tmnow;
  5533. struct tm *tm;
  5534. char buf[28];//, usec_buf[6];
  5535. gettimeofday(&tmnow, NULL);
  5536. time_t t;
  5537. t = time(NULL);
  5538. /*UTC time and date*/
  5539. tm = gmtime(&t);
  5540. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5541. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5542. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5543. //********************************(1)Current.Import L1************************************************/
  5544. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5545. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5546. (dataType == ReadingContext_Trigger))
  5547. {
  5548. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5549. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5550. {
  5551. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5552. {
  5553. tempIndex = ((gun_index==2) ? 1: 0);
  5554. }
  5555. else
  5556. {
  5557. tempIndex = gun_index;
  5558. }
  5559. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5560. {
  5561. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5562. {
  5563. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5564. }
  5565. }
  5566. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5567. }
  5568. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5569. {
  5570. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5571. {
  5572. tempIndex = ((gun_index==2) ? 1: 0);
  5573. }
  5574. else
  5575. {
  5576. tempIndex = gun_index;
  5577. }
  5578. for (int index = 0; index < CCS_QUANTITY; index++)
  5579. {
  5580. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5581. {
  5582. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5583. }
  5584. }
  5585. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5586. }
  5587. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5588. {
  5589. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5590. {
  5591. tempIndex = ((gun_index==2) ? 1: 0);
  5592. }
  5593. else
  5594. {
  5595. tempIndex = gun_index;
  5596. }
  5597. for (int index = 0; index < GB_QUANTITY; index++)
  5598. {
  5599. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5600. {
  5601. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5602. }
  5603. }
  5604. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5605. }
  5606. else if(gunType[gun_index] == GUN_TYPE_DO)
  5607. {
  5608. tempIndex = gun_index;
  5609. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5610. {
  5611. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5612. {
  5613. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5614. }
  5615. }
  5616. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5617. }
  5618. else
  5619. {
  5620. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5621. {
  5622. tempIndex = 2;
  5623. }
  5624. else
  5625. {
  5626. tempIndex = gun_index;
  5627. }
  5628. for (int index = 0; index < AC_QUANTITY; index++)
  5629. {
  5630. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5631. {
  5632. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5633. }
  5634. }
  5635. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5636. }
  5637. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5638. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5639. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5640. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5641. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5642. }
  5643. //********************************(2)Energy.Active.Import.Register ************************************************/
  5644. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  5645. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  5646. (dataType == ReadingContext_Trigger))
  5647. {
  5648. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5649. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5650. {
  5651. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5652. {
  5653. tempIndex = ((gun_index==2) ? 1: 0);
  5654. }
  5655. else
  5656. {
  5657. tempIndex = gun_index;
  5658. }
  5659. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5660. {
  5661. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5662. {
  5663. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5664. }
  5665. }
  5666. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5667. }
  5668. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5669. {
  5670. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5671. {
  5672. tempIndex = ((gun_index==2) ? 1: 0);
  5673. }
  5674. else
  5675. {
  5676. tempIndex = gun_index;
  5677. }
  5678. for (int index = 0; index < CCS_QUANTITY; index++)
  5679. {
  5680. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5681. {
  5682. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5683. }
  5684. }
  5685. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5686. }
  5687. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5688. {
  5689. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5690. {
  5691. tempIndex = ((gun_index==2) ? 1: 0);
  5692. }
  5693. else
  5694. {
  5695. tempIndex = gun_index;
  5696. }
  5697. for (int index = 0; index < GB_QUANTITY; index++)
  5698. {
  5699. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5700. {
  5701. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5702. }
  5703. }
  5704. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5705. }
  5706. else if(gunType[gun_index] == GUN_TYPE_DO)
  5707. {
  5708. tempIndex = gun_index;
  5709. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5710. {
  5711. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5712. {
  5713. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5714. }
  5715. }
  5716. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5717. }
  5718. else
  5719. {
  5720. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5721. {
  5722. tempIndex = 2;
  5723. }
  5724. else
  5725. {
  5726. tempIndex = gun_index;
  5727. }
  5728. for (int index = 0; index < AC_QUANTITY; index++)
  5729. {
  5730. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5731. {
  5732. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5733. }
  5734. }
  5735. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5736. }
  5737. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5738. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5739. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5740. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5741. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5742. }
  5743. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5744. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5745. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5746. (dataType == ReadingContext_Trigger))
  5747. {
  5748. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5749. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5750. {
  5751. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5752. {
  5753. tempIndex = ((gun_index==2) ? 1: 0);
  5754. }
  5755. else
  5756. {
  5757. tempIndex = gun_index;
  5758. }
  5759. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5760. {
  5761. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5762. {
  5763. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5764. }
  5765. } // END OF FOR CHAdeMO_QUANTITY
  5766. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5767. }
  5768. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5769. {
  5770. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5771. {
  5772. tempIndex = ((gun_index==2) ? 1: 0);
  5773. }
  5774. else
  5775. {
  5776. tempIndex = gun_index;
  5777. }
  5778. for (int index = 0; index < CCS_QUANTITY; index++)
  5779. {
  5780. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5781. {
  5782. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5783. }
  5784. } // END OF CCS_QUANTITY
  5785. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5786. }
  5787. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5788. {
  5789. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5790. {
  5791. tempIndex = ((gun_index==2) ? 1: 0);
  5792. }
  5793. else
  5794. {
  5795. tempIndex = gun_index;
  5796. }
  5797. for (int index = 0; index < GB_QUANTITY; index++)
  5798. {
  5799. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5800. {
  5801. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5802. }
  5803. } // END OF GB_QUANTITY
  5804. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5805. }
  5806. else if(gunType[gun_index] == GUN_TYPE_DO)
  5807. {
  5808. tempIndex = gun_index;
  5809. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5810. {
  5811. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5812. {
  5813. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5814. }
  5815. }
  5816. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5817. }
  5818. else
  5819. {
  5820. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5821. {
  5822. tempIndex = 2;
  5823. }
  5824. else
  5825. {
  5826. tempIndex = gun_index;
  5827. }
  5828. for (int index = 0; index < AC_QUANTITY; index++)
  5829. {
  5830. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5831. {
  5832. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5833. }
  5834. }
  5835. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5836. }
  5837. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5838. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5839. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5840. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5841. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5842. }
  5843. //********************************(4)Power.Active.Import************************************************/
  5844. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5845. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5846. (dataType == ReadingContext_Trigger))
  5847. {
  5848. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5849. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5850. {
  5851. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5852. {
  5853. tempIndex = ((gun_index==2) ? 1: 0);
  5854. }
  5855. else
  5856. {
  5857. tempIndex = gun_index;
  5858. }
  5859. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5860. {
  5861. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5862. {
  5863. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5864. }
  5865. } // END OF FOR
  5866. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5867. }
  5868. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5869. {
  5870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5871. {
  5872. tempIndex = ((gun_index==2) ? 1: 0);
  5873. }
  5874. else
  5875. {
  5876. tempIndex = gun_index;
  5877. }
  5878. for (int index = 0; index < CCS_QUANTITY; index++)
  5879. {
  5880. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5881. {
  5882. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5883. }
  5884. }
  5885. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5886. }
  5887. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5888. {
  5889. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5890. {
  5891. tempIndex = ((gun_index==2) ? 1: 0);
  5892. }
  5893. else
  5894. {
  5895. tempIndex = gun_index;
  5896. }
  5897. for (int index = 0; index < GB_QUANTITY; index++)
  5898. {
  5899. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5900. {
  5901. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5902. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5903. }
  5904. }
  5905. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5906. }
  5907. else if(gunType[gun_index] == GUN_TYPE_DO)
  5908. {
  5909. tempIndex = gun_index;
  5910. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5911. {
  5912. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5913. {
  5914. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5915. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5916. }
  5917. }
  5918. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5919. }
  5920. else
  5921. {
  5922. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5923. {
  5924. tempIndex = 2;
  5925. }
  5926. else
  5927. {
  5928. tempIndex = gun_index;
  5929. }
  5930. for (int index = 0; index < AC_QUANTITY; index++)
  5931. {
  5932. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5933. {
  5934. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5935. }
  5936. }
  5937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5938. }
  5939. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5940. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5941. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5942. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5943. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5944. }
  5945. //***********************************************(5)VOLTAGE L1******************************************************/
  5946. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5947. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5948. (dataType == ReadingContext_Trigger))
  5949. {
  5950. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5951. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5952. {
  5953. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5954. {
  5955. tempIndex = ((gun_index==2) ? 1: 0);
  5956. }
  5957. else
  5958. {
  5959. tempIndex = gun_index;
  5960. }
  5961. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5962. {
  5963. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5964. {
  5965. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5966. }
  5967. }
  5968. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5969. }
  5970. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5971. {
  5972. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5973. {
  5974. tempIndex = ((gun_index==2) ? 1: 0);
  5975. }
  5976. else
  5977. {
  5978. tempIndex = gun_index;
  5979. }
  5980. for (int index = 0; index < CCS_QUANTITY; index++)
  5981. {
  5982. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5983. {
  5984. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5985. }
  5986. }
  5987. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5988. }
  5989. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5990. {
  5991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5992. {
  5993. tempIndex = ((gun_index==2) ? 1: 0);
  5994. }
  5995. else
  5996. {
  5997. tempIndex = gun_index;
  5998. }
  5999. for (int index = 0; index < GB_QUANTITY; index++)
  6000. {
  6001. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6002. {
  6003. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6004. }
  6005. }
  6006. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6007. }
  6008. else if(gunType[gun_index] == GUN_TYPE_DO)
  6009. {
  6010. tempIndex = gun_index;
  6011. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6012. {
  6013. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6014. {
  6015. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6016. }
  6017. }
  6018. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6019. }
  6020. else
  6021. {
  6022. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6023. {
  6024. tempIndex = 2;
  6025. }
  6026. else
  6027. {
  6028. tempIndex = gun_index;
  6029. }
  6030. for (int index = 0; index < AC_QUANTITY; index++)
  6031. {
  6032. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6033. {
  6034. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6035. }
  6036. }
  6037. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6038. }
  6039. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6040. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6041. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6042. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6043. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6044. }
  6045. //***********************************************(6)SOC******************************************************/
  6046. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  6047. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  6048. (dataType == ReadingContext_Trigger))
  6049. {
  6050. 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))
  6051. {
  6052. //idx_sample=5;
  6053. //sampledValue = NULL;
  6054. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6055. {
  6056. tempIndex = ((gun_index==2) ? 1: 0);
  6057. }
  6058. else
  6059. {
  6060. tempIndex = gun_index;
  6061. }
  6062. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6063. {
  6064. //tempIndex = ((gun_index==2) ? 1: 0);
  6065. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6066. {
  6067. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6068. {
  6069. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6070. }
  6071. }
  6072. }
  6073. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6074. {
  6075. //tempIndex = ((gun_index==2) ? 1: 0);
  6076. for (int index = 0; index < CCS_QUANTITY; index++)
  6077. {
  6078. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6079. {
  6080. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6081. }
  6082. }
  6083. }
  6084. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6085. {
  6086. //tempIndex = ((gun_index==2) ? 1: 0);
  6087. for (int index = 0; index < GB_QUANTITY; index++)
  6088. {
  6089. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6090. {
  6091. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6092. }
  6093. }
  6094. }
  6095. else if(gunType[gun_index] == GUN_TYPE_DO)
  6096. {
  6097. //tempIndex = ((gun_index==2) ? 1: 0);
  6098. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6099. {
  6100. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6101. {
  6102. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6103. }
  6104. }
  6105. }
  6106. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6107. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6108. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6109. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6110. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6111. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6112. }
  6113. }
  6114. //********************************(7)Current.Import L2************************************************/
  6115. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  6116. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  6117. (dataType == ReadingContext_Trigger))
  6118. {
  6119. // Only for AC 3 phase
  6120. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6121. {
  6122. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6123. {
  6124. tempIndex = 2;
  6125. }
  6126. else
  6127. {
  6128. tempIndex = gun_index;
  6129. }
  6130. for (int index = 0; index < AC_QUANTITY; index++)
  6131. {
  6132. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6133. {
  6134. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6135. }
  6136. }
  6137. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6138. }
  6139. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6140. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6141. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6142. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6143. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6144. }
  6145. //********************************(8)Current.Import L3************************************************/
  6146. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  6147. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  6148. (dataType == ReadingContext_Trigger))
  6149. {
  6150. // Only for AC 3 phase
  6151. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6152. {
  6153. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6154. {
  6155. tempIndex = 2;
  6156. }
  6157. else
  6158. {
  6159. tempIndex = gun_index;
  6160. }
  6161. for (int index = 0; index < AC_QUANTITY; index++)
  6162. {
  6163. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6164. {
  6165. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6166. }
  6167. }
  6168. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6169. }
  6170. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6171. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6172. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6173. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6174. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6175. }
  6176. //***********************************************(9)VOLTAGE L2******************************************************/
  6177. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  6178. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  6179. (dataType == ReadingContext_Trigger))
  6180. {
  6181. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6182. {
  6183. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6184. {
  6185. tempIndex = 2;
  6186. }
  6187. else
  6188. {
  6189. tempIndex = gun_index;
  6190. }
  6191. for (int index = 0; index < AC_QUANTITY; index++)
  6192. {
  6193. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6194. {
  6195. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6196. }
  6197. }
  6198. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6199. }
  6200. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6201. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6202. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6203. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6204. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6205. }
  6206. //***********************************************(10)VOLTAGE L3******************************************************/
  6207. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  6208. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  6209. (dataType == ReadingContext_Trigger))
  6210. {
  6211. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6212. {
  6213. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6214. {
  6215. tempIndex = 2;
  6216. }
  6217. else
  6218. {
  6219. tempIndex = gun_index;
  6220. }
  6221. for (int index = 0; index < AC_QUANTITY; index++)
  6222. {
  6223. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6224. {
  6225. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6226. }
  6227. }
  6228. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6229. }
  6230. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6231. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6232. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6233. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6234. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6235. }
  6236. // Message create ====================================================================================================
  6237. if(TRUE)
  6238. {
  6239. json_object *MeterValueReq = json_object_new_object();
  6240. json_object *MeterValues = json_object_new_array();
  6241. json_object *sampledValues = json_object_new_array();
  6242. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  6243. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  6244. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  6245. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  6246. {
  6247. json_object *MeterValue = json_object_new_object();
  6248. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6249. {
  6250. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6251. {
  6252. json_object *sampledValue = json_object_new_object();
  6253. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6254. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6255. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6256. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6257. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6258. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6259. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6260. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6261. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6262. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6263. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6264. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6265. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6266. json_object_array_add(sampledValues, sampledValue);
  6267. }
  6268. }
  6269. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6270. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6271. json_object_array_add(MeterValues, MeterValue);
  6272. }
  6273. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6274. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6275. ,gun_index + 1
  6276. ,MESSAGE_TYPE_CALL
  6277. ,guid
  6278. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6279. json_object_put(MeterValueReq);
  6280. }
  6281. // Put request guid to hash map
  6282. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6283. 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*/)
  6284. {
  6285. result = PASS;
  6286. //DEBUG_INFO("MeterValues mapitem pass\n");
  6287. }
  6288. if((dataType != ReadingContext_Trigger) &&
  6289. (dataType != ReadingContext_Sample_Clock) &&
  6290. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  6291. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6292. else
  6293. {
  6294. if(FirstHeartBeat)
  6295. LWS_Send(queuedata +2);
  6296. }
  6297. return result;
  6298. }
  6299. int sendLogStatusNotificationRequest(char *status)
  6300. {
  6301. mtrace();
  6302. int result = PASS;
  6303. char message[4096]={0};
  6304. char guid[37]={0};
  6305. char tempdata[128]={0};
  6306. json_object *LogStatusNotification = json_object_new_object();
  6307. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6308. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  6309. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  6310. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  6311. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  6312. random_uuid(guid);
  6313. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6314. json_object_put(LogStatusNotification);
  6315. LWS_Send(message);
  6316. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6317. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6318. {
  6319. result = PASS;
  6320. }
  6321. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  6322. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  6323. return result;
  6324. }
  6325. int sendSecurityEventNotificationRequest()
  6326. {
  6327. mtrace();
  6328. int result = PASS;
  6329. char message[4096]={0};
  6330. char guid[37]={0};
  6331. char tempdata[128]={0};
  6332. json_object *SecurityEventNotification = json_object_new_object();
  6333. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6334. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  6335. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  6336. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  6337. random_uuid(guid);
  6338. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6339. json_object_put(SecurityEventNotification);
  6340. LWS_Send(message);
  6341. sprintf(tempdata, "SecurityEventNotification,0");
  6342. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6343. {
  6344. result = PASS;
  6345. }
  6346. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  6347. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  6348. return result;
  6349. }
  6350. int sendSignCertificateRequest()
  6351. {
  6352. mtrace();
  6353. int result = PASS;
  6354. char message[4096]={0};
  6355. char guid[37]={0};
  6356. char tempdata[128]={0};
  6357. json_object *SignCertificate = json_object_new_object();
  6358. DEBUG_INFO("sendSignCertificateRequest...\n");
  6359. // Read csr file content
  6360. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  6361. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  6362. char *line = NULL;
  6363. size_t len = 0;
  6364. while(getline(&line, &len, fp) != -1)
  6365. {
  6366. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6367. {
  6368. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  6369. }
  6370. }
  6371. fclose(fp);
  6372. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  6373. random_uuid(guid);
  6374. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6375. json_object_put(SignCertificate);
  6376. LWS_Send(message);
  6377. sprintf(tempdata, "SignCertificate,0");
  6378. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6379. {
  6380. result = PASS;
  6381. }
  6382. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  6383. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  6384. return result;
  6385. }
  6386. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6387. {
  6388. mtrace();
  6389. int result = PASS;
  6390. char message[110]={0};
  6391. char guid[37]={0};
  6392. char tempdata[65]={0};
  6393. json_object *FirmwareStatusNotification = json_object_new_object();
  6394. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6395. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6396. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  6397. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  6398. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  6399. random_uuid(guid);
  6400. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6401. json_object_put(FirmwareStatusNotification);
  6402. LWS_Send(message);
  6403. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6404. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6405. {
  6406. result = PASS;
  6407. }
  6408. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6409. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6410. return result;
  6411. }
  6412. //==========================================
  6413. // send confirm routine
  6414. //==========================================
  6415. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6416. {
  6417. mtrace();
  6418. int result = FAIL;
  6419. char message[100]={0};
  6420. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6421. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6422. LWS_Send(message);
  6423. result = TRUE;
  6424. return result;
  6425. }
  6426. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6427. {
  6428. mtrace();
  6429. int result = FAIL;
  6430. char message[100]={0};
  6431. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6432. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6433. LWS_Send(message);
  6434. result = TRUE;
  6435. return result;
  6436. }
  6437. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6438. {
  6439. mtrace();
  6440. int result = FAIL;
  6441. char message[100]={0};
  6442. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6443. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6444. LWS_Send(message);
  6445. result = TRUE;
  6446. return result;
  6447. }
  6448. int sendClearCacheConfirmation(char *uuid,char *payload)
  6449. {
  6450. mtrace();
  6451. int result = FAIL;
  6452. char message[500]={0};
  6453. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6454. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6455. LWS_Send(message);
  6456. return result;
  6457. }
  6458. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6459. {
  6460. mtrace();
  6461. int result = FAIL;
  6462. char message[500]={0};
  6463. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6464. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6465. LWS_Send(message);
  6466. return result;
  6467. }
  6468. int sendDataTransferConfirmation(char *uuid,char *payload)
  6469. {
  6470. mtrace();
  6471. char statusStr[20]={0};
  6472. char dataStr[10]={0};
  6473. char sstr[20]={0};
  6474. int c = 0;
  6475. char *loc;
  6476. int result = FAIL;
  6477. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6478. /**********************status**************************/
  6479. loc = strstr(payload, "status");
  6480. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6481. c = 0;
  6482. while (loc[3+strlen("status")+c] != '\"')
  6483. {
  6484. sstr[c] = loc[3+strlen("status")+c];
  6485. c++;
  6486. }
  6487. sstr[c] = '\0';
  6488. strcpy(statusStr, sstr);
  6489. /**********************data**************************/
  6490. loc = strstr(payload, "data");
  6491. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6492. c = 0;
  6493. while (loc[3+strlen("data")+c] != '\"')
  6494. {
  6495. sstr[c] = loc[3+strlen("data")+c];
  6496. c++;
  6497. }
  6498. sstr[c] = '\0';
  6499. strcpy(dataStr, sstr);
  6500. return result;
  6501. }
  6502. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6503. {
  6504. mtrace();
  6505. int result = FAIL;
  6506. char message[1000]={0};
  6507. int CompositeScheduleIndex = 0;
  6508. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6509. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6510. if(nPeriod == 0)
  6511. {
  6512. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6513. {
  6514. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6515. ,MESSAGE_TYPE_CALLRESULT
  6516. ,uuid
  6517. ,payload
  6518. ,connectorIdInt);
  6519. }
  6520. else
  6521. {
  6522. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6523. ,MESSAGE_TYPE_CALLRESULT
  6524. ,uuid
  6525. ,payload
  6526. ,connectorIdInt
  6527. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6528. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6529. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6530. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6531. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6532. }
  6533. }
  6534. else
  6535. {
  6536. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6537. ,MESSAGE_TYPE_CALLRESULT
  6538. ,uuid
  6539. ,payload
  6540. ,connectorIdInt
  6541. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6542. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6543. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6544. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  6545. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  6546. {
  6547. if (idx_sample == 0)
  6548. {
  6549. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6550. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6551. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6552. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6553. }
  6554. else
  6555. {
  6556. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6557. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6558. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6559. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6560. }
  6561. }
  6562. sprintf(message + strlen(message), "]}}]");
  6563. }
  6564. LWS_Send(message);
  6565. result = TRUE;
  6566. return result;
  6567. }
  6568. int sendGetConfigurationConfirmation(char *uuid)
  6569. {
  6570. mtrace();
  6571. int result = FAIL;
  6572. int MaxKeySupported = 0;
  6573. int sentConfigurationNumber= 0;
  6574. int sentunConfigurationNumber= 0;
  6575. char message[4000]={0};
  6576. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  6577. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  6578. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  6579. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  6580. ,MESSAGE_TYPE_CALLRESULT
  6581. ,uuid );
  6582. //configuration key
  6583. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  6584. {
  6585. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  6586. {
  6587. if (sentConfigurationNumber == 0)
  6588. {
  6589. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6590. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6591. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6592. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6593. }
  6594. else
  6595. {
  6596. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6597. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6598. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6599. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6600. }
  6601. sentConfigurationNumber = sentConfigurationNumber + 1;
  6602. }
  6603. }
  6604. sprintf(message + strlen(message), "]");
  6605. if(UnknownKeynum != 0)
  6606. {
  6607. sprintf(message + strlen(message), ",\"unknownKey\":[");
  6608. //unkown key
  6609. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  6610. {
  6611. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  6612. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  6613. if(sentunConfigurationNumber == 0)
  6614. {
  6615. sprintf(message + strlen(message), "\"%s\""
  6616. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6617. }
  6618. else
  6619. {
  6620. sprintf(message + strlen(message), ",\"%s\""
  6621. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6622. }
  6623. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  6624. }
  6625. sprintf(message + strlen(message), "]");
  6626. }
  6627. sprintf(message + strlen(message), "}]");
  6628. LWS_Send(message);
  6629. return result;
  6630. }
  6631. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  6632. {
  6633. mtrace();
  6634. int result = FAIL;
  6635. char message[400]={0};
  6636. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  6637. if(strcmp(payload,"")==0)
  6638. {
  6639. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6640. }
  6641. else
  6642. {
  6643. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6644. }
  6645. LWS_Send(message);
  6646. result = TRUE;
  6647. return result;
  6648. }
  6649. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  6650. {
  6651. mtrace();
  6652. int result = FAIL;
  6653. char message[80]={0};
  6654. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  6655. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  6656. LWS_Send(message);
  6657. result = TRUE;
  6658. return result;
  6659. }
  6660. int sendRemoteStartConfirmation(char *uuid,char *payload)
  6661. {
  6662. mtrace();
  6663. int result = FAIL;
  6664. char message[80]={0};
  6665. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  6666. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6667. LWS_Send(message);
  6668. result = TRUE;
  6669. return result;
  6670. }
  6671. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  6672. {
  6673. mtrace();
  6674. int result = FAIL;
  6675. char message[80]={0};
  6676. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  6677. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6678. LWS_Send(message);
  6679. result = TRUE;
  6680. return result;
  6681. }
  6682. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  6683. {
  6684. mtrace();
  6685. int result = FAIL;
  6686. char message[80]={0};
  6687. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  6688. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  6689. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6690. LWS_Send(message);
  6691. result = TRUE;
  6692. return result;
  6693. }
  6694. int sendResetConfirmation(char *uuid,char *payload)
  6695. {
  6696. mtrace();
  6697. int result = FAIL;
  6698. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6699. char message[80]={0};
  6700. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  6701. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6702. LWS_Send(message);
  6703. result = TRUE;
  6704. return result;
  6705. }
  6706. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6707. {
  6708. mtrace();
  6709. int result = FAIL;
  6710. char message[500]={0};
  6711. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6712. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6713. LWS_Send(message);
  6714. result = TRUE;
  6715. return result;
  6716. }
  6717. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6718. {
  6719. mtrace();
  6720. int result = FAIL;
  6721. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6722. char message[80]={0};
  6723. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6724. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6725. LWS_Send(message);
  6726. result = TRUE;
  6727. return result;
  6728. }
  6729. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6730. {
  6731. mtrace();
  6732. int result = FAIL;
  6733. char message[80]={0};
  6734. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6735. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6736. LWS_Send(message);
  6737. result = TRUE;
  6738. return result;
  6739. }
  6740. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6741. {
  6742. mtrace();
  6743. int result = FAIL;
  6744. char message[80]={0};
  6745. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6746. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6747. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6748. LWS_Send(message);
  6749. result = TRUE;
  6750. return result;
  6751. }
  6752. int sendUpdateFirmwareConfirmation(char *uuid)
  6753. {
  6754. mtrace();
  6755. int result = FAIL;
  6756. char message[60]={0};
  6757. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6758. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6759. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6760. LWS_Send(message);
  6761. result = TRUE;
  6762. return result;
  6763. }
  6764. int sendCertificateSignedConfirmation(char *uuid)
  6765. {
  6766. mtrace();
  6767. int result = PASS;
  6768. char message[4096]={0};
  6769. json_object *CertificateSigned = json_object_new_object();
  6770. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6771. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  6772. sprintf(message,"[%d,\"%s\",%s]"
  6773. ,MESSAGE_TYPE_CALLRESULT
  6774. ,uuid
  6775. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6776. json_object_put(CertificateSigned);
  6777. LWS_Send(message);
  6778. return result;
  6779. }
  6780. int sendDeleteCertificateConfirmation(char *uuid)
  6781. {
  6782. mtrace();
  6783. int result = PASS;
  6784. char message[4096]={0};
  6785. json_object *DeleteCertificate = json_object_new_object();
  6786. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6787. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  6788. sprintf(message,"[%d,\"%s\",%s]"
  6789. ,MESSAGE_TYPE_CALLRESULT
  6790. ,uuid
  6791. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6792. json_object_put(DeleteCertificate);
  6793. LWS_Send(message);
  6794. return result;
  6795. }
  6796. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6797. {
  6798. mtrace();
  6799. int result = PASS;
  6800. char message[4096]={0};
  6801. json_object *ExtendedTriggerMessage = json_object_new_object();
  6802. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6803. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  6804. sprintf(message,"[%d,\"%s\",%s]"
  6805. ,MESSAGE_TYPE_CALLRESULT
  6806. ,uuid
  6807. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6808. json_object_put(ExtendedTriggerMessage);
  6809. LWS_Send(message);
  6810. return result;
  6811. }
  6812. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6813. {
  6814. mtrace();
  6815. int result = PASS;
  6816. char message[4096]={0};
  6817. json_object *GetInstalledCertificateIds = json_object_new_object();
  6818. json_object *certificateHashDataDatas = json_object_new_array();
  6819. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6820. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  6821. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6822. {
  6823. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6824. {
  6825. json_object *certificateHashData = json_object_new_object();
  6826. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6827. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6828. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6829. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6830. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6831. }
  6832. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6833. }
  6834. else
  6835. {
  6836. json_object_put(certificateHashDataDatas);
  6837. }
  6838. sprintf(message,"[%d,\"%s\",%s]"
  6839. ,MESSAGE_TYPE_CALLRESULT
  6840. ,uuid
  6841. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6842. json_object_put(GetInstalledCertificateIds);
  6843. LWS_Send(message);
  6844. return result;
  6845. }
  6846. int sendGetLogConfirmation(char *uuid)
  6847. {
  6848. mtrace();
  6849. int result = PASS;
  6850. char message[4096]={0};
  6851. json_object *GetLog = json_object_new_object();
  6852. DEBUG_INFO("sendGetLogConfirmation...\n");
  6853. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  6854. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  6855. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  6856. sprintf(message,"[%d,\"%s\",%s]"
  6857. ,MESSAGE_TYPE_CALLRESULT
  6858. ,uuid
  6859. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6860. json_object_put(GetLog);
  6861. LWS_Send(message);
  6862. return result;
  6863. }
  6864. int sendInstallCertificateConfirmation(char *uuid)
  6865. {
  6866. mtrace();
  6867. int result = PASS;
  6868. char message[4096]={0};
  6869. json_object *InstallCertificate = json_object_new_object();
  6870. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6871. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  6872. sprintf(message,"[%d,\"%s\",%s]"
  6873. ,MESSAGE_TYPE_CALLRESULT
  6874. ,uuid
  6875. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6876. json_object_put(InstallCertificate);
  6877. LWS_Send(message);
  6878. return result;
  6879. }
  6880. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6881. {
  6882. mtrace();
  6883. int result = PASS;
  6884. char message[4096]={0};
  6885. json_object *SignedUpdateFirmware = json_object_new_object();
  6886. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6887. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  6888. sprintf(message,"[%d,\"%s\",%s]"
  6889. ,MESSAGE_TYPE_CALLRESULT
  6890. ,uuid
  6891. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6892. json_object_put(SignedUpdateFirmware);
  6893. LWS_Send(message);
  6894. return result;
  6895. }
  6896. int sendUnknownConfirmation(char *uuid)
  6897. {
  6898. mtrace();
  6899. int result = PASS;
  6900. char message[256]={0};
  6901. DEBUG_INFO("sendUnknownConfirmation...\n");
  6902. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6903. LWS_Send(message);
  6904. return result;
  6905. }
  6906. //==========================================
  6907. // Handle server request routine Start
  6908. //==========================================
  6909. int handleCancelReservationRequest(char *uuid, char *payload)
  6910. {
  6911. mtrace();
  6912. int result = FAIL;
  6913. int gunNO = 0;
  6914. int reservationIdInt = -1;
  6915. char comfirmstr[20];
  6916. DEBUG_INFO("handleCancelReservationRequest...\n");
  6917. json_object *CancelReservation;
  6918. CancelReservation = json_tokener_parse(payload);
  6919. if(!is_error(CancelReservation))
  6920. {
  6921. // Required data
  6922. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6923. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6924. }
  6925. json_object_put(CancelReservation);
  6926. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6927. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6928. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6929. if(reservationIdInt != -1)
  6930. {
  6931. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6932. //check Transaction active
  6933. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6934. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6935. {
  6936. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6937. {
  6938. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6939. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6940. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6941. {
  6942. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6943. }
  6944. else
  6945. {
  6946. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6947. }
  6948. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6949. goto end;
  6950. }
  6951. }
  6952. for (int index = 0; index < CCS_QUANTITY; index++)
  6953. {
  6954. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6955. {
  6956. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6957. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6958. if(gunType[2] == GUN_TYPE_CCS)
  6959. {
  6960. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6961. }
  6962. else
  6963. {
  6964. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6965. }
  6966. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6967. goto end;
  6968. }
  6969. }
  6970. for (int index = 0; index < GB_QUANTITY; index++)
  6971. {
  6972. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6973. {
  6974. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6975. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6976. if(gunType[2] == GUN_TYPE_GBT)
  6977. {
  6978. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6979. }
  6980. else
  6981. {
  6982. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6983. }
  6984. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6985. goto end;
  6986. }
  6987. }
  6988. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6989. {
  6990. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6991. {
  6992. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6993. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6994. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6995. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6996. goto end;
  6997. }
  6998. }
  6999. for (int index = 0; index < AC_QUANTITY; index++)
  7000. {
  7001. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7002. {
  7003. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7004. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7005. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7006. {
  7007. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7008. }
  7009. else
  7010. {
  7011. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7012. }
  7013. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7014. goto end;
  7015. }
  7016. }
  7017. }
  7018. //The reservationId does NOT match the reservationId
  7019. sendCancelReservationConfirmation(uuid, comfirmstr);
  7020. end:
  7021. // Fill in ocpp packet uuid
  7022. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7023. return result;
  7024. }
  7025. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7026. {
  7027. mtrace();
  7028. int result = FAIL;
  7029. int gunIndex = 0;
  7030. char typeStr[16]={0};
  7031. char comfirmstr[20];
  7032. int specificId = FALSE;
  7033. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7034. json_object *ChangeAvailability;
  7035. ChangeAvailability = json_tokener_parse(payload);
  7036. if(!is_error(ChangeAvailability))
  7037. {
  7038. // Required data
  7039. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  7040. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7041. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7042. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7043. }
  7044. json_object_put(ChangeAvailability);
  7045. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7046. {
  7047. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7048. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7049. }
  7050. else if(gunIndex == 0)
  7051. {
  7052. for(int i=0; i < gunTotalNumber; i++)
  7053. {
  7054. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  7055. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  7056. }
  7057. }
  7058. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7059. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7060. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  7061. {
  7062. specificId = TRUE;
  7063. }
  7064. if(specificId == FALSE)
  7065. goto end;
  7066. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7067. {
  7068. //----------------------gunIndex is 0 ------------------------------------------------//
  7069. if(gunIndex == 0)
  7070. {
  7071. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7072. {
  7073. for(int i=0; i < gunTotalNumber; i++)
  7074. {
  7075. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7076. {
  7077. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7078. {
  7079. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7080. {
  7081. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7082. goto end;
  7083. }
  7084. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7085. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7086. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7087. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7088. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7089. {
  7090. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7091. goto end;
  7092. }
  7093. }
  7094. }//END FOR CHAdeMO_QUANTITY
  7095. for (int index = 0; index < CCS_QUANTITY; index++)
  7096. {
  7097. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7098. {
  7099. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7100. {
  7101. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7102. goto end;
  7103. }
  7104. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7105. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7106. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7107. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7108. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7109. {
  7110. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7111. goto end;
  7112. }
  7113. }
  7114. }//END FOR CCS_QUANTITY
  7115. for (int index = 0; index < GB_QUANTITY; index++)
  7116. {
  7117. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7118. {
  7119. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7120. {
  7121. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7122. goto end;
  7123. }
  7124. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7125. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7126. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7127. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7128. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7129. {
  7130. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7131. goto end;
  7132. }
  7133. }
  7134. }// END FOR GB_QUANTITY
  7135. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7136. {
  7137. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7138. {
  7139. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7140. {
  7141. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7142. goto end;
  7143. }
  7144. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7145. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7146. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7147. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7148. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7149. {
  7150. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7151. goto end;
  7152. }
  7153. }
  7154. }// END FOR GENERAL_GUN_QUANTITY
  7155. for (int index = 0; index < AC_QUANTITY; index++)
  7156. {
  7157. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7158. {
  7159. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7160. {
  7161. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7162. goto end;
  7163. }
  7164. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7165. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7166. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7167. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7168. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7169. {
  7170. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7171. goto end;
  7172. }
  7173. }
  7174. }//END FOR AC_QUANTITY
  7175. }// END FOR gunTotalNumber
  7176. }
  7177. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7178. {
  7179. for(int i=0; i < gunTotalNumber; i++)
  7180. {
  7181. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7182. {
  7183. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7184. goto end;
  7185. }
  7186. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7187. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7188. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7189. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7190. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7191. {
  7192. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7193. goto end;
  7194. }
  7195. }
  7196. }
  7197. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7198. goto end;
  7199. }
  7200. //----------------------gunIndex is not 0 ------------------------------------------------//
  7201. //check Transaction active
  7202. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7203. {
  7204. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7205. {
  7206. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7207. {
  7208. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7209. goto end;
  7210. }
  7211. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7212. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7213. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7214. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7215. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7216. {
  7217. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7218. goto end;
  7219. }
  7220. else
  7221. {
  7222. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7223. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7224. goto end;
  7225. }
  7226. }
  7227. }//END FOR CHAdeMO_QUANTITY
  7228. for (int index = 0; index < CCS_QUANTITY; index++)
  7229. {
  7230. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7231. {
  7232. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7233. {
  7234. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7235. goto end;
  7236. }
  7237. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7238. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7239. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7240. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7241. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7242. {
  7243. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7244. goto end;
  7245. }
  7246. else
  7247. {
  7248. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7249. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7250. goto end;
  7251. }
  7252. }
  7253. }//END FOR CCS_QUANTITY
  7254. for (int index = 0; index < GB_QUANTITY; index++)
  7255. {
  7256. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7257. {
  7258. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7259. {
  7260. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7261. goto end;
  7262. }
  7263. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7264. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7265. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7266. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7267. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7268. {
  7269. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7270. goto end;
  7271. }
  7272. else
  7273. {
  7274. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7275. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7276. goto end;
  7277. }
  7278. }
  7279. }// END FOR GB_QUANTITY
  7280. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7281. {
  7282. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7283. {
  7284. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7285. {
  7286. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7287. goto end;
  7288. }
  7289. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7290. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7291. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7292. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7293. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7294. {
  7295. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7296. goto end;
  7297. }
  7298. else
  7299. {
  7300. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7301. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7302. goto end;
  7303. }
  7304. }
  7305. }// END FOR GENERAL_GUN_QUANTITY
  7306. for (int index = 0; index < AC_QUANTITY; index++)
  7307. {
  7308. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7309. {
  7310. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7311. {
  7312. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7313. goto end;
  7314. }
  7315. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7316. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7317. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7318. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7319. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7320. {
  7321. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7322. goto end;
  7323. }
  7324. else
  7325. {
  7326. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7327. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7328. goto end;
  7329. }
  7330. }
  7331. }//END FOR AC_QUANTITY
  7332. }//END FOR AvailabilityTypeStr[Inoperative]
  7333. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7334. {
  7335. //----------------------gunIndex is 0 ------------------------------------------------//
  7336. if(gunIndex == 0)
  7337. {
  7338. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7339. {
  7340. for(int i=0; i < gunTotalNumber; i++)
  7341. {
  7342. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7343. {
  7344. 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
  7345. {
  7346. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7347. goto end;
  7348. }
  7349. }//END FOR CHAdeMO_QUANTITY
  7350. for (int index = 0; index < CCS_QUANTITY; index++)
  7351. {
  7352. 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
  7353. {
  7354. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7355. goto end;
  7356. }
  7357. }//END FOR CCS_QUANTITY
  7358. for (int index = 0; index < GB_QUANTITY; index++)
  7359. {
  7360. 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
  7361. {
  7362. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7363. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7364. goto end;
  7365. }
  7366. }// END FOR GB_QUANTITY
  7367. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7368. {
  7369. 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
  7370. {
  7371. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7372. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7373. goto end;
  7374. }
  7375. }// END FOR GENERAL_GUN_QUANTITY
  7376. for (int index = 0; index < AC_QUANTITY; index++)
  7377. {
  7378. 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
  7379. {
  7380. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7381. goto end;
  7382. }
  7383. }//END FOR CHAdeMO_QUANTITY
  7384. }// END FOR gunTotalNumber
  7385. }
  7386. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7387. {
  7388. for(int i=0; i < gunTotalNumber; i++)
  7389. {
  7390. for (int index = 0; index < AC_QUANTITY; index++)
  7391. {
  7392. 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
  7393. {
  7394. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7395. goto end;
  7396. }
  7397. }//END FOR CHAdeMO_QUANTITY
  7398. } // END FOR gunTotalNumber
  7399. }
  7400. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7401. goto end;
  7402. }
  7403. //----------------------gunIndex is not 0 ------------------------------------------------//
  7404. //check Transaction active
  7405. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7406. {
  7407. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7408. {
  7409. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7410. goto end;
  7411. }
  7412. }//END FOR CHAdeMO_QUANTITY
  7413. for (int index = 0; index < CCS_QUANTITY; index++)
  7414. {
  7415. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7416. {
  7417. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7418. goto end;
  7419. }
  7420. }//END FOR CCS_QUANTITY
  7421. for (int index = 0; index < GB_QUANTITY; index++)
  7422. {
  7423. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7424. {
  7425. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7426. goto end;
  7427. }
  7428. }// END FOR GB_QUANTITY
  7429. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7430. {
  7431. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7432. {
  7433. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7434. goto end;
  7435. }
  7436. }// END FOR GENERAL_GUN_QUANTITY
  7437. for (int index = 0; index < AC_QUANTITY; index++)
  7438. {
  7439. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7440. {
  7441. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7442. goto end;
  7443. }
  7444. }//END FOR AC_QUANTITY
  7445. }//END FOR AvailabilityTypeStr[Operative]
  7446. end:
  7447. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7448. {
  7449. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7450. }
  7451. else
  7452. {
  7453. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7454. }
  7455. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7456. {
  7457. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7458. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7459. }
  7460. else if(gunIndex == 0)
  7461. {
  7462. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7463. {
  7464. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7465. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7466. }
  7467. }
  7468. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7469. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7470. return result;
  7471. }
  7472. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7473. {
  7474. mtrace();
  7475. int result = FAIL;
  7476. char keystr[40]={0};
  7477. char valuestr[256]={0};
  7478. char comfirmstr[20]={0};
  7479. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7480. json_object *ChangeConfiguration;
  7481. ChangeConfiguration = json_tokener_parse(payload);
  7482. if(!is_error(ChangeConfiguration))
  7483. {
  7484. // Required data
  7485. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7486. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7487. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7488. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7489. }
  7490. json_object_put(ChangeConfiguration);
  7491. if((uuid==NULL) || (payload ==NULL) )
  7492. {
  7493. DEBUG_ERROR("Payload is null\n");
  7494. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7495. }
  7496. else
  7497. {
  7498. int status = setKeyValue(keystr, valuestr);
  7499. switch(status)
  7500. {
  7501. case ConfigurationStatus_Accepted:
  7502. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7503. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  7504. StoreConfigurationTable();
  7505. break;
  7506. case RebootRequired:
  7507. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7508. StoreConfigurationTable();
  7509. break;
  7510. case NotSupported:
  7511. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7512. break;
  7513. case ConfigurationStatus_Rejected:
  7514. default:
  7515. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7516. break;
  7517. }
  7518. }
  7519. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7520. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  7521. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7522. {
  7523. ChageWebSocketPingInterval(atoi(valuestr));
  7524. }
  7525. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  7526. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7527. {
  7528. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7529. SetOcppConnStatus(FALSE);
  7530. }
  7531. return result;
  7532. }
  7533. int handleClearCacheRequest(char *uuid, char *payload)
  7534. {
  7535. mtrace();
  7536. int result = FAIL;
  7537. char comfirmstr[20];
  7538. char rmFileCmd[100]={0};
  7539. struct stat stats;
  7540. DEBUG_INFO("handleClearCacheRequest...\n");
  7541. stat("/Storage/OCPP", &stats);
  7542. // Check for directory existence
  7543. if (S_ISDIR(stats.st_mode) == 1)
  7544. {}
  7545. else
  7546. {
  7547. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  7548. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  7549. system(rmFileCmd);
  7550. }
  7551. if(OCPP_cleanLocalCache())
  7552. {
  7553. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  7554. }
  7555. else
  7556. {
  7557. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  7558. }
  7559. sendClearCacheConfirmation(uuid, comfirmstr);
  7560. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7561. return result;
  7562. }
  7563. int handleClearChargingProfileRequest(char *uuid, char *payload)
  7564. {
  7565. mtrace();
  7566. int result = FAIL;
  7567. int resultRename;
  7568. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  7569. char chargingProfilePurposeStr[26]={0};
  7570. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  7571. char tempchargingProfilePurposeStr[26]={0};
  7572. char str[100]={0};
  7573. char fname[200]={0};
  7574. char comfirmstr[20]={0};
  7575. char word[1600]={0};
  7576. int clearflag = FALSE;
  7577. int chargingProfileIdIsNULL = FALSE;
  7578. int connectorIsNULL = FALSE;
  7579. int chargingProfilePurposeIsNULL = FALSE;
  7580. int stackLevelIsNULL = FALSE;
  7581. //int GotoEnd = FALSE;
  7582. FILE *fptr1, *fptr2;
  7583. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  7584. int n_chargingProfile=0;
  7585. int isEmptyFile = FALSE;
  7586. char sLineWord[1600]={0};
  7587. char chargingProfiles[10][100]={0};
  7588. int ChargeProfileCount = 0;
  7589. int ch;
  7590. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  7591. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  7592. json_object *ClearChargingProfile;
  7593. ClearChargingProfile = json_tokener_parse(payload);
  7594. if(!is_error(ClearChargingProfile))
  7595. {
  7596. // Optional data
  7597. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  7598. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  7599. else
  7600. chargingProfileIdIsNULL = TRUE;
  7601. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  7602. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  7603. else
  7604. connectorIsNULL = TRUE;
  7605. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  7606. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  7607. else
  7608. chargingProfilePurposeIsNULL = TRUE;
  7609. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  7610. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  7611. else
  7612. stackLevelIsNULL = TRUE;
  7613. }
  7614. json_object_put(ClearChargingProfile);
  7615. if(connectorIsNULL == FALSE)
  7616. {
  7617. switch(connectorIdInt)
  7618. {
  7619. case 0:
  7620. if(chargingProfilePurposeIsNULL == TRUE)
  7621. {
  7622. int l = 0;
  7623. strcpy(fname, ChargePointMaxProfile_JSON);
  7624. if((access(fname,F_OK))!=-1)
  7625. {
  7626. strcpy(chargingProfiles[l], fname);
  7627. l = l + 1;
  7628. }
  7629. strcpy(fname, TxDefaultProfile_0_JSON);
  7630. if((access(fname,F_OK))!=-1)
  7631. {
  7632. strcpy(chargingProfiles[l], fname);
  7633. l = l + 1;
  7634. }
  7635. ChargeProfileCount = l;
  7636. }
  7637. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  7638. {
  7639. strcpy(fname, ChargePointMaxProfile_JSON);
  7640. if((access(fname,F_OK))!=-1)
  7641. {
  7642. strcpy(chargingProfiles[0], fname);
  7643. ChargeProfileCount = 1;
  7644. }
  7645. }
  7646. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7647. {
  7648. strcpy(fname, TxDefaultProfile_0_JSON);
  7649. if((access(fname,F_OK))!=-1)
  7650. {
  7651. strcpy(chargingProfiles[0], fname);
  7652. ChargeProfileCount = 1;
  7653. }
  7654. }
  7655. break;
  7656. default:
  7657. if(chargingProfilePurposeIsNULL == TRUE)
  7658. {
  7659. int m = 0;
  7660. memset(fname, 0, ARRAY_SIZE(fname));
  7661. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  7662. if((access(fname,F_OK))!=-1)
  7663. {
  7664. strcpy(chargingProfiles[m], fname);
  7665. m = m + 1;
  7666. }
  7667. memset(fname, 0, ARRAY_SIZE(fname));
  7668. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7669. if((access(fname,F_OK))!=-1)
  7670. {
  7671. strcpy(chargingProfiles[m], fname);
  7672. m = m + 1;
  7673. }
  7674. ChargeProfileCount = m;
  7675. }
  7676. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7677. {
  7678. //strcpy(fname, TxDefaultProfile_1_JSON);
  7679. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  7680. if((access(fname,F_OK))!=-1)
  7681. {
  7682. strcpy(chargingProfiles[0], fname);
  7683. ChargeProfileCount = 1;
  7684. }
  7685. }
  7686. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  7687. {
  7688. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7689. if((access(fname,F_OK))!=-1)
  7690. {
  7691. strcpy(chargingProfiles[0], fname);
  7692. ChargeProfileCount = 1;
  7693. }
  7694. //strcpy(fname, TxProfile_1_JSON);
  7695. }
  7696. //strcpy(fname, ChargePointMaxProfile_JSON );
  7697. break;
  7698. }
  7699. }
  7700. else // Check all Charging Profiles
  7701. {
  7702. int i = 0;
  7703. char fnametemp[200]={0};
  7704. ChargeProfileCount = 0;
  7705. //Check ChargePointMaxProfile.json exit
  7706. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  7707. {
  7708. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  7709. i = i + 1;
  7710. }
  7711. //Check TxDefaultProfile_0.json exit
  7712. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  7713. {
  7714. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  7715. i = i + 1;
  7716. }
  7717. //Check TxDefaultProfile_%d.json
  7718. for(int j=1; j <= gunTotalNumber; j++)
  7719. {
  7720. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7721. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  7722. if((access(fnametemp,F_OK))!=-1)
  7723. {
  7724. strcpy(chargingProfiles[i], fnametemp);
  7725. i = i + 1;
  7726. }
  7727. }
  7728. //Check TxProfile_%d.json
  7729. for(int j=1; j <= gunTotalNumber; j++)
  7730. {
  7731. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7732. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  7733. if((access(fnametemp,F_OK))!=-1)
  7734. {
  7735. strcpy(chargingProfiles[i], fnametemp);
  7736. i = i + 1;
  7737. }
  7738. }
  7739. ChargeProfileCount = i;
  7740. }// End connectorIsNULL is TRUE
  7741. if(ChargeProfileCount == 0)
  7742. {
  7743. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7744. goto end;
  7745. }
  7746. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7747. {
  7748. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7749. goto end;
  7750. }
  7751. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7752. {
  7753. memset(str, 0, ARRAY_SIZE(str));
  7754. // clear temp file
  7755. sprintf(str,"rm -f %s",temp);
  7756. system(str);
  7757. for(int k=0; k < ChargeProfileCount; k++)
  7758. {
  7759. memset(str, 0, ARRAY_SIZE(str));
  7760. //clear file in C
  7761. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7762. system(str);
  7763. }
  7764. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7765. goto end;
  7766. }
  7767. else if(connectorIsNULL == TRUE)
  7768. {
  7769. for(int k=0; k < ChargeProfileCount; k++)
  7770. {
  7771. fptr1 = fopen(chargingProfiles[k], "r");
  7772. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  7773. //Check Charging Profile Count
  7774. while(fscanf(fptr1, "%s", word) != EOF)
  7775. {
  7776. //DEBUG_INFO("word=%s\n",word);
  7777. if(strstr(word, "chargingProfileId")!= NULL)
  7778. {
  7779. //DEBUG_INFO("test chargingProfileId \n");
  7780. n_chargingProfile = n_chargingProfile + 1;
  7781. //DEBUG_INFO("chargingProfileId Found\n");
  7782. }
  7783. }
  7784. rewind(fptr1);
  7785. //search Charging Profile Element
  7786. //int i= 0;
  7787. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7788. {
  7789. json_object *tmpProfilee;
  7790. tmpProfilee = json_tokener_parse(sLineWord);
  7791. if(!is_error(tmpProfilee))
  7792. {
  7793. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7794. {
  7795. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7796. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7797. }
  7798. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7799. {
  7800. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7801. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7802. }
  7803. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7804. {
  7805. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7806. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7807. }
  7808. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7809. {
  7810. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7811. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7812. }
  7813. }
  7814. json_object_put(tmpProfilee);
  7815. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7816. {
  7817. //------- not write to fptr2-------//
  7818. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7819. //clearflag = TRUE;
  7820. }
  7821. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7822. {
  7823. //------- not write to fptr2-------//
  7824. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7825. }
  7826. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7827. {
  7828. //------- not write to fptr2-------//
  7829. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7830. }
  7831. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7832. {
  7833. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7834. }
  7835. else
  7836. {
  7837. fprintf(fptr2, sLineWord);//writing data into file
  7838. }
  7839. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7840. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7841. if(clearflag == TRUE)
  7842. {
  7843. fclose(fptr1);
  7844. fclose(fptr2);
  7845. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7846. system(str);
  7847. // clear temp file
  7848. sprintf(str,"rm -f %s",temp);
  7849. system(str);
  7850. }
  7851. else
  7852. {
  7853. fclose(fptr1);
  7854. fclose(fptr2);
  7855. memset(str, 0, ARRAY_SIZE(str));
  7856. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7857. system(str);
  7858. resultRename = rename(temp, chargingProfiles[k]);
  7859. if(resultRename == 0)
  7860. {
  7861. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7862. }
  7863. else
  7864. {
  7865. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7866. }
  7867. if(comfirmstr[0]== 0)
  7868. {
  7869. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7870. }
  7871. //Check chargingProfile is empty file
  7872. /*------ Read the file ----------------*/
  7873. fptr1=fopen(chargingProfiles[k],"r");
  7874. ch=fgetc(fptr1);
  7875. rewind(fptr1);
  7876. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7877. if(ch!=EOF)
  7878. {
  7879. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7880. {
  7881. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7882. if(sLineWord[0]=='\0')
  7883. {
  7884. isEmptyFile = TRUE;
  7885. break;
  7886. }
  7887. else
  7888. {
  7889. isEmptyFile = FALSE;
  7890. break;
  7891. }
  7892. }
  7893. }
  7894. else
  7895. isEmptyFile = TRUE;
  7896. fclose(fptr1);
  7897. if(isEmptyFile == TRUE)
  7898. {
  7899. memset(str, 0, ARRAY_SIZE(str));
  7900. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7901. system(str);
  7902. }
  7903. }
  7904. }// End of while(int k=0; k < ChargePointCount; k++)
  7905. }
  7906. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7907. {
  7908. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7909. for(int k=0; k < ChargeProfileCount; k++)
  7910. {
  7911. fptr1 = fopen(chargingProfiles[k], "r");
  7912. fptr2 = fopen(temp, "w+");
  7913. //Check Charging Profile Count
  7914. while(fscanf(fptr1, "%s", word) != EOF)
  7915. {
  7916. //DEBUG_INFO("word=%s\n",word);
  7917. if(strstr(word, "chargingProfileId")!= NULL)
  7918. {
  7919. n_chargingProfile = n_chargingProfile + 1;
  7920. }
  7921. }
  7922. rewind(fptr1);
  7923. //search Charging Profile Element
  7924. //int i= 0;
  7925. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7926. {
  7927. json_object *tmpProfilee;
  7928. tmpProfilee = json_tokener_parse(sLineWord);
  7929. if(!is_error(tmpProfilee))
  7930. {
  7931. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7932. {
  7933. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7934. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7935. }
  7936. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7937. {
  7938. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7939. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7940. }
  7941. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7942. {
  7943. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7944. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7945. }
  7946. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7947. {
  7948. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7949. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7950. }
  7951. }
  7952. json_object_put(tmpProfilee);
  7953. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7954. {
  7955. //------- not write to fptr2-------//
  7956. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7957. //clearflag = TRUE;
  7958. }
  7959. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7960. {
  7961. //------- not write to fptr2-------//
  7962. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7963. }
  7964. else if(stackLevelIsNULL == TRUE)
  7965. {
  7966. //Clear Whole File
  7967. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7968. clearflag = TRUE;
  7969. break;
  7970. }
  7971. else
  7972. {
  7973. fprintf(fptr2, sLineWord);//writing data into file
  7974. }
  7975. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7976. }
  7977. if(clearflag == TRUE)
  7978. {
  7979. fclose(fptr1);
  7980. fclose(fptr2);
  7981. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7982. system(str);
  7983. // clear temp file
  7984. sprintf(str,"rm -f %s",temp);
  7985. system(str);
  7986. }
  7987. else
  7988. {
  7989. fclose(fptr1);
  7990. fclose(fptr2);
  7991. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7992. system(str);
  7993. resultRename = rename(temp, chargingProfiles[k]);
  7994. if(resultRename == 0)
  7995. {
  7996. DEBUG_INFO("File ChargingProfile renamed successfully");
  7997. }
  7998. else
  7999. {
  8000. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8001. }
  8002. if(comfirmstr[0]== 0)
  8003. {
  8004. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8005. }
  8006. //Check chargingProfile is empty file
  8007. /*------ Read the file ----------------*/
  8008. fptr1=fopen(chargingProfiles[k],"r");
  8009. ch=fgetc(fptr1);
  8010. rewind(fptr1);
  8011. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8012. if(ch!=EOF)
  8013. {
  8014. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8015. {
  8016. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8017. if(sLineWord[0]=='\0')
  8018. {
  8019. isEmptyFile = TRUE;
  8020. break;
  8021. }
  8022. else
  8023. {
  8024. isEmptyFile = FALSE;
  8025. break;
  8026. }
  8027. }
  8028. }
  8029. else
  8030. isEmptyFile = TRUE;
  8031. fclose(fptr1);
  8032. if(isEmptyFile == TRUE)
  8033. {
  8034. memset(str, 0, ARRAY_SIZE(str));
  8035. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8036. system(str);
  8037. }
  8038. /*------- End of reading ---------------*/
  8039. }
  8040. } // while(int k=0; k < ChargeProfileCount; k++)
  8041. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8042. end:
  8043. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8044. {
  8045. if(connectorIdInt == 0)
  8046. {
  8047. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8048. {
  8049. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  8050. }
  8051. }
  8052. else
  8053. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  8054. }
  8055. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8056. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8057. return result;
  8058. }
  8059. void createFirmwareVersionByDataTransfer(void)
  8060. {
  8061. json_object *FirmwareDataTransfer = json_object_new_object();
  8062. // AC & DC model
  8063. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8064. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8065. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8066. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8067. // DC model
  8068. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8069. {
  8070. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8071. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8072. (gunType[3] != GUN_TYPE_UNKNOWN))
  8073. {
  8074. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8075. }
  8076. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8077. {
  8078. // DS DM DW
  8079. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8080. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8081. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8082. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8083. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8084. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8085. }
  8086. else
  8087. {
  8088. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8089. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8090. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8091. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8092. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8093. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8094. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8095. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8096. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8097. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8098. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8099. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8100. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8101. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8102. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8103. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8104. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8105. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8106. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8107. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8108. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8109. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8110. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8111. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8112. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8113. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8114. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8115. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8116. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8117. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8118. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8119. }
  8120. }
  8121. // 4G model
  8122. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8123. {
  8124. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8125. }
  8126. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8127. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  8128. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8129. json_object_put(FirmwareDataTransfer);
  8130. }
  8131. int handleDataTransferRequest(char *uuid, char *payload)
  8132. {
  8133. mtrace();
  8134. json_object *response = json_object_new_object();
  8135. int result = FAIL;
  8136. char tempvendorId[255]={0};
  8137. char tempmessageId[50]={0};
  8138. char tempdata[512]={0};
  8139. char message[2048]={0};
  8140. DEBUG_INFO("handleDataTransferRequest...\n");
  8141. if((uuid != NULL) && (payload != NULL))
  8142. {
  8143. json_object *DataTransfer;
  8144. DataTransfer = json_tokener_parse(payload);
  8145. if(!is_error(DataTransfer))
  8146. {
  8147. // Required data
  8148. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8149. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8150. // Optional data
  8151. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8152. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8153. if(json_object_object_get(DataTransfer, "data") != NULL)
  8154. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8155. result = PASS;
  8156. }
  8157. json_object_put(DataTransfer);
  8158. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8159. {
  8160. // Send all moudle firmware version on EVSE
  8161. createFirmwareVersionByDataTransfer();
  8162. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8163. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  8164. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8165. json_object_put(response);
  8166. }
  8167. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8168. {
  8169. system("/usr/bin/run_tmate_restart.sh &");
  8170. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8171. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8172. json_object_put(response);
  8173. }
  8174. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8175. {
  8176. json_object *data;
  8177. data = json_tokener_parse(tempdata);
  8178. if(!is_error(data))
  8179. {
  8180. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8181. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8182. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8183. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8184. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8185. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8186. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8187. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8188. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8189. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8190. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8191. }
  8192. else
  8193. {
  8194. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8195. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8196. }
  8197. json_object_put(data);
  8198. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8199. json_object_put(response);
  8200. }
  8201. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8202. {
  8203. json_object *data;
  8204. data = json_tokener_parse(tempdata);
  8205. if(!is_error(data))
  8206. {
  8207. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8208. if(json_object_object_get(data, "idToken") != NULL)
  8209. {
  8210. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8211. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8212. }
  8213. if(json_object_object_get(data, "price") != NULL)
  8214. {
  8215. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8216. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8217. }
  8218. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8219. }
  8220. else
  8221. {
  8222. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8223. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8224. }
  8225. json_object_put(data);
  8226. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8227. json_object_put(response);
  8228. }
  8229. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8230. {
  8231. json_object *data;
  8232. data = json_tokener_parse(tempdata);
  8233. if(!is_error(data))
  8234. {
  8235. if(json_object_object_get(data, "txId") != NULL)
  8236. {
  8237. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8238. for(int idx = 0;idx<gunTotalNumber;idx++)
  8239. {
  8240. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8241. {
  8242. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8243. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8244. if(json_object_object_get(data, "description") != NULL)
  8245. {
  8246. // California pricing V1.0
  8247. DEBUG_INFO("California pricing V1.0\n");
  8248. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8249. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8250. }
  8251. else
  8252. {
  8253. // California pricing V1.1
  8254. DEBUG_INFO("California pricing V1.1\n");
  8255. if(json_object_object_get(data, "timestamp") != NULL)
  8256. {
  8257. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8258. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8259. }
  8260. if(json_object_object_get(data, "meterValue") != NULL)
  8261. {
  8262. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8263. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8264. }
  8265. if(json_object_object_get(data, "cost") != NULL)
  8266. {
  8267. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8268. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8269. }
  8270. if(json_object_object_get(data, "state") != NULL)
  8271. {
  8272. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8273. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8274. }
  8275. if(json_object_object_get(data, "chargingPrice") != NULL)
  8276. {
  8277. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8278. {
  8279. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8280. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8281. }
  8282. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8283. {
  8284. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8285. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8286. }
  8287. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8288. {
  8289. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8290. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8291. }
  8292. }
  8293. if(json_object_object_get(data, "idlePrice") != NULL)
  8294. {
  8295. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8296. {
  8297. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8298. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8299. }
  8300. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8301. {
  8302. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8303. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8304. }
  8305. }
  8306. if(json_object_object_get(data, "nextPeriod") != NULL)
  8307. {
  8308. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8309. {
  8310. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8311. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8312. }
  8313. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8314. {
  8315. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8316. {
  8317. 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")));
  8318. 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"));
  8319. }
  8320. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8321. {
  8322. 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")));
  8323. 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"));
  8324. }
  8325. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8326. {
  8327. 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")));
  8328. 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"));
  8329. }
  8330. }
  8331. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8332. {
  8333. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8334. {
  8335. 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")));
  8336. 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"));
  8337. }
  8338. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8339. {
  8340. 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")));
  8341. 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"));
  8342. }
  8343. }
  8344. }
  8345. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8346. {
  8347. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8348. {
  8349. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8350. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8351. }
  8352. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8353. {
  8354. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8355. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8356. }
  8357. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8358. {
  8359. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8360. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8361. }
  8362. }
  8363. }
  8364. }
  8365. }
  8366. }
  8367. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8368. }
  8369. else
  8370. {
  8371. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8372. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8373. }
  8374. json_object_put(data);
  8375. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8376. json_object_put(response);
  8377. }
  8378. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8379. {
  8380. json_object *data;
  8381. data = json_tokener_parse(tempdata);
  8382. if(!is_error(data))
  8383. {
  8384. if(json_object_object_get(data, "txId") != NULL)
  8385. {
  8386. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8387. for(int idx = 0;idx<gunTotalNumber;idx++)
  8388. {
  8389. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8390. {
  8391. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8392. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8393. if(json_object_object_get(data, "description") != NULL)
  8394. {
  8395. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8396. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8397. }
  8398. }
  8399. }
  8400. }
  8401. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8402. }
  8403. else
  8404. {
  8405. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8406. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8407. }
  8408. json_object_put(data);
  8409. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8410. json_object_put(response);
  8411. }
  8412. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8413. {
  8414. json_object *data;
  8415. data = json_tokener_parse(tempdata);
  8416. if(!is_error(data))
  8417. {
  8418. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8419. if(json_object_object_get(data, "Content_Type") != NULL)
  8420. {
  8421. 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))
  8422. {
  8423. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8424. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8425. {
  8426. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8427. }
  8428. }
  8429. else
  8430. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8431. }
  8432. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8433. }
  8434. else
  8435. {
  8436. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8437. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8438. }
  8439. json_object_put(data);
  8440. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8441. json_object_put(response);
  8442. }
  8443. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8444. {
  8445. json_object *data;
  8446. data = json_tokener_parse(tempdata);
  8447. if(!is_error(data))
  8448. {
  8449. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8450. if(json_object_object_get(data, "Page_Index") != NULL)
  8451. {
  8452. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8453. }
  8454. if(json_object_object_get(data, "Duration") != NULL)
  8455. {
  8456. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8457. }
  8458. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8459. }
  8460. else
  8461. {
  8462. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8463. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8464. }
  8465. json_object_put(data);
  8466. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8467. json_object_put(response);
  8468. }
  8469. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8470. {
  8471. json_object *data;
  8472. data = json_tokener_parse(tempdata);
  8473. if(!is_error(data))
  8474. {
  8475. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8476. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8477. {
  8478. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8479. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8480. else
  8481. {
  8482. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8483. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8484. }
  8485. }
  8486. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8487. {
  8488. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8489. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8490. else
  8491. {
  8492. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8493. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8494. }
  8495. }
  8496. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  8497. {
  8498. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  8499. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  8500. else
  8501. {
  8502. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8503. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8504. }
  8505. }
  8506. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  8507. {
  8508. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  8509. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  8510. else
  8511. {
  8512. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8513. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8514. }
  8515. }
  8516. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  8517. {
  8518. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  8519. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  8520. else
  8521. {
  8522. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8523. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8524. }
  8525. }
  8526. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  8527. {
  8528. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  8529. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  8530. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  8531. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  8532. else
  8533. {
  8534. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8535. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8536. }
  8537. }
  8538. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  8539. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8540. }
  8541. else
  8542. {
  8543. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8544. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8545. }
  8546. json_object_put(data);
  8547. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8548. json_object_put(response);
  8549. }
  8550. else
  8551. {
  8552. // Can not find valid message id
  8553. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  8554. }
  8555. }
  8556. else
  8557. {
  8558. // Payload is null
  8559. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  8560. }
  8561. LWS_Send(message);
  8562. return result;
  8563. }
  8564. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  8565. {
  8566. mtrace();
  8567. int result = FAIL;
  8568. int connectorIdInt, durationInt;
  8569. char chargingRateUnitStr[4]={0};
  8570. char comfirmstr[20];
  8571. int confirmPeriods = 0;
  8572. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  8573. json_object *GetCompositeSchedule;
  8574. GetCompositeSchedule = json_tokener_parse(payload);
  8575. if(!is_error(GetCompositeSchedule))
  8576. {
  8577. // Required data
  8578. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  8579. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  8580. else
  8581. connectorIdInt = -1;
  8582. if(json_object_object_get(GetCompositeSchedule, "duration"))
  8583. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  8584. else
  8585. durationInt = 86400;
  8586. // Optional data
  8587. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  8588. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  8589. }
  8590. json_object_put(GetCompositeSchedule);
  8591. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  8592. if((connectorIdInt == 0) ||
  8593. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  8594. {
  8595. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  8596. struct StructChargingProfile tmpProfile[1];
  8597. if(strstr(chargingRateUnitStr, "W") != NULL)
  8598. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  8599. else
  8600. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  8601. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8602. {
  8603. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8604. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8605. }
  8606. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  8607. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  8608. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  8609. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8610. {
  8611. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8612. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8613. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  8614. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  8615. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  8616. {
  8617. confirmPeriods = idx;
  8618. break;
  8619. }
  8620. }
  8621. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  8622. {
  8623. confirmPeriods += 1;
  8624. }
  8625. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  8626. }
  8627. else
  8628. {
  8629. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  8630. }
  8631. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  8632. return result;
  8633. }
  8634. int handleGetConfigurationRequest(char *uuid, char *payload)
  8635. {
  8636. mtrace();
  8637. int result = FAIL;
  8638. int MaxKeySupported = 0;
  8639. int n_keys = 0;
  8640. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  8641. DEBUG_INFO("handleGetConfigurationRequest...\n");
  8642. json_object *GetConfiguration;
  8643. GetConfiguration = json_tokener_parse(payload);
  8644. if(!is_error(GetConfiguration))
  8645. {
  8646. // Optional data
  8647. if(json_object_object_get(GetConfiguration, "key") != NULL)
  8648. {
  8649. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  8650. {
  8651. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  8652. n_keys = idx + 1;
  8653. }
  8654. }
  8655. }
  8656. json_object_put(GetConfiguration);
  8657. UnknownKeynum = 0;
  8658. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  8659. MaxKeySupported = GetConfigurationMaxKeysNUM;
  8660. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  8661. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  8662. if(n_keys != 0)
  8663. {
  8664. for(int i=0;i<n_keys;i++)
  8665. {
  8666. getKeyValue(requestKey[i]);
  8667. }
  8668. }
  8669. else
  8670. {
  8671. DEBUG_INFO("There is no key in Message, get all configuration\n");
  8672. getKeyValue("");
  8673. }
  8674. processUnkownKey();
  8675. sendGetConfigurationConfirmation(uuid);
  8676. return result;
  8677. }
  8678. static char fnamePlusPath[100]={0};
  8679. static char fnamePWithNoPath[60]={0};
  8680. void checkUploadLog(void)
  8681. {
  8682. FILE *fp;
  8683. /* Open the command for reading. */
  8684. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  8685. if (fp == NULL) {
  8686. DEBUG_WARN("Failed to run command\n" );
  8687. exit(1);
  8688. }
  8689. int ftppathlen = 0;
  8690. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  8691. int i = 0;
  8692. /* Read the output a line at a time - output it. */
  8693. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  8694. if(i==0)
  8695. {
  8696. ftppathlen = strlen(fnamePlusPath);
  8697. DEBUG_INFO("%s\n", fnamePlusPath);
  8698. fnamePlusPath[ftppathlen]='\0';
  8699. break;
  8700. }
  8701. i= i+1;
  8702. }
  8703. /* close */
  8704. pclose(fp);
  8705. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  8706. {
  8707. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  8708. {
  8709. fnamePlusPath[k]='\0';
  8710. }
  8711. }
  8712. i=1;
  8713. //char fname[60]={0};
  8714. while(i < ftppathlen)
  8715. {
  8716. int len=ftppathlen-i;
  8717. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  8718. {
  8719. DEBUG_INFO("compare '/' all right\n");
  8720. break;
  8721. }
  8722. i=i+1;
  8723. }
  8724. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  8725. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  8726. fnamePWithNoPath[i+1] = '\0';
  8727. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  8728. {
  8729. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  8730. {
  8731. fnamePWithNoPath[j]='\0';
  8732. }
  8733. }
  8734. FILE* fp1 = fopen(fnamePlusPath, "r");
  8735. if (fp1)
  8736. {
  8737. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  8738. // file exists
  8739. fclose(fp1);
  8740. }
  8741. else
  8742. {
  8743. // file doesn't exist
  8744. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  8745. }
  8746. }
  8747. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  8748. {
  8749. mtrace();
  8750. int result = FAIL;
  8751. time_t CurrentTime;
  8752. struct tm *tm;
  8753. pthread_t th_Status;
  8754. CurrentTime = time(NULL);
  8755. tm = localtime(&CurrentTime);
  8756. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  8757. 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);
  8758. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  8759. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  8760. return result;
  8761. }
  8762. void* GetDiagnosticsProcess(void* data)
  8763. {
  8764. pthread_detach(pthread_self());
  8765. mtrace();
  8766. int retriesInt=0, retryIntervalInt=0;
  8767. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  8768. 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};
  8769. int port=0;
  8770. int isSuccess = FALSE;
  8771. char cmdBuf[2048];
  8772. struct tm *tmNow;
  8773. time_t CurrentTime;
  8774. struct tm tmStart;
  8775. struct tm tmStop;
  8776. CurrentTime = time(NULL);
  8777. tmNow=localtime(&CurrentTime);
  8778. uint16_t targetYear, targetMonth;
  8779. json_object *GetDiagnostics;
  8780. DEBUG_INFO("GetDiagnosticsProcess...\n");
  8781. GetDiagnostics = json_tokener_parse(data);
  8782. if(!is_error(GetDiagnostics))
  8783. {
  8784. // Required data
  8785. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  8786. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  8787. // Optional data
  8788. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  8789. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  8790. else
  8791. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  8792. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  8793. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  8794. else
  8795. retryIntervalInt = 30;
  8796. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  8797. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  8798. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  8799. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  8800. }
  8801. json_object_put(GetDiagnostics);
  8802. // Pack log to compress file
  8803. 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) &&
  8804. (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))
  8805. {
  8806. // Pack system log
  8807. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8808. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  8809. targetYear = tmStart.tm_year;
  8810. targetMonth = tmStart.tm_mon;
  8811. do
  8812. {
  8813. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8814. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  8815. if(targetMonth+1>=13)
  8816. {
  8817. targetYear += 1;
  8818. targetMonth = 1;
  8819. }
  8820. else
  8821. {
  8822. targetMonth += 1;
  8823. }
  8824. }while((targetYear < (tmNow->tm_year+1900)) ||
  8825. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8826. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  8827. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  8828. system(cmdBuf);
  8829. // Pack charging & event log
  8830. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8831. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  8832. targetYear = tmStart.tm_year;
  8833. targetMonth = tmStart.tm_mon;
  8834. do
  8835. {
  8836. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8837. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  8838. if(targetMonth+1>=13)
  8839. {
  8840. targetYear += 1;
  8841. targetMonth = 1;
  8842. }
  8843. else
  8844. {
  8845. targetMonth += 1;
  8846. }
  8847. }while((targetYear < (tmNow->tm_year+1900)) ||
  8848. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8849. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  8850. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  8851. system(cmdBuf);
  8852. // Combine log file
  8853. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  8854. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  8855. }
  8856. else
  8857. {
  8858. system("exec /root/logPackTools 'log' 6");
  8859. }
  8860. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  8861. system(cmdBuf);
  8862. checkUploadLog();
  8863. //****************location*******************/
  8864. if(strcmp(locationstr,"")==0)
  8865. {
  8866. DEBUG_INFO("location is <Empty>!\n");
  8867. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8868. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8869. goto end;
  8870. }
  8871. memset(protocol, 0, ARRAY_SIZE(protocol));
  8872. memset(user, 0, ARRAY_SIZE(user) );
  8873. memset(password, 0, ARRAY_SIZE(password));
  8874. memset(host, 0, ARRAY_SIZE(host));
  8875. memset(path, 0, ARRAY_SIZE(path));
  8876. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  8877. memset(host1, 0, ARRAY_SIZE(host1));
  8878. memset(path1, 0, ARRAY_SIZE(path1));
  8879. /*location: ftp://user:password@host:port/path*/
  8880. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  8881. if((access(fnamePlusPath,F_OK))!=-1)
  8882. {
  8883. DEBUG_INFO("fnamePlusPath exist.\n");
  8884. }
  8885. else
  8886. {
  8887. DEBUG_INFO("fnamePlusPath not exist!\n");
  8888. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8889. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8890. goto end;
  8891. }
  8892. if(strchr(locationstr,'@')==NULL)
  8893. {
  8894. sscanf(locationstr,
  8895. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8896. protocol, host, &port, path);
  8897. strcpy(user,"anonymous");
  8898. strcpy(password,"");
  8899. }
  8900. else
  8901. {
  8902. //DEBUG_INFO("pch=%s\n", pch);
  8903. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8904. protocol, user, password, host, &port, path);
  8905. }
  8906. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  8907. {
  8908. DEBUG_INFO("protocol is not ftp/http ! \n");
  8909. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8910. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8911. goto end;
  8912. }
  8913. if(strncmp(locationstr,"http", 4) == 0)
  8914. {
  8915. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  8916. sprintf(ftppath,"/%s", path);
  8917. do
  8918. {
  8919. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8920. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8921. sleep(3);
  8922. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  8923. if(!isSuccess)
  8924. {
  8925. DEBUG_INFO("Diagnostics fail.\n");
  8926. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8927. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8928. sleep(retryIntervalInt);
  8929. }
  8930. else
  8931. {
  8932. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8933. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8934. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8935. }
  8936. retriesInt--;
  8937. }while((isSuccess == 0)&&(retriesInt >= 0));
  8938. }
  8939. else
  8940. {
  8941. sscanf(host,"%[^/]%s",host1, path1);
  8942. if(strlen(path) > 0)
  8943. sprintf(ftppath,"/%s", path);
  8944. else
  8945. sprintf(ftppath,"/%s", path1);
  8946. int ftppathlen=strlen(ftppath);
  8947. int i=1;
  8948. char filenametemp[50];
  8949. while(i < ftppathlen)
  8950. {
  8951. int len=ftppathlen-i;
  8952. if(ftppath[len]== 47) // '/' ascll code: 47
  8953. {
  8954. DEBUG_INFO("find '/' all right\n");
  8955. break;
  8956. }
  8957. i=i+1;
  8958. }
  8959. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  8960. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8961. filenametemp[i+1] = 0;
  8962. if(port == 0)
  8963. port = 21;
  8964. do
  8965. {
  8966. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8967. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8968. sleep(3);
  8969. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  8970. if(!isSuccess)
  8971. {
  8972. DEBUG_INFO("Diagnostics fail.\n");
  8973. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8974. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8975. sleep(retryIntervalInt);
  8976. }
  8977. else
  8978. {
  8979. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8980. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8981. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8982. }
  8983. retriesInt--;
  8984. }while((!isSuccess)&&(retriesInt >= 0));
  8985. }
  8986. end:
  8987. system("rm -f /mnt/*");
  8988. sleep(5);
  8989. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8990. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8991. pthread_exit(NULL);
  8992. }
  8993. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  8994. {
  8995. mtrace();
  8996. int result = FAIL;
  8997. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  8998. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  8999. {
  9000. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9001. locallistVersion = -1;
  9002. }
  9003. else
  9004. {
  9005. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9006. OCPP_getListVerion();
  9007. }
  9008. //from db.OCPP_getListVerion
  9009. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9010. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  9011. sendGetLocalListVersionConfirmation(uuid,"");
  9012. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  9013. return result;
  9014. }
  9015. int handleRemoteStartRequest(char *uuid, char *payload)
  9016. {
  9017. mtrace();
  9018. int result = FAIL;
  9019. int connectorIdInt=-1;
  9020. int tempIndex = 0;
  9021. int connectorIdIsNULL, chargingProfileIsNULL;
  9022. char comfirmstr[20]={0};
  9023. char cmdBuf[512];
  9024. json_object *RemoteStartTransaction;
  9025. FILE *fp;
  9026. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9027. if(server_pending == TRUE)
  9028. {
  9029. return 0;
  9030. }
  9031. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9032. RemoteStartTransaction = json_tokener_parse(payload);
  9033. if(!is_error(RemoteStartTransaction))
  9034. {
  9035. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9036. {
  9037. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9038. }
  9039. else
  9040. {
  9041. connectorIdIsNULL = TRUE;
  9042. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9043. {
  9044. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9045. {
  9046. connectorIdIsNULL = FALSE;
  9047. connectorIdInt = (gun_index+1);
  9048. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9049. break;
  9050. }
  9051. }
  9052. }
  9053. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9054. {
  9055. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9056. // Required data
  9057. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9058. // Optional data
  9059. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9060. {
  9061. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9062. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9063. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9064. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9065. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9066. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9067. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9068. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9069. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9070. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9071. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9072. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9073. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9074. {
  9075. 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")));
  9076. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9077. 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"));
  9078. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9079. 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"));
  9080. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9081. 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")));
  9082. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9083. {
  9084. 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++)
  9085. {
  9086. 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"));
  9087. 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"));
  9088. 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)
  9089. 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"));
  9090. }
  9091. }
  9092. }
  9093. }
  9094. else
  9095. {
  9096. chargingProfileIsNULL = TRUE;
  9097. }
  9098. }
  9099. }
  9100. else
  9101. {
  9102. connectorIdIsNULL = TRUE;
  9103. }
  9104. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9105. {
  9106. DEBUG_WARN("Connector id is NULL\n.");
  9107. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9108. goto end;
  9109. }
  9110. /*
  9111. enum _SYSTEM_STATUS
  9112. {
  9113. S_BOOTING = 0,
  9114. S_IDLE, = 1
  9115. S_AUTHORIZING, = 2
  9116. S_REASSIGN_CHECK, = 3
  9117. S_REASSIGN, = 4
  9118. S_PRECHARGE, = 5
  9119. S_PREPARING_FOR_EV, = 6
  9120. S_PREPARING_FOR_EVSE, = 7
  9121. S_CHARGING, = 8
  9122. S_TERMINATING, = 9
  9123. S_COMPLETE, = 10
  9124. S_ALARM, = 11
  9125. S_FAULT = 12
  9126. }
  9127. */
  9128. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9129. {
  9130. //check Transaction active
  9131. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9132. {
  9133. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9134. {
  9135. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9136. }
  9137. else
  9138. {
  9139. tempIndex = connectorIdInt -1;
  9140. }
  9141. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9142. {
  9143. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9144. {
  9145. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9146. {
  9147. //Reserved
  9148. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9149. }
  9150. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9151. {
  9152. //Reserved
  9153. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9154. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9155. goto end;
  9156. }
  9157. else
  9158. {
  9159. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9160. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9161. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9162. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9163. {
  9164. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9165. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9166. goto end;
  9167. }
  9168. }//END FOR ELSE
  9169. }
  9170. }// END FOR CHAdeMO_QUANTITY
  9171. }
  9172. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9173. {
  9174. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9175. {
  9176. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9177. }
  9178. else
  9179. {
  9180. tempIndex = connectorIdInt -1;
  9181. }
  9182. for (int index = 0; index < CCS_QUANTITY; index++)
  9183. {
  9184. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9185. {
  9186. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9187. {
  9188. //Reserved
  9189. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9190. }
  9191. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9192. {
  9193. //Reserved
  9194. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9195. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9196. goto end;
  9197. }
  9198. else
  9199. {
  9200. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9201. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9202. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9203. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9204. {
  9205. DEBUG_WARN("CCS connector not allow start\n.");
  9206. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9207. goto end;
  9208. }
  9209. }// END FOR ELSE
  9210. }
  9211. }// END FOR CCS_QUANTITY
  9212. }
  9213. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9214. {
  9215. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9216. {
  9217. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9218. }
  9219. else
  9220. {
  9221. tempIndex = connectorIdInt -1;
  9222. }
  9223. for (int index = 0; index < GB_QUANTITY; index++)
  9224. {
  9225. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9226. {
  9227. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9228. {
  9229. //Reserved
  9230. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9231. }
  9232. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9233. {
  9234. //Reserved
  9235. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9236. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9237. goto end;
  9238. }
  9239. else
  9240. {
  9241. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9242. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9243. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9244. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9245. {
  9246. DEBUG_WARN("GB connector not allow start\n.");
  9247. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9248. goto end;
  9249. }
  9250. }// END FOR ELSE
  9251. }
  9252. } // END FOR GB_QUANTITY
  9253. }
  9254. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9255. {
  9256. tempIndex = connectorIdInt -1;
  9257. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9258. {
  9259. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9260. {
  9261. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9262. {
  9263. //Reserved
  9264. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9265. }
  9266. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9267. {
  9268. //Reserved
  9269. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9270. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9271. goto end;
  9272. }
  9273. else
  9274. {
  9275. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9276. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9277. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9278. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9279. {
  9280. DEBUG_WARN("GB connector not allow start\n.");
  9281. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9282. goto end;
  9283. }
  9284. }// END FOR ELSE
  9285. }
  9286. } // END FOR GB_QUANTITY
  9287. }
  9288. else
  9289. {
  9290. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9291. {
  9292. tempIndex = 2;
  9293. }
  9294. else
  9295. {
  9296. tempIndex = connectorIdInt -1;
  9297. }
  9298. for (int index = 0; index < AC_QUANTITY; index++)
  9299. {
  9300. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9301. {
  9302. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9303. {
  9304. //Reserved
  9305. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9306. }
  9307. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9308. {
  9309. //Reserved
  9310. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9311. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9312. goto end;
  9313. }
  9314. else
  9315. {
  9316. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9317. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9318. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9319. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9320. {
  9321. DEBUG_WARN("AC connector not allow start\n.");
  9322. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9323. goto end;
  9324. }
  9325. }//END FOR ELSE
  9326. }
  9327. }// END FOR AC_QUANTITY
  9328. }
  9329. if(chargingProfileIsNULL == FALSE)
  9330. {
  9331. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9332. {
  9333. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9334. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9335. //memset idTag
  9336. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9337. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9338. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9339. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9340. // Save profile to file
  9341. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9342. system(cmdBuf);
  9343. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9344. fp = fopen(cmdBuf, "w");
  9345. 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));
  9346. fclose(fp);
  9347. }
  9348. else
  9349. {
  9350. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9351. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9352. }
  9353. }
  9354. else
  9355. {
  9356. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9357. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9358. //memset idTag
  9359. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9360. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9361. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9362. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9363. }
  9364. }
  9365. else
  9366. {
  9367. DEBUG_WARN("Connector id over\n.");
  9368. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9369. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9370. }
  9371. end:
  9372. json_object_put(RemoteStartTransaction);
  9373. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9374. {
  9375. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9376. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9377. }
  9378. //OCPP send RemoteStartConfirmation by first.
  9379. sendRemoteStartConfirmation(uuid, comfirmstr);
  9380. return result;
  9381. }
  9382. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9383. {
  9384. mtrace();
  9385. int result = FAIL;
  9386. int match = FALSE;
  9387. int GunNO = 0;
  9388. int tempIndex = 0;
  9389. int transactionIdInt=0;
  9390. int transactionIdIsNULL= TRUE;
  9391. char comfirmstr[20];
  9392. json_object *RemoteStopTransaction;
  9393. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9394. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9395. if(server_pending == TRUE)
  9396. {
  9397. return 0;
  9398. }
  9399. RemoteStopTransaction = json_tokener_parse(payload);
  9400. if(!is_error(RemoteStopTransaction))
  9401. {
  9402. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9403. {
  9404. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9405. transactionIdIsNULL = FALSE;
  9406. }
  9407. }
  9408. json_object_put(RemoteStopTransaction);
  9409. if(transactionIdIsNULL == FALSE)
  9410. {
  9411. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9412. {
  9413. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9414. {
  9415. //check Transaction active
  9416. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9417. {
  9418. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9419. {
  9420. tempIndex = ((gun_index==2) ? 1: 0);
  9421. }
  9422. else
  9423. {
  9424. tempIndex = gun_index;
  9425. }
  9426. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9427. {
  9428. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9429. {
  9430. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9431. {
  9432. match = TRUE;
  9433. GunNO = gun_index;
  9434. }
  9435. }
  9436. }// END FOR CHAdeMO_QUANTITY
  9437. }
  9438. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9439. {
  9440. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9441. {
  9442. tempIndex = ((gun_index==2) ? 1: 0);
  9443. }
  9444. else
  9445. {
  9446. tempIndex = gun_index;
  9447. }
  9448. for (int index = 0; index < CCS_QUANTITY; index++)
  9449. {
  9450. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9451. {
  9452. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9453. {
  9454. match = TRUE;
  9455. GunNO = gun_index;
  9456. }
  9457. }
  9458. }// END FOR CCS_QUANTITY
  9459. }
  9460. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9461. {
  9462. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9463. {
  9464. tempIndex = ((gun_index==2) ? 1: 0);
  9465. }
  9466. else
  9467. {
  9468. tempIndex = gun_index;
  9469. }
  9470. for (int index = 0; index < GB_QUANTITY; index++)
  9471. {
  9472. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9473. {
  9474. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9475. {
  9476. match = TRUE;
  9477. GunNO = gun_index;
  9478. }
  9479. }
  9480. }// END FOR GB_QUANTITY
  9481. }
  9482. else if(gunType[gun_index] == GUN_TYPE_DO)
  9483. {
  9484. tempIndex = gun_index;
  9485. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9486. {
  9487. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9488. {
  9489. 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
  9490. {
  9491. match = TRUE;
  9492. GunNO = gun_index;
  9493. }
  9494. }
  9495. }// END FOR GB_QUANTITY
  9496. }
  9497. else
  9498. {
  9499. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9500. {
  9501. tempIndex = 2;
  9502. }
  9503. else
  9504. {
  9505. tempIndex = gun_index;
  9506. }
  9507. for (int index = 0; index < AC_QUANTITY; index++)
  9508. {
  9509. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9510. {
  9511. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9512. {
  9513. match = TRUE;
  9514. GunNO = gun_index;
  9515. }
  9516. }
  9517. }// END FOR CHAdeMO_QUANTITY
  9518. } // END FOR AC ELSE
  9519. }// CHECK IF ResponseTransactionId == transactionIdInt
  9520. }//END FOR
  9521. if( match == TRUE)
  9522. {
  9523. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9524. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9525. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9526. }
  9527. else
  9528. {
  9529. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9530. }
  9531. }
  9532. else
  9533. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9534. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9535. return result;
  9536. }
  9537. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9538. {
  9539. mtrace();
  9540. int result = FAIL;
  9541. int connectorIdInt=0, reservationIdInt=0;
  9542. int tempIndex = 0;
  9543. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9544. char comfirmstr[20]={0};
  9545. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9546. int c = 0;
  9547. char *loc;
  9548. //char *ptr;
  9549. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  9550. strcpy(sstrtemp, stringtrimspace(payload));
  9551. //***(1)connectorId ****/
  9552. c=0;
  9553. loc = strstr(sstrtemp, "connectorId");
  9554. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9555. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  9556. {
  9557. sstr[c] = loc[strlen("connectorId")+2+c];
  9558. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9559. c++;
  9560. }
  9561. sstr[c] = '\0';
  9562. connectorIdInt = atoi(sstr);
  9563. //***(2)expiryDate ****/
  9564. loc = strstr(sstrtemp, "expiryDate");
  9565. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9566. c = 0;
  9567. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  9568. {
  9569. sstr[c] = loc[3+strlen("expiryDate")+c];
  9570. c++;
  9571. }
  9572. sstr[c] = '\0';
  9573. strcpy(expiryDatestr, sstr);
  9574. //***(3)idTag ****/
  9575. loc = strstr(sstrtemp, "idTag");
  9576. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9577. c = 0;
  9578. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  9579. {
  9580. sstr[c] = loc[3+strlen("idTag")+c];
  9581. c++;
  9582. }
  9583. sstr[c] = '\0';
  9584. strcpy(idTagstr, sstr);
  9585. //***(4)parentIdTag ****/
  9586. loc = strstr(sstrtemp, "parentIdTag");
  9587. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9588. c = 0;
  9589. if(loc == NULL)
  9590. {
  9591. strcpy(parentIdTagstr, "");
  9592. }
  9593. else
  9594. {
  9595. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9596. {
  9597. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9598. c++;
  9599. }
  9600. sstr[c] = '\0';
  9601. strcpy(parentIdTagstr, sstr);
  9602. }
  9603. //***(5)reservationId ****/
  9604. c=0;
  9605. loc = strstr(sstrtemp, "reservationId");
  9606. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9607. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  9608. {
  9609. sstr[c] = loc[strlen("reservationId")+2+c];
  9610. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9611. c++;
  9612. }
  9613. sstr[c] = '\0';
  9614. reservationIdInt = atoi(sstr);
  9615. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9616. /*
  9617. enum SYSTEM_STATUS
  9618. {
  9619. SYS_MODE_BOOTING = 0,
  9620. SYS_MODE_IDLE = 1,
  9621. SYS_MODE_AUTHORIZING = 2,
  9622. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  9623. SYS_MODE_REASSIGN = 4,
  9624. SYS_MODE_PREPARING = 5,
  9625. SYS_MODE_PREPARE_FOR_EV = 6,
  9626. SYS_MODE_PREPARE_FOR_EVSE = 7,
  9627. SYS_MODE_CHARGING = 8,
  9628. SYS_MODE_TERMINATING = 9,
  9629. SYS_MODE_COMPLETE = 10,
  9630. SYS_MODE_ALARM = 11,
  9631. SYS_MODE_FAULT = 12,
  9632. SYS_MODE_RESERVATION = 13,
  9633. SYS_MODE_BOOKING = 14,
  9634. SYS_MODE_MAINTAIN = 15,
  9635. SYS_MODE_DEBUG = 16,
  9636. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  9637. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  9638. SYS_MODE_UPDATE = 19
  9639. };
  9640. */
  9641. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  9642. {
  9643. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9644. goto end;
  9645. }
  9646. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  9647. {
  9648. //check Transaction active
  9649. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9650. {
  9651. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9652. {
  9653. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9654. }
  9655. else
  9656. {
  9657. tempIndex = connectorIdInt -1;
  9658. }
  9659. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9660. {
  9661. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9662. {
  9663. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9664. {
  9665. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9666. {
  9667. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9668. {
  9669. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9670. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9671. }
  9672. 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'))
  9673. {
  9674. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9675. }
  9676. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9677. {
  9678. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9679. }
  9680. else
  9681. {
  9682. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9683. }
  9684. }
  9685. 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
  9686. {
  9687. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9688. }
  9689. }
  9690. else
  9691. {
  9692. //replace reservation
  9693. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9694. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9695. }
  9696. }
  9697. } // END FOR CHAdeMO_QUANTITY
  9698. }
  9699. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9700. {
  9701. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9702. {
  9703. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9704. }
  9705. else
  9706. {
  9707. tempIndex = connectorIdInt -1;
  9708. }
  9709. for (int index = 0; index < CCS_QUANTITY; index++)
  9710. {
  9711. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9712. {
  9713. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9714. {
  9715. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9716. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9717. {
  9718. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9719. {
  9720. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9721. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9722. }
  9723. 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'))
  9724. {
  9725. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9726. }
  9727. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  9728. {
  9729. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9730. }
  9731. else
  9732. {
  9733. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9734. }
  9735. }
  9736. 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
  9737. {
  9738. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9739. }
  9740. }
  9741. else
  9742. {
  9743. //replace reservation
  9744. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9745. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9746. }
  9747. }
  9748. } // END FOR CCS_QUANTITY
  9749. }
  9750. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9751. {
  9752. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9753. {
  9754. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9755. }
  9756. else
  9757. {
  9758. tempIndex = connectorIdInt -1;
  9759. }
  9760. for (int index = 0; index < GB_QUANTITY; index++)
  9761. {
  9762. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9763. {
  9764. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9765. {
  9766. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9767. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9768. {
  9769. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9770. {
  9771. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9772. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9773. }
  9774. 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'))
  9775. {
  9776. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9777. }
  9778. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9779. {
  9780. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9781. }
  9782. else
  9783. {
  9784. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9785. }
  9786. }
  9787. 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
  9788. {
  9789. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9790. }
  9791. }
  9792. else
  9793. {
  9794. //replace reservation
  9795. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9796. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9797. }
  9798. }
  9799. }// END FOR GB_QUANTITY
  9800. }
  9801. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9802. {
  9803. tempIndex = connectorIdInt -1;
  9804. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9805. {
  9806. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9807. {
  9808. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  9809. {
  9810. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9811. 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
  9812. {
  9813. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9814. {
  9815. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9816. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9817. }
  9818. 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'))
  9819. {
  9820. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9821. }
  9822. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9823. {
  9824. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9825. }
  9826. else
  9827. {
  9828. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9829. }
  9830. }
  9831. 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
  9832. {
  9833. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9834. }
  9835. }
  9836. else
  9837. {
  9838. //replace reservation
  9839. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9840. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9841. }
  9842. }
  9843. }// END FOR GB_QUANTITY
  9844. }
  9845. else
  9846. {
  9847. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9848. {
  9849. tempIndex = 2;
  9850. }
  9851. else
  9852. {
  9853. tempIndex = (connectorIdInt -1);
  9854. }
  9855. for (int index = 0; index < AC_QUANTITY; index++)
  9856. {
  9857. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9858. {
  9859. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9860. {
  9861. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9862. {
  9863. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9864. {
  9865. 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))
  9866. {
  9867. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9868. }
  9869. else
  9870. {
  9871. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9872. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9873. }
  9874. }
  9875. 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'))
  9876. {
  9877. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9878. }
  9879. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9880. {
  9881. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9882. }
  9883. else
  9884. {
  9885. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9886. }
  9887. }
  9888. 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
  9889. {
  9890. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9891. }
  9892. }
  9893. else
  9894. {
  9895. //replace reservation
  9896. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9897. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9898. }
  9899. }
  9900. } // END FOR AC_QUANTITY
  9901. }
  9902. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9903. }
  9904. else if(connectorIdInt == 0)
  9905. {
  9906. //check Transaction active
  9907. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9908. {
  9909. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9910. {
  9911. 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'))
  9912. {
  9913. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9914. goto end;
  9915. }
  9916. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9917. {
  9918. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9919. goto end;
  9920. }
  9921. 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
  9922. {
  9923. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9924. goto end;
  9925. }
  9926. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9927. {
  9928. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9929. goto end;
  9930. }
  9931. }
  9932. }// END FOR CHAdeMO_QUANTITY
  9933. for (int index = 0; index < CCS_QUANTITY; index++)
  9934. {
  9935. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9936. {
  9937. 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'))
  9938. {
  9939. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9940. goto end;
  9941. }
  9942. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  9943. {
  9944. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9945. goto end;
  9946. }
  9947. 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
  9948. {
  9949. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9950. goto end;
  9951. }
  9952. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9953. {
  9954. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9955. goto end;
  9956. }
  9957. }
  9958. } // END FOR CCS_QUANTITY
  9959. for (int index = 0; index < GB_QUANTITY; index++)
  9960. {
  9961. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9962. {
  9963. 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'))
  9964. {
  9965. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9966. goto end;
  9967. }
  9968. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9969. {
  9970. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9971. goto end;
  9972. }
  9973. 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
  9974. {
  9975. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9976. goto end;
  9977. }
  9978. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9979. {
  9980. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9981. goto end;
  9982. }
  9983. }
  9984. } // END FOR GB_QUANTITY
  9985. for (int index = 0; index < AC_QUANTITY; index++)
  9986. {
  9987. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9988. {
  9989. 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'))
  9990. {
  9991. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9992. goto end;
  9993. }
  9994. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9995. {
  9996. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9997. goto end;
  9998. }
  9999. 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
  10000. {
  10001. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10002. goto end;
  10003. }
  10004. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10005. {
  10006. 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))
  10007. {
  10008. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10009. goto end;
  10010. }
  10011. }
  10012. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10013. {
  10014. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10015. goto end;
  10016. }
  10017. }
  10018. }// END FOR AC_QUANTITY
  10019. //The connectorId is 0
  10020. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  10021. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10022. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10023. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  10024. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10025. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  10026. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10027. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  10028. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  10029. result = TRUE;
  10030. return result;
  10031. }
  10032. else
  10033. {
  10034. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10035. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10036. }
  10037. if(strcmp(comfirmstr,"Accepted") == 0)
  10038. {
  10039. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  10040. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  10041. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  10042. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  10043. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  10044. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  10045. result = TRUE;
  10046. return result;
  10047. }
  10048. end:
  10049. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  10050. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  10051. return result;
  10052. }
  10053. int handleResetRequest(char *uuid, char *payload)
  10054. {
  10055. mtrace();
  10056. int result = FAIL;
  10057. char sstr[10]={0},sstrtemp[30]={ 0 };
  10058. char typestr[10]={0};
  10059. char comfirmstr[20]={0};
  10060. int c = 0;
  10061. char *loc;
  10062. DEBUG_INFO("handleResetRequest...\n");
  10063. strcpy(sstrtemp, stringtrimspace(payload));
  10064. loc = strstr(sstrtemp, "type");
  10065. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10066. c = 0;
  10067. while (loc[3+strlen("type")+c] != '\"')
  10068. {
  10069. sstr[c] = loc[3+strlen("type")+c];
  10070. c++;
  10071. }
  10072. sstr[c] = '\0';
  10073. strcpy(typestr,sstr);
  10074. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  10075. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  10076. {
  10077. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  10078. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  10079. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  10080. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10081. }
  10082. else
  10083. {
  10084. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  10085. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10086. result = PASS;
  10087. }
  10088. sendResetConfirmation(uuid, comfirmstr);
  10089. return result;
  10090. }
  10091. int handleSendLocalListRequest(char *uuid, char *payload)
  10092. {
  10093. mtrace();
  10094. int result = FAIL;
  10095. char comfirmstr[20];
  10096. int checkState_Faulted = FALSE;
  10097. json_object *SendLocalList;
  10098. DEBUG_INFO("handleSendLocalListRequest...\n");
  10099. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  10100. {
  10101. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10102. goto end;
  10103. }
  10104. //check Charge Point state
  10105. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10106. {
  10107. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10108. {
  10109. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10110. }
  10111. }
  10112. for (int index = 0; index < CCS_QUANTITY; index++)
  10113. {
  10114. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10115. {
  10116. checkState_Faulted = TRUE; //OCPP Status
  10117. }
  10118. }
  10119. for (int index = 0; index < GB_QUANTITY; index++)
  10120. {
  10121. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10122. {
  10123. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10124. }
  10125. }
  10126. //check Charge Point state
  10127. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10128. {
  10129. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10130. {
  10131. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10132. }
  10133. }
  10134. //check Charge Point state
  10135. for (int index = 0; index < AC_QUANTITY; index++)
  10136. {
  10137. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10138. {
  10139. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10140. }
  10141. }
  10142. if(checkState_Faulted == TRUE)
  10143. {
  10144. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10145. goto end;
  10146. }
  10147. // Parsing payload
  10148. SendLocalList = json_tokener_parse(payload);
  10149. if(!is_error(SendLocalList))
  10150. {
  10151. // Required data
  10152. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  10153. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  10154. // Optional data
  10155. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  10156. {
  10157. //Check UpdateType
  10158. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10159. {
  10160. //Local list full update
  10161. DEBUG_INFO("Local list full update.\n");
  10162. OCPP_getListVerion();
  10163. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10164. {
  10165. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10166. goto end;
  10167. }
  10168. OCPP_cleanLocalList();
  10169. }
  10170. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10171. {
  10172. //Local list different update
  10173. DEBUG_INFO("Local list different update.\n");
  10174. OCPP_getListVerion();
  10175. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10176. {
  10177. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  10178. goto end;
  10179. }
  10180. }
  10181. else
  10182. {
  10183. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10184. goto end;
  10185. }
  10186. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  10187. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  10188. {
  10189. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  10190. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  10191. {
  10192. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].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")));
  10193. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  10194. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].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")));
  10195. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  10196. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].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")));
  10197. }
  10198. // Add to db
  10199. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10200. {
  10201. //Local list full update
  10202. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  10203. idx,
  10204. ShmOCPP16Data->SendLocalList.ListVersion,
  10205. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10206. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10207. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10208. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10209. // update list
  10210. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10211. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10212. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10213. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10214. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10215. }
  10216. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10217. {
  10218. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  10219. idx,
  10220. ShmOCPP16Data->SendLocalList.ListVersion,
  10221. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10222. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10223. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10224. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10225. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10226. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10227. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10228. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10229. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10230. }
  10231. }
  10232. }
  10233. else
  10234. {
  10235. //Check UpdateType
  10236. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10237. {
  10238. //Local list full update
  10239. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  10240. OCPP_cleanLocalList();
  10241. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10242. goto end;
  10243. }
  10244. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10245. {
  10246. //Local list different update
  10247. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  10248. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10249. goto end;
  10250. }
  10251. }
  10252. result = PASS;
  10253. }
  10254. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10255. end:
  10256. json_object_put(SendLocalList);
  10257. sendSendLocalListConfirmation(uuid, comfirmstr);
  10258. return result;
  10259. }
  10260. #define MAX 200
  10261. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10262. {
  10263. mtrace();
  10264. int result = FAIL;
  10265. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  10266. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  10267. char chargingProfilePurposeStr[30]={0};
  10268. char chargingProfileKindStr[16]={0};
  10269. char recurrencyKindStr[10]={0};
  10270. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  10271. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  10272. int chargingSchedulePeriodCount = 0;
  10273. char comfirmstr[20]={0};
  10274. int meet= FALSE;
  10275. FILE *fptr1;
  10276. char filename[MAX]={0};
  10277. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  10278. char rmFileCmd[50]={0};
  10279. char tempchargingProfilePurposeStr[30]={0};
  10280. char word[1600]={0};
  10281. int n_chargingProfile = 0;
  10282. json_object *SetChargingProfile;
  10283. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10284. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  10285. SetChargingProfile = json_tokener_parse(payload);
  10286. if(!is_error(SetChargingProfile))
  10287. {
  10288. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10289. {
  10290. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10291. if(connectorIdInt == 0)
  10292. {
  10293. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  10294. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  10295. }
  10296. else
  10297. {
  10298. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  10299. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  10300. }
  10301. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  10302. }
  10303. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10304. {
  10305. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10306. {
  10307. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10308. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10309. {
  10310. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10311. }
  10312. else
  10313. {
  10314. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10315. }
  10316. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  10317. }
  10318. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10319. {
  10320. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10321. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10322. {
  10323. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  10324. }
  10325. else
  10326. {
  10327. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  10328. }
  10329. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  10330. }
  10331. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10332. {
  10333. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10334. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10335. {
  10336. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10337. }
  10338. else
  10339. {
  10340. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10341. }
  10342. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  10343. }
  10344. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10345. {
  10346. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10347. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10348. {
  10349. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10350. }
  10351. else
  10352. {
  10353. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10354. }
  10355. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  10356. }
  10357. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10358. {
  10359. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10360. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10361. {
  10362. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  10363. }
  10364. else
  10365. {
  10366. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  10367. }
  10368. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  10369. }
  10370. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10371. {
  10372. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10373. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10374. {
  10375. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10376. }
  10377. else
  10378. {
  10379. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10380. }
  10381. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  10382. }
  10383. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10384. {
  10385. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10386. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10387. {
  10388. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  10389. }
  10390. else
  10391. {
  10392. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  10393. }
  10394. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  10395. }
  10396. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10397. {
  10398. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10399. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10400. {
  10401. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  10402. }
  10403. else
  10404. {
  10405. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  10406. }
  10407. //DEBUG_INFO("validToStr: %s\n", validToStr);
  10408. }
  10409. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10410. {
  10411. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10412. {
  10413. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  10414. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10415. {
  10416. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10417. }
  10418. else
  10419. {
  10420. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10421. }
  10422. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  10423. }
  10424. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10425. {
  10426. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10427. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10428. {
  10429. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10430. }
  10431. else
  10432. {
  10433. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10434. }
  10435. //DEBUG_INFO("durationInt: %d\n", durationInt);
  10436. }
  10437. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10438. {
  10439. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10440. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10441. {
  10442. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10443. }
  10444. else
  10445. {
  10446. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10447. }
  10448. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  10449. }
  10450. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10451. {
  10452. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  10453. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10454. {
  10455. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10456. }
  10457. else
  10458. {
  10459. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10460. }
  10461. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  10462. }
  10463. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10464. {
  10465. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10466. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  10467. if(chargingSchedulePeriodCount <= 10)
  10468. {
  10469. 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++)
  10470. {
  10471. 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)
  10472. {
  10473. startPeriodInt[idxPeriod] = 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"));
  10474. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10475. {
  10476. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10477. }
  10478. else
  10479. {
  10480. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10481. }
  10482. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  10483. }
  10484. 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)
  10485. {
  10486. limitflaot[idxPeriod] = 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"));
  10487. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10488. {
  10489. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10490. }
  10491. else
  10492. {
  10493. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10494. }
  10495. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  10496. }
  10497. 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)
  10498. {
  10499. numberPhasesInt[idxPeriod] = 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"));
  10500. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10501. {
  10502. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10503. }
  10504. else
  10505. {
  10506. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10507. }
  10508. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  10509. }
  10510. }
  10511. }
  10512. }
  10513. }
  10514. }
  10515. }
  10516. json_object_put(SetChargingProfile);
  10517. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10518. {
  10519. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10520. goto end;
  10521. }
  10522. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10523. {
  10524. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  10525. if(connectorIdInt != 0)
  10526. {
  10527. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10528. goto end;
  10529. }
  10530. strcpy(filename, ChargePointMaxProfile_JSON );
  10531. fptr1 = fopen(filename, "r");
  10532. if (!fptr1)
  10533. {
  10534. //file not exist
  10535. DEBUG_INFO("Unable to open the input file!!\n");
  10536. fptr1 = fopen(filename, "w+");
  10537. }
  10538. else
  10539. {
  10540. //Check Charging Profile Count
  10541. while(fscanf(fptr1, "%s", word) != EOF)
  10542. {
  10543. //DEBUG_INFO("word=%s\n",word);
  10544. if(strstr(word, "chargingProfileId")!= NULL)
  10545. {
  10546. //DEBUG_INFO("test chargingProfileId \n");
  10547. n_chargingProfile = n_chargingProfile + 1;
  10548. //DEBUG_INFO("chargingProfileId Found\n");
  10549. }
  10550. }
  10551. }
  10552. fclose(fptr1);
  10553. }
  10554. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10555. {
  10556. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  10557. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10558. {
  10559. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10560. goto end;
  10561. }
  10562. memset(filename, 0, ARRAY_SIZE(filename));
  10563. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  10564. fptr1 = fopen(filename, "r");
  10565. if (!fptr1)
  10566. {
  10567. //file not exist
  10568. //DEBUG_INFO("Unable to open the input file!!\n");
  10569. fptr1 = fopen(filename, "w+");
  10570. }
  10571. else
  10572. {
  10573. //Check Charging Profile Count
  10574. while(fscanf(fptr1, "%s", word) != EOF)
  10575. {
  10576. //DEBUG_INFO("word=%s\n",word);
  10577. if(strstr(word, "chargingProfileId")!= NULL)
  10578. {
  10579. //DEBUG_INFO("test chargingProfileId \n");
  10580. n_chargingProfile = n_chargingProfile + 1;
  10581. //DEBUG_INFO("chargingProfileId Found\n");
  10582. }
  10583. }
  10584. }
  10585. fclose(fptr1);
  10586. }
  10587. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10588. {
  10589. //printf("set chargingProfile 1-4\n");
  10590. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  10591. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10592. if(connectorIdInt == 0)
  10593. {
  10594. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10595. goto end;
  10596. }
  10597. int tempIndex = 0;
  10598. //check Transaction active
  10599. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10600. {
  10601. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10602. {
  10603. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10604. }
  10605. else
  10606. {
  10607. tempIndex = connectorIdInt -1;
  10608. }
  10609. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10610. {
  10611. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10612. {
  10613. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  10614. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10615. {
  10616. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10617. {
  10618. meet = TRUE;
  10619. break;
  10620. }
  10621. }
  10622. }
  10623. }
  10624. }
  10625. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10626. {
  10627. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10628. {
  10629. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10630. }
  10631. else
  10632. {
  10633. tempIndex = connectorIdInt -1;
  10634. }
  10635. for (int index = 0; index < CCS_QUANTITY; index++)
  10636. {
  10637. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10638. {
  10639. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  10640. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10641. {
  10642. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10643. {
  10644. meet = TRUE;
  10645. break;
  10646. }
  10647. }
  10648. }
  10649. }
  10650. }
  10651. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10652. {
  10653. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10654. {
  10655. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10656. }
  10657. else
  10658. {
  10659. tempIndex = connectorIdInt -1;
  10660. }
  10661. for (int index = 0; index < GB_QUANTITY; index++)
  10662. {
  10663. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10664. {
  10665. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  10666. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10667. {
  10668. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10669. {
  10670. meet = TRUE;
  10671. break;
  10672. }
  10673. }
  10674. }
  10675. }
  10676. }
  10677. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10678. {
  10679. tempIndex = connectorIdInt -1;
  10680. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10681. {
  10682. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10683. {
  10684. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  10685. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10686. {
  10687. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10688. {
  10689. meet = TRUE;
  10690. break;
  10691. }
  10692. }
  10693. }
  10694. }
  10695. }
  10696. else
  10697. {
  10698. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10699. {
  10700. tempIndex = 2;
  10701. }
  10702. else
  10703. {
  10704. tempIndex = (connectorIdInt -1);
  10705. }
  10706. for (int index = 0; index < AC_QUANTITY; index++)
  10707. {
  10708. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10709. {
  10710. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10711. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  10712. {
  10713. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10714. {
  10715. meet = TRUE;
  10716. break;
  10717. }
  10718. }
  10719. }
  10720. }
  10721. }
  10722. //check Transaction active
  10723. if(meet == FALSE)
  10724. {
  10725. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10726. goto end;
  10727. }
  10728. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10729. {
  10730. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10731. goto end;
  10732. }
  10733. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10734. fptr1 = fopen(filename, "r");
  10735. if (!fptr1)
  10736. {
  10737. //file not exist
  10738. DEBUG_INFO("Unable to open the input file!!\n");
  10739. fptr1 = fopen(filename, "w+");
  10740. }
  10741. else
  10742. {
  10743. //Check Charging Profile Count
  10744. while(fscanf(fptr1, "%s", word) != EOF)
  10745. {
  10746. //DEBUG_INFO("word=%s\n",word);
  10747. if(strstr(word, "chargingProfileId")!= NULL)
  10748. {
  10749. //DEBUG_INFO("test chargingProfileId \n");
  10750. n_chargingProfile = n_chargingProfile + 1;
  10751. //DEBUG_INFO("chargingProfileId Found\n");
  10752. }
  10753. }
  10754. }
  10755. fclose(fptr1);
  10756. }
  10757. // Check ChargeProfileMaxStackLevel
  10758. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  10759. {
  10760. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10761. goto end;
  10762. }
  10763. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10764. {
  10765. int i = 0;
  10766. char fnametemp[200]={0};
  10767. n_chargingProfile = 0;
  10768. //Check ChargePointMaxProfile.json exit
  10769. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  10770. {
  10771. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  10772. //Check Charging Profile Count
  10773. while(fscanf(fptr1, "%s", word) != EOF)
  10774. {
  10775. //DEBUG_INFO("word=%s\n",word);
  10776. if(strstr(word, "chargingProfileId")!= NULL)
  10777. {
  10778. //DEBUG_INFO("test chargingProfileId \n");
  10779. n_chargingProfile = n_chargingProfile + 1;
  10780. i = i + 1;
  10781. //DEBUG_INFO("chargingProfileId Found\n");
  10782. }
  10783. memset(word, 0, ARRAY_SIZE(word));
  10784. }
  10785. fclose(fptr1);
  10786. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  10787. }
  10788. //Check TxDefaultProfile_0.json exit
  10789. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  10790. {
  10791. i = 0;
  10792. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  10793. //Check Charging Profile Count
  10794. while(fscanf(fptr1, "%s", word) != EOF)
  10795. {
  10796. //DEBUG_INFO("word=%s\n",word);
  10797. if(strstr(word, "chargingProfileId")!= NULL)
  10798. {
  10799. //DEBUG_INFO("test chargingProfileId \n");
  10800. n_chargingProfile = n_chargingProfile + 1;
  10801. i = i + 1;
  10802. //DEBUG_INFO("chargingProfileId Found\n");
  10803. }
  10804. memset(word, 0, ARRAY_SIZE(word));
  10805. }
  10806. fclose(fptr1);
  10807. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  10808. }
  10809. //Check TxDefaultProfile_%d.json
  10810. for(int j=1; j <= gunTotalNumber; j++)
  10811. {
  10812. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10813. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  10814. if((access(fnametemp,F_OK))!=-1)
  10815. {
  10816. i = 0;
  10817. fptr1 = fopen(fnametemp, "r");
  10818. //Check Charging Profile Count
  10819. while(fscanf(fptr1, "%s", word) != EOF)
  10820. {
  10821. //DEBUG_INFO("word=%s\n",word);
  10822. if(strstr(word, "chargingProfileId")!= NULL)
  10823. {
  10824. //DEBUG_INFO("test chargingProfileId \n");
  10825. n_chargingProfile = n_chargingProfile + 1;
  10826. i = i + 1;
  10827. //DEBUG_INFO("chargingProfileId Found\n");
  10828. }
  10829. memset(word, 0, ARRAY_SIZE(word));
  10830. }
  10831. fclose(fptr1);
  10832. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10833. }
  10834. }
  10835. //Check TxProfile_%d.json
  10836. for(int j=1; j <= gunTotalNumber; j++)
  10837. {
  10838. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10839. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  10840. if((access(fnametemp,F_OK))!=-1)
  10841. {
  10842. i = 0;
  10843. fptr1 = fopen(fnametemp, "r");
  10844. //Check Charging Profile Count
  10845. while(fscanf(fptr1, "%s", word) != EOF)
  10846. {
  10847. //DEBUG_INFO("word=%s\n",word);
  10848. if(strstr(word, "chargingProfileId")!= NULL)
  10849. {
  10850. //DEBUG_INFO("test chargingProfileId \n");
  10851. n_chargingProfile = n_chargingProfile + 1;
  10852. i = i + 1;
  10853. //DEBUG_INFO("chargingProfileId Found\n");
  10854. }
  10855. memset(word, 0, ARRAY_SIZE(word));
  10856. }
  10857. fclose(fptr1);
  10858. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10859. }
  10860. }
  10861. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10862. {
  10863. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10864. goto end;
  10865. }
  10866. }
  10867. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10868. //**********************************Write to File********************************************************/
  10869. FILE *infile;
  10870. FILE *outfile;
  10871. infile = fopen (filename, "r");
  10872. outfile = fopen (tempfile, "w");
  10873. int d =0;
  10874. d = fgetc(infile);
  10875. rewind(infile);
  10876. if(d == EOF)
  10877. {
  10878. // Profile is empty
  10879. fprintf(outfile,"%s\n",payload);
  10880. fclose(infile);
  10881. fclose(outfile);
  10882. sprintf(rmFileCmd,"rm -f %s",filename);
  10883. system(rmFileCmd);
  10884. rename(tempfile, filename);
  10885. }
  10886. else
  10887. {
  10888. // Profile is not empty
  10889. char buf[2048]={0};
  10890. int ChargingProfileAdded = FALSE;
  10891. while (fgets(buf, sizeof(buf), infile) != NULL)
  10892. {
  10893. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10894. json_object *tmpChargingProfile;
  10895. tmpChargingProfile = json_tokener_parse(buf);
  10896. if(!is_error(SetChargingProfile))
  10897. {
  10898. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10899. {
  10900. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10901. }
  10902. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10903. {
  10904. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10905. {
  10906. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10907. }
  10908. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10909. {
  10910. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10911. }
  10912. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10913. {
  10914. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10915. }
  10916. }
  10917. }
  10918. json_object_put(tmpChargingProfile);
  10919. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10920. {
  10921. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10922. {
  10923. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10924. if(ChargingProfileAdded == FALSE)
  10925. {
  10926. fprintf(outfile,"%s\n",payload);
  10927. ChargingProfileAdded = TRUE;
  10928. }
  10929. }
  10930. else
  10931. {
  10932. if(tempstackLevelInt < stackLevelInt)
  10933. {
  10934. if(ChargingProfileAdded == FALSE)
  10935. {
  10936. fprintf(outfile,"%s\n",buf);
  10937. fprintf(outfile,"%s\n",payload);
  10938. ChargingProfileAdded = TRUE;
  10939. }
  10940. else
  10941. {
  10942. fprintf(outfile,"%s\n",buf);
  10943. }
  10944. }
  10945. else
  10946. {
  10947. if(ChargingProfileAdded == FALSE)
  10948. {
  10949. fprintf(outfile,"%s\n",buf);
  10950. fprintf(outfile,"%s\n",payload);
  10951. ChargingProfileAdded = TRUE;
  10952. }
  10953. else
  10954. {
  10955. fprintf(outfile,"%s\n",buf);
  10956. }
  10957. }
  10958. }
  10959. }
  10960. else
  10961. {
  10962. if(tempchargingProfileIdInt < chargingProfileIdInt)
  10963. {
  10964. if(ChargingProfileAdded == FALSE)
  10965. {
  10966. fprintf(outfile,"%s\n",buf);
  10967. fprintf(outfile,"%s\n",payload);
  10968. ChargingProfileAdded = TRUE;
  10969. }
  10970. else
  10971. {
  10972. fprintf(outfile,"%s\n",buf);
  10973. }
  10974. }
  10975. else if(tempstackLevelInt < stackLevelInt)
  10976. {
  10977. if(ChargingProfileAdded == FALSE)
  10978. {
  10979. fprintf(outfile,"%s\n",buf);
  10980. fprintf(outfile,"%s\n",payload);
  10981. ChargingProfileAdded = TRUE;
  10982. }
  10983. else
  10984. {
  10985. fprintf(outfile,"%s\n",buf);
  10986. }
  10987. }
  10988. else
  10989. {
  10990. if(ChargingProfileAdded == FALSE)
  10991. {
  10992. fprintf(outfile,"%s\n",buf);
  10993. fprintf(outfile,"%s\n",payload);
  10994. ChargingProfileAdded = TRUE;
  10995. }
  10996. else
  10997. {
  10998. fprintf(outfile,"%s\n",buf);
  10999. }
  11000. }
  11001. }
  11002. } // end of while loop
  11003. fclose(infile);
  11004. fclose(outfile);
  11005. sprintf(rmFileCmd,"rm -f %s",filename);
  11006. system(rmFileCmd);
  11007. rename(tempfile, filename);
  11008. }
  11009. sleep(1);
  11010. result = TRUE;
  11011. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11012. end:
  11013. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11014. {
  11015. if(connectorIdInt == 0)
  11016. {
  11017. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11018. {
  11019. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  11020. }
  11021. }
  11022. else
  11023. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  11024. }
  11025. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11026. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11027. return result;
  11028. }
  11029. int handleTriggerMessageRequest(char *uuid, char *payload)
  11030. {
  11031. mtrace();
  11032. int result = FAIL;
  11033. int connectorIdIsNULL = FALSE;
  11034. int connectorIdInt =0;
  11035. char sstr[40]={0},sstrtemp[100]={ 0 };
  11036. char requestedMessagestr[40]={0};
  11037. char comfirmstr[20]={0};
  11038. int c = 0;
  11039. char *loc;
  11040. DEBUG_INFO("handleTriggerMessageRequest\n");
  11041. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11042. strcpy(sstrtemp, stringtrimspace(payload));
  11043. c = 0;
  11044. loc = strstr(sstrtemp, "requestedMessage");
  11045. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11046. {
  11047. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11048. c++;
  11049. }
  11050. sstr[c] = '\0';
  11051. strcpy(requestedMessagestr, sstr);
  11052. c = 0;
  11053. loc = strstr(sstrtemp, "connectorId");
  11054. if(loc == NULL)
  11055. {
  11056. connectorIdIsNULL = TRUE;
  11057. }
  11058. else
  11059. {
  11060. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11061. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11062. {
  11063. sstr[c] = loc[strlen("connectorId")+2+c];
  11064. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11065. c++;
  11066. }
  11067. sstr[c] = '\0';
  11068. connectorIdInt = atoi(sstr);
  11069. }
  11070. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11071. {
  11072. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11073. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11074. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11075. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11076. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11077. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11078. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11079. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11080. {
  11081. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11082. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11083. return TRUE;
  11084. }
  11085. else
  11086. {
  11087. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11088. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11089. }
  11090. }
  11091. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11092. {
  11093. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11094. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11095. return TRUE;
  11096. }
  11097. //==========================
  11098. // Trigger message
  11099. //==========================
  11100. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11101. {
  11102. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11103. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11104. {
  11105. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11106. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11107. }
  11108. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11109. }
  11110. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11111. {
  11112. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  11113. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11114. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11115. }
  11116. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11117. {
  11118. //sendBootNotificationRequest();
  11119. server_sign = FALSE;
  11120. }
  11121. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11122. {
  11123. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11124. }
  11125. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11126. {
  11127. if(connectorIdIsNULL == FALSE)
  11128. {
  11129. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11130. {
  11131. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11132. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11133. }
  11134. }
  11135. else
  11136. {
  11137. for(int idx=0;idx< gunTotalNumber;idx++)
  11138. {
  11139. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11140. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11141. }
  11142. }
  11143. }
  11144. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11145. {
  11146. if(connectorIdIsNULL == FALSE)
  11147. {
  11148. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  11149. {
  11150. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11151. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  11152. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11153. }
  11154. }
  11155. else
  11156. {
  11157. for(int idx=0;idx< gunTotalNumber;idx++)
  11158. {
  11159. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  11160. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11161. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11162. }
  11163. }
  11164. }
  11165. return result;
  11166. }
  11167. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11168. {
  11169. mtrace();
  11170. int result = FAIL;
  11171. int connectorIdInt =0;
  11172. char comfirmstr[20]={0};
  11173. int tempIndex = 0;
  11174. json_object *UnlockConnector;
  11175. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11176. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11177. UnlockConnector = json_tokener_parse(payload);
  11178. if(!is_error(UnlockConnector))
  11179. {
  11180. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11181. {
  11182. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11183. }
  11184. }
  11185. json_object_put(UnlockConnector);
  11186. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11187. if(gunTotalNumber == 0)
  11188. {
  11189. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11190. goto end;
  11191. }
  11192. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11193. {
  11194. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11195. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11196. goto end;
  11197. }
  11198. else
  11199. {
  11200. //check Transaction active
  11201. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11202. {
  11203. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11204. {
  11205. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11206. }
  11207. else
  11208. {
  11209. tempIndex = connectorIdInt -1;
  11210. }
  11211. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11212. {
  11213. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11214. {
  11215. //stop Transaction
  11216. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11217. }
  11218. }
  11219. }
  11220. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  11221. {
  11222. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11223. {
  11224. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11225. }
  11226. else
  11227. {
  11228. tempIndex = connectorIdInt -1;
  11229. }
  11230. for (int index = 0; index < CCS_QUANTITY; index++)
  11231. {
  11232. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11233. {
  11234. //stop Transaction
  11235. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11236. }
  11237. }
  11238. }
  11239. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  11240. {
  11241. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11242. {
  11243. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11244. }
  11245. else
  11246. {
  11247. tempIndex = connectorIdInt -1;
  11248. }
  11249. for (int index = 0; index < GB_QUANTITY; index++)
  11250. {
  11251. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  11252. {
  11253. //stop Transaction
  11254. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11255. }
  11256. }
  11257. }
  11258. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  11259. {
  11260. tempIndex = connectorIdInt -1;
  11261. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11262. {
  11263. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)))
  11264. {
  11265. //stop Transaction
  11266. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11267. }
  11268. }
  11269. }
  11270. else
  11271. {
  11272. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11273. {
  11274. tempIndex = 2;
  11275. }
  11276. else
  11277. {
  11278. tempIndex = connectorIdInt-1;
  11279. }
  11280. for (int index = 0; index < AC_QUANTITY; index++)
  11281. {
  11282. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11283. {
  11284. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11285. }
  11286. }
  11287. }
  11288. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11289. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  11290. result = TRUE;
  11291. return result;
  11292. }
  11293. end:
  11294. //json_object_put(obj); --- remove temporally
  11295. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11296. return result;
  11297. }
  11298. static char UpdateFirmwarepayloadData[300]={0};
  11299. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11300. {
  11301. mtrace();
  11302. int result = FAIL;
  11303. pthread_t t;
  11304. sendUpdateFirmwareConfirmation(uuid);
  11305. memset(UpdateFirmwarepayloadData, 0, 300);
  11306. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11307. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11308. ////pthread_join(t, NULL); //
  11309. //pthread_detach(t);
  11310. //sendUpdateFirmwareConfirmation(uuid);
  11311. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  11312. return result;
  11313. }
  11314. void *UpdateFirmwareProcess(void *data)
  11315. {
  11316. pthread_detach(pthread_self());
  11317. mtrace();
  11318. int retriesInt =0, retryIntervalInt=0;
  11319. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  11320. int port=0;
  11321. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  11322. int isSuccess = 0;
  11323. char ftpbuf[1024];
  11324. char temp[1024];
  11325. char * pch;
  11326. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11327. json_object *UpdateFirmware;
  11328. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11329. if(!is_error(UpdateFirmware))
  11330. {
  11331. // Required data
  11332. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11333. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11334. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11335. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11336. // Optional data
  11337. if(json_object_object_get(UpdateFirmware, "retries"))
  11338. {
  11339. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11340. }
  11341. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11342. {
  11343. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11344. }
  11345. }
  11346. json_object_put(UpdateFirmware);
  11347. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11348. memset(path, 0, ARRAY_SIZE(path));
  11349. // Wait retrieveData
  11350. if(strlen(retrieveDatestr) > 10)
  11351. {
  11352. do
  11353. {
  11354. sleep(1);
  11355. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11356. }
  11357. // Ready to download
  11358. system("rm -f /mnt/*");
  11359. if(strncmp(locationstr,"http", 4) == 0)
  11360. {
  11361. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11362. sprintf(ftppath,"/%s", path);
  11363. DEBUG_INFO("locationstr: %s\n", locationstr);
  11364. DEBUG_INFO("protocol: %s\n",protocol);
  11365. DEBUG_INFO("host: %s\n",host);
  11366. DEBUG_INFO("path: %s\n",path);
  11367. DEBUG_INFO("ftppath: %s\n",ftppath);
  11368. int ftppathlen=strlen(ftppath);
  11369. int i=1;
  11370. char filenametemp[50];
  11371. while(i < ftppathlen)
  11372. {
  11373. int len=ftppathlen-i;
  11374. if(ftppath[len]== 47) // '/' ascll code: 47
  11375. {
  11376. DEBUG_INFO("compare '/' all right\n");
  11377. break;
  11378. }
  11379. i=i+1;
  11380. }
  11381. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11382. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11383. filenametemp[i+1] = 0;
  11384. do
  11385. {
  11386. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11387. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11388. sleep(1);
  11389. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11390. if(!isSuccess)
  11391. {
  11392. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11393. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11394. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11395. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11396. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11397. }
  11398. else
  11399. {
  11400. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11401. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11402. }
  11403. retriesInt--;
  11404. }while((isSuccess == 0)&&(retriesInt >= 0));
  11405. }
  11406. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11407. {
  11408. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11409. memset(temp, 0, ARRAY_SIZE(temp));
  11410. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11411. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11412. int ftppathlen=strlen(ftpbuf);
  11413. int i=1;
  11414. char filenametemp[50];
  11415. while(i < ftppathlen)
  11416. {
  11417. int len=ftppathlen-i;
  11418. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11419. {
  11420. DEBUG_INFO(" compare '/' all right\n");
  11421. break;
  11422. }
  11423. i=i+1;
  11424. }
  11425. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11426. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11427. filenametemp[i+1] = 0;
  11428. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11429. pch=strchr(temp,'@');
  11430. if(pch==NULL)
  11431. {
  11432. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11433. protocol, host, &port, path);
  11434. strcpy(user,"anonymous");
  11435. strcpy(password,"");
  11436. }
  11437. else
  11438. {
  11439. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11440. protocol, user, password, host, &port, path);
  11441. }
  11442. sscanf(host,"%[^/]%s",host1, path1);
  11443. sprintf(ftppath,"%s", path1);
  11444. //DEBUG_INFO("protocol =%s\n",protocol);
  11445. //DEBUG_INFO("user =%s\n",user);
  11446. //DEBUG_INFO("password =%s\n",password);
  11447. //DEBUG_INFO("host1 =%s\n",host1);
  11448. //DEBUG_INFO("port =%d\n",port);
  11449. //DEBUG_INFO("path1 =%s\n",path1);
  11450. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11451. //ftpFile(host, user, password, port, ftppath, fname);
  11452. //download firmware pthred
  11453. if(port == 0)
  11454. {
  11455. port = 21;
  11456. }
  11457. do
  11458. {
  11459. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11460. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11461. sleep(1);
  11462. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11463. if(!isSuccess)
  11464. {
  11465. //BulldogUtil.sleepMs(interval*1000);
  11466. DEBUG_INFO("Update firmware request and download file fail.\n");
  11467. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11468. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11469. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11470. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11471. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11472. }
  11473. else
  11474. {
  11475. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11476. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11477. }
  11478. retriesInt--;
  11479. }while((!isSuccess)&&(retriesInt >= 0));
  11480. }
  11481. else
  11482. {
  11483. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11484. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11485. sleep(1);
  11486. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11487. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11488. }
  11489. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  11490. pthread_exit(NULL);
  11491. }
  11492. int handleCertificateSignedRequest(char *uuid, char *payload)
  11493. {
  11494. mtrace();
  11495. int result = PASS;
  11496. json_object *CertificateSigned;
  11497. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11498. CertificateSigned = json_tokener_parse(payload);
  11499. if(!is_error(CertificateSigned))
  11500. {
  11501. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11502. }
  11503. json_object_put(CertificateSigned);
  11504. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  11505. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  11506. fclose(fp);
  11507. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11508. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  11509. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  11510. sendCertificateSignedConfirmation(uuid);
  11511. return result;
  11512. }
  11513. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11514. {
  11515. mtrace();
  11516. int result = PASS;
  11517. json_object *DeleteCertificate;
  11518. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11519. DeleteCertificate = json_tokener_parse(payload);
  11520. if(!is_error(DeleteCertificate))
  11521. {
  11522. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11523. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11524. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11525. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11526. }
  11527. json_object_put(DeleteCertificate);
  11528. /*
  11529. * TODO: Delete certificateSigned process
  11530. */
  11531. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  11532. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  11533. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  11534. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  11535. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  11536. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  11537. sendDeleteCertificateConfirmation(uuid);
  11538. return result;
  11539. }
  11540. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11541. {
  11542. mtrace();
  11543. int result = PASS;
  11544. json_object *ExtendedTriggerMessage;
  11545. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11546. ExtendedTriggerMessage = json_tokener_parse(payload);
  11547. if(!is_error(ExtendedTriggerMessage))
  11548. {
  11549. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11550. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11551. {
  11552. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11553. }
  11554. else
  11555. {
  11556. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  11557. }
  11558. }
  11559. json_object_put(ExtendedTriggerMessage);
  11560. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  11561. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  11562. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11563. {
  11564. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11565. }
  11566. else
  11567. {
  11568. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11569. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11570. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11571. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11572. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11573. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11574. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11575. {
  11576. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11577. }
  11578. else
  11579. {
  11580. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11581. }
  11582. }
  11583. sendExtendedTriggerMessageConfirmation(uuid);
  11584. //==========================
  11585. // Trigger message
  11586. //==========================
  11587. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11588. {
  11589. //sendBootNotificationRequest();
  11590. server_sign = FALSE;
  11591. }
  11592. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11593. {
  11594. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  11595. }
  11596. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11597. {
  11598. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11599. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11600. {
  11601. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11602. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11603. }
  11604. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11605. }
  11606. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11607. {
  11608. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11609. }
  11610. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11611. {
  11612. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11613. {
  11614. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11615. }
  11616. else
  11617. {
  11618. for(int idx=0;idx< gunTotalNumber;idx++)
  11619. {
  11620. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11621. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11622. }
  11623. }
  11624. }
  11625. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11626. {
  11627. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  11628. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  11629. {
  11630. system("openssl req -newkey rsa:2048 -out /Storage/OCPP/certCP.csr -nodes -keyout /Storage/OCPP/certCP.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  11631. }
  11632. }
  11633. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11634. {
  11635. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11636. {
  11637. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11638. }
  11639. else
  11640. {
  11641. for(int idx=0;idx< gunTotalNumber;idx++)
  11642. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11643. }
  11644. }
  11645. return result;
  11646. }
  11647. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11648. {
  11649. mtrace();
  11650. int result = PASS;
  11651. json_object *GetInstalledCertificateIds;
  11652. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11653. GetInstalledCertificateIds = json_tokener_parse(payload);
  11654. if(!is_error(GetInstalledCertificateIds))
  11655. {
  11656. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11657. }
  11658. json_object_put(GetInstalledCertificateIds);
  11659. /*
  11660. * TODO: Return installed certificate process
  11661. */
  11662. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11663. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  11664. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11665. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  11666. sendGetInstalledCertificateIdsConfirmation(uuid);
  11667. return result;
  11668. }
  11669. int handleGetLogRequest(char *uuid, char *payload)
  11670. {
  11671. mtrace();
  11672. int result = PASS;
  11673. json_object *GetLog;
  11674. DEBUG_INFO("handleGetLogRequest...\n");
  11675. GetLog = json_tokener_parse(payload);
  11676. if(!is_error(GetLog))
  11677. {
  11678. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11679. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11680. if(json_object_object_get(GetLog, "retries") != NULL)
  11681. {
  11682. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11683. }
  11684. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11685. {
  11686. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11687. }
  11688. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11689. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11690. {
  11691. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11692. }
  11693. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11694. {
  11695. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11696. }
  11697. }
  11698. json_object_put(GetLog);
  11699. /*
  11700. * TODO: Upload log process
  11701. */
  11702. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  11703. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  11704. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  11705. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  11706. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  11707. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  11708. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  11709. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  11710. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  11711. sendGetLogConfirmation(uuid);
  11712. return result;
  11713. }
  11714. int handleInstallCertificateRequest(char *uuid, char *payload)
  11715. {
  11716. mtrace();
  11717. int result = PASS;
  11718. json_object *InstallCertificate;
  11719. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11720. InstallCertificate = json_tokener_parse(payload);
  11721. if(!is_error(InstallCertificate))
  11722. {
  11723. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11724. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11725. /*
  11726. * TODO: Install certificate process
  11727. */
  11728. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  11729. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  11730. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  11731. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  11732. sendInstallCertificateConfirmation(uuid);
  11733. }
  11734. json_object_put(InstallCertificate);
  11735. return result;
  11736. }
  11737. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  11738. {
  11739. mtrace();
  11740. int result = PASS;
  11741. json_object *SignedUpdateFirmware;
  11742. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  11743. SignedUpdateFirmware = json_tokener_parse(payload);
  11744. if(!is_error(SignedUpdateFirmware))
  11745. {
  11746. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  11747. {
  11748. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  11749. }
  11750. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  11751. {
  11752. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  11753. }
  11754. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  11755. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  11756. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  11757. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  11758. {
  11759. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  11760. }
  11761. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  11762. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  11763. }
  11764. json_object_put(SignedUpdateFirmware);
  11765. /*
  11766. * TODO: Upgrade firmware process
  11767. */
  11768. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  11769. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  11770. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  11771. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  11772. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  11773. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  11774. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  11775. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  11776. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  11777. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  11778. sendInstallCertificateConfirmation(uuid);
  11779. return result;
  11780. }
  11781. int handleUnknownRequest(char *uuid, char *payload)
  11782. {
  11783. mtrace();
  11784. int result = PASS;
  11785. DEBUG_INFO("handleUnknownRequest...\n");
  11786. sendUnknownConfirmation(uuid);
  11787. result = PASS;
  11788. return result;
  11789. }
  11790. //==========================================
  11791. // Handle server response routine
  11792. //==========================================
  11793. void handleAuthorizeResponse(char *payload, int gun_index)
  11794. {
  11795. mtrace();
  11796. char expiryDatestr[30]={0};
  11797. char parentIdTagstr[20]={0};
  11798. char statusstr[20]={0};
  11799. int expiryDateISNULL=FALSE;
  11800. int parentIdTagISNULL=FALSE;
  11801. DEBUG_INFO("handleAuthorizeResponse...\n");
  11802. json_object *Authorize;
  11803. Authorize = json_tokener_parse(payload);
  11804. if(!is_error(Authorize))
  11805. {
  11806. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  11807. {
  11808. // Required data
  11809. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11810. // Optional data
  11811. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11812. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11813. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11814. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11815. }
  11816. }
  11817. json_object_put(Authorize);
  11818. if(expiryDateISNULL == FALSE)
  11819. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11820. if(parentIdTagISNULL == FALSE)
  11821. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11822. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  11823. //Update idTag information to authorization cache if supproted
  11824. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11825. {
  11826. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11827. }
  11828. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  11829. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11830. authorizeRetryTimes = 0;
  11831. }
  11832. void handleBootNotificationResponse(char *payload, int gun_index)
  11833. {
  11834. mtrace();
  11835. char statusStr[12]={0};
  11836. char currentTimeStr[30]={0};
  11837. int intervalInt = 0;
  11838. DEBUG_INFO("handleBootNotificationResponse...\n");
  11839. json_object *BootNotification;
  11840. BootNotification = json_tokener_parse(payload);
  11841. if(!is_error(BootNotification))
  11842. {
  11843. // Required data
  11844. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11845. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11846. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11847. }
  11848. json_object_put(BootNotification);
  11849. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11850. BootNotificationInterval = intervalInt;
  11851. HeartBeatWaitTime = intervalInt;
  11852. //write back to ShmOCPP16Data->BootNotification
  11853. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  11854. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11855. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  11856. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11857. {
  11858. server_sign = TRUE;
  11859. server_pending =FALSE;
  11860. }
  11861. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11862. {
  11863. server_pending = TRUE;
  11864. }
  11865. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  11866. srand(time(NULL));
  11867. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11868. SetOcppConnStatus(TRUE);
  11869. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  11870. }
  11871. void handleDataTransferResponse(char *payload, int gun_index)
  11872. {
  11873. char sstr[160]={0};//sstr[200]={ 0 };
  11874. int c = 0;
  11875. char *loc;
  11876. DEBUG_INFO("handleDataTransferResponse ...\n");
  11877. loc = strstr(payload, "status");
  11878. c = 0;
  11879. while (loc[3+strlen("status")+c] != '\"')
  11880. {
  11881. sstr[c] = loc[3+strlen("status")+c];
  11882. c++;
  11883. }
  11884. sstr[c] = '\0';
  11885. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11886. }
  11887. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11888. {
  11889. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11890. //struct json_object *obj;
  11891. // obj = json_tokener_parse(payload);
  11892. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11893. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11894. //No fields are defined.
  11895. }
  11896. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11897. {
  11898. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11899. //struct json_object *obj;
  11900. // obj = json_tokener_parse(payload);
  11901. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11902. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11903. //No fields are defined.
  11904. }
  11905. void handleHeartbeatResponse(char *payload, int gun_index)
  11906. {
  11907. mtrace();
  11908. DEBUG_INFO("handleHeartbeatResponse...\n");
  11909. json_object *Heartbeat;
  11910. Heartbeat = json_tokener_parse(payload);
  11911. if(!is_error(Heartbeat))
  11912. {
  11913. // Required data
  11914. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11915. }
  11916. json_object_put(Heartbeat);
  11917. if(FirstHeartBeat == 0)
  11918. {
  11919. FirstHeartBeat = 1;
  11920. DEBUG_INFO("FirstHeartBeat \n");
  11921. }
  11922. HeartBeatWithNOResponse = 0;
  11923. clientTime.Heartbeat=time((time_t*)NULL);
  11924. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  11925. }
  11926. void handleMeterValuesResponse(char *payload, int gun_index)
  11927. {
  11928. mtrace();
  11929. DEBUG_INFO("handleMeterValuesResponse...\n");
  11930. }
  11931. void handleStartTransactionResponse(char *payload, int gun_index)
  11932. {
  11933. mtrace();
  11934. //int transactionIdInt = 0;
  11935. FILE *outfile;
  11936. char data[100]={0};
  11937. DEBUG_INFO("handleStartTransactionResponse...\n");
  11938. json_object *StartTransaction;
  11939. StartTransaction = json_tokener_parse(payload);
  11940. if(!is_error(StartTransaction))
  11941. {
  11942. // Required data
  11943. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11944. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11945. // Optional data
  11946. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11947. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11948. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11949. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11950. }
  11951. json_object_put(StartTransaction);
  11952. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11953. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11954. //-----------Start : write to the Queue TransactionId file -----------------//
  11955. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  11956. {}
  11957. else
  11958. {
  11959. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  11960. if(log == NULL)
  11961. {
  11962. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11963. return ;
  11964. }
  11965. else
  11966. {
  11967. fclose(log);
  11968. }
  11969. }
  11970. // open file for writing
  11971. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11972. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  11973. {
  11974. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  11975. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11976. fputs(data, outfile);
  11977. fclose (outfile);
  11978. }
  11979. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11980. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11981. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11982. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  11983. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11984. }
  11985. void handleStatusNotificationResponse(char *payload, int gun_index)
  11986. {
  11987. mtrace();
  11988. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11989. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  11990. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11991. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11992. }
  11993. void handleStopTransactionnResponse(char *payload, int gun_index)
  11994. {
  11995. mtrace();
  11996. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11997. json_object *StopTransaction;
  11998. StopTransaction = json_tokener_parse(payload);
  11999. if(!is_error(StopTransaction))
  12000. {
  12001. // Optional data
  12002. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12003. {
  12004. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12005. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12006. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12007. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12008. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12009. }
  12010. }
  12011. json_object_put(StopTransaction);
  12012. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12013. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12014. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12015. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12016. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12017. }
  12018. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12019. {
  12020. mtrace();
  12021. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12022. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  12023. }
  12024. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12025. {
  12026. mtrace();
  12027. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12028. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  12029. }
  12030. void handleSignCertificateResponse(char *payload, int gun_index)
  12031. {
  12032. mtrace();
  12033. DEBUG_INFO("handleSignCertificateResponse...\n");
  12034. json_object *SignCertificate;
  12035. SignCertificate = json_tokener_parse(payload);
  12036. if(!is_error(SignCertificate))
  12037. {
  12038. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12039. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  12040. }
  12041. json_object_put(SignCertificate);
  12042. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  12043. }
  12044. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12045. {
  12046. mtrace();
  12047. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12048. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12049. }
  12050. //==========================================
  12051. // Handle Error routine
  12052. //==========================================
  12053. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12054. {
  12055. mtrace();
  12056. #ifdef SystemLogMessage
  12057. DEBUG_INFO("errorCode: %s\n", errorCode);
  12058. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12059. DEBUG_INFO("errorDetails: %s\n", payload);
  12060. #endif
  12061. }
  12062. //===============================================
  12063. // Common routine
  12064. //===============================================
  12065. int initialConfigurationTable(void)
  12066. {
  12067. //clock_t start_t, end_t, total_t;
  12068. FILE *fp;
  12069. FILE *outfile;
  12070. char str[512]={0};
  12071. char sstr[256]={0};
  12072. int c = 0;
  12073. char *loc;
  12074. int confVersion = 6;
  12075. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12076. //start_t = clock();
  12077. //printf("Starting of the program, start_t = %ld\n", start_t);
  12078. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12079. // Check configuration file size is correct
  12080. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  12081. {
  12082. struct stat st;
  12083. stat("/Storage/OCPP/OCPPConfiguration", &st);
  12084. if(st.st_size < 3100)
  12085. {
  12086. system("rm -f /Storage/OCPP/OCPPConfiguration");
  12087. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12088. }
  12089. }
  12090. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  12091. {
  12092. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12093. if(outfile == NULL)
  12094. {
  12095. DEBUG_INFO("Error opening file\n");
  12096. return FALSE;
  12097. }
  12098. /*Core Profile*/
  12099. //AllowOfflineTxForUnknownId
  12100. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12104. //AuthorizationCacheEnabled
  12105. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12109. //AuthorizeRemoteTxRequests
  12110. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12114. //BlinkRepeat
  12115. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12119. //ClockAlignedDataInterval
  12120. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12123. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12124. //ConnectionTimeOut
  12125. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12129. //GetConfigurationMaxKeys
  12130. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12132. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12133. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12134. // HeartbeatInterval
  12135. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12139. // LightIntensity
  12140. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12144. // LocalAuthorizeOffline
  12145. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12149. // LocalPreAuthorize
  12150. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12154. // MaxEnergyOnInvalidId
  12155. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12158. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12159. // MeterValuesAlignedData
  12160. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12162. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  12164. else
  12165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12167. // MeterValuesAlignedDataMaxLength
  12168. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12170. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  12172. else
  12173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  12174. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12175. // MeterValuesSampledData
  12176. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12178. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  12180. else
  12181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12182. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12183. // MeterValuesSampledDataMaxLength
  12184. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12186. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  12188. else
  12189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  12190. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12191. // MeterValueSampleInterval
  12192. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  12195. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12196. // MinimumStatusDuration
  12197. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  12200. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  12201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12202. // NumberOfConnectors
  12203. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12205. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12206. {
  12207. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12208. }
  12209. else
  12210. {
  12211. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12212. }
  12213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12214. // ResetRetries
  12215. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12218. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12219. // ConnectorPhaseRotation
  12220. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12223. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12224. // ConnectorPhaseRotationMaxLength
  12225. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12228. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12229. // StopTransactionOnEVSideDisconnect
  12230. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12234. // StopTransactionOnInvalidId
  12235. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12238. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12239. // StopTxnAlignedData
  12240. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12243. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12244. // StopTxnAlignedDataMaxLength
  12245. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12248. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12249. // StopTxnSampledData
  12250. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12252. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  12254. else
  12255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12256. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12257. // StopTxnSampledDataMaxLength
  12258. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12260. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12261. {
  12262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12263. }
  12264. else
  12265. {
  12266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12267. }
  12268. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12269. // SupportedFeatureProfiles
  12270. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12273. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12274. // SupportedFeatureProfilesMaxLength
  12275. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12278. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12279. // TransactionMessageAttempts
  12280. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12283. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12285. // TransactionMessageRetryInterval
  12286. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12289. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12290. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12291. // UnlockConnectorOnEVSideDisconnect
  12292. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12295. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12296. // WebSocketPingInterval
  12297. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12300. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12301. // QueueOffLineStartTransactionMessage
  12302. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  12303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12305. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12306. // AuthorizationKey
  12307. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12310. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12311. // SecurityProfile
  12312. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12314. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12315. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12316. // DefaultPrice
  12317. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12321. // CustomDisplayCostAndPrice
  12322. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12326. // CustomIdleFeeAfterStop
  12327. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12331. // TimeOffset
  12332. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  12333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  12334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  12335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  12336. // NextTimeOffsetTransitionDateTime
  12337. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  12338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  12339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  12340. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  12341. // TimeOffsetNextTransition
  12342. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  12343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  12344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  12345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  12346. // Configuration Version
  12347. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12349. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12350. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12351. //* Local Auth List Management Profile*/
  12352. #if 0
  12353. //For OCTT Test Case
  12354. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12357. #endif
  12358. #if 1
  12359. //LocalAuthListEnabled
  12360. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12363. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12364. #endif
  12365. //LocalAuthListMaxLength
  12366. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  12369. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12370. //SendLocalListMaxLength
  12371. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12375. //ReserveConnectorZeroSupported
  12376. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12380. //* Smart Charging Profile */
  12381. //ChargeProfileMaxStackLevel
  12382. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12385. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12386. // ChargingScheduleAllowedChargingRateUnit
  12387. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12390. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12391. // ChargingScheduleMaxPeriods
  12392. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12395. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12396. // ConnectorSwitch3to1PhaseSupported
  12397. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12400. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12401. // MaxChargingProfilesInstalled
  12402. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12405. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12406. fclose(outfile);
  12407. }
  12408. else
  12409. {
  12410. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  12411. char keystr[60]={0};
  12412. char readonlystr[10]={0};
  12413. char valuestr[256]={0};
  12414. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  12415. if(fp == NULL) {
  12416. DEBUG_INFO("Error opening file");
  12417. return FALSE;
  12418. }
  12419. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12420. {
  12421. //DEBUG_INFO("Get Configuration \n");
  12422. if(strlen(str) > 0)
  12423. {
  12424. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12425. //*************************key*********************************/
  12426. if(strstr(str, "key") != NULL)
  12427. {
  12428. loc = strstr(str, "key");
  12429. c = 0;
  12430. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12431. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12432. {
  12433. sstr[c] = loc[strlen("key")+3+c];
  12434. c++;
  12435. }
  12436. sstr[c] = '\0';
  12437. strcpy(keystr,sstr);
  12438. }
  12439. //*************************readonly*********************************/
  12440. if(strstr(str, "readonly") != NULL)
  12441. {
  12442. loc = strstr(str, "readonly");
  12443. c = 0;
  12444. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12445. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12446. {
  12447. sstr[c] = loc[strlen("readonly")+2+c];
  12448. c++;
  12449. }
  12450. sstr[c] = '\0';
  12451. strcpy(readonlystr,sstr);
  12452. }
  12453. //*************************value*********************************/
  12454. if(strstr(str, "value") != NULL)
  12455. {
  12456. loc = strstr(str, "value");
  12457. c = 0;
  12458. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12459. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12460. {
  12461. sstr[c] = loc[strlen("value")+3+c];
  12462. c++;
  12463. }
  12464. sstr[c] = '\0';
  12465. strcpy(valuestr,sstr);
  12466. }
  12467. // DEBUG_INFO("keystr=%s\n",keystr);
  12468. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12469. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12470. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12471. {
  12472. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12473. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12475. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12476. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12477. }
  12478. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12479. {
  12480. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12481. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12482. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12483. }
  12484. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12485. {
  12486. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12487. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12488. }
  12489. if(strcmp(keystr, "BlinkRepeat") == 0)
  12490. {
  12491. //Charger.BlinkRepeat = Integer.parseInt(value);
  12492. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12494. }
  12495. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12496. {
  12497. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12498. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12499. }
  12500. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12501. {
  12502. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12503. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12504. }
  12505. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12506. {
  12507. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12508. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12509. }
  12510. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12511. {
  12512. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12513. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12514. HeartBeatWaitTime = atoi(valuestr);
  12515. }
  12516. if(strcmp(keystr, "LightIntensity") == 0)
  12517. {
  12518. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12519. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12520. }
  12521. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12522. {
  12523. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12524. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12525. }
  12526. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12527. {
  12528. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12529. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12530. }
  12531. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12532. {
  12533. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12534. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12535. }
  12536. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12537. {
  12538. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12539. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12540. }
  12541. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12542. {
  12543. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12544. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12545. }
  12546. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12547. {
  12548. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12549. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12550. }
  12551. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12552. {
  12553. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12554. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12555. }
  12556. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12557. {
  12558. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12559. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12560. }
  12561. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12562. {
  12563. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12564. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12565. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12566. }
  12567. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12568. {
  12569. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12570. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12571. }
  12572. if(strcmp(keystr, "ResetRetries") == 0)
  12573. {
  12574. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12575. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12576. }
  12577. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12578. {
  12579. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12580. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12581. }
  12582. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12583. {
  12584. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12586. }
  12587. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12588. {
  12589. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12591. }
  12592. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12593. {
  12594. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12595. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12596. }
  12597. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12598. {
  12599. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12600. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12601. }
  12602. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12603. {
  12604. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12606. }
  12607. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12608. {
  12609. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12610. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12611. }
  12612. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12613. {
  12614. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12615. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12616. }
  12617. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12618. {
  12619. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12620. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12621. }
  12622. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12623. {
  12624. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12625. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12626. }
  12627. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12628. {
  12629. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12630. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12631. TransactionMessageAttemptsValue = atoi(valuestr);
  12632. }
  12633. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12634. {
  12635. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12637. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12638. }
  12639. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12640. {
  12641. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12642. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12643. }
  12644. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12645. {
  12646. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12647. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12648. }
  12649. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  12650. {
  12651. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12652. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  12653. }
  12654. if(strcmp(keystr, "AuthorizationKey") == 0)
  12655. {
  12656. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12657. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12658. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12659. }
  12660. if(strcmp(keystr, "SecurityProfile") == 0)
  12661. {
  12662. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12664. }
  12665. if(strcmp(keystr, "DefaultPrice") == 0)
  12666. {
  12667. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12668. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12669. }
  12670. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12671. {
  12672. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12673. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12674. }
  12675. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12676. {
  12677. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12679. }
  12680. if(strcmp(keystr, "TimeOffset") == 0)
  12681. {
  12682. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  12684. }
  12685. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  12686. {
  12687. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  12689. }
  12690. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  12691. {
  12692. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12693. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  12694. }
  12695. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12696. {
  12697. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12698. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12699. }
  12700. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12701. {
  12702. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12704. }
  12705. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  12706. {
  12707. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  12709. }
  12710. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  12711. {
  12712. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  12714. }
  12715. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  12716. {
  12717. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12718. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  12719. }
  12720. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  12721. {
  12722. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  12724. }
  12725. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12726. {
  12727. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12728. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  12729. }
  12730. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  12731. {
  12732. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12733. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  12734. }
  12735. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  12736. {
  12737. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12738. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  12739. }
  12740. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  12741. {
  12742. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12743. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  12744. }
  12745. }
  12746. }
  12747. fclose(fp);
  12748. }
  12749. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  12750. {
  12751. return PASS;
  12752. }
  12753. else
  12754. {
  12755. return FAIL;
  12756. }
  12757. }
  12758. void StoreConfigurationTable(void)
  12759. {
  12760. FILE *outfile;
  12761. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12762. if(outfile == NULL)
  12763. {
  12764. DEBUG_INFO("Error opening file");
  12765. return ;
  12766. }
  12767. /*Core Profile*/
  12768. //AllowOfflineTxForUnknownId
  12769. /*
  12770. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12771. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  12772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  12774. */
  12775. //DEBUG_INFO("data=%s\n",data);
  12776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12777. //AuthorizationCacheEnabled
  12778. /*
  12779. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12782. */
  12783. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12784. //AuthorizeRemoteTxRequests
  12785. /*
  12786. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  12789. */
  12790. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12791. //BlinkRepeat
  12792. /*
  12793. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12796. */
  12797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12798. //ClockAlignedDataInterval
  12799. /*
  12800. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12803. */
  12804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12805. //ConnectionTimeOut
  12806. /*
  12807. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12810. */
  12811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12812. //GetConfigurationMaxKeys
  12813. /*
  12814. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  12817. */
  12818. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12819. // HeartbeatInterval
  12820. /*
  12821. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  12824. */
  12825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12826. // LightIntensity
  12827. /*
  12828. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12831. */
  12832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12833. // LocalAuthorizeOffline
  12834. /*
  12835. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  12836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12838. */
  12839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12840. // LocalPreAuthorize
  12841. /*
  12842. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12845. */
  12846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12847. // MaxEnergyOnInvalidId
  12848. /*
  12849. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12852. */
  12853. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12855. // MeterValuesAlignedData
  12856. /*
  12857. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12860. */
  12861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12862. // MeterValuesAlignedDataMaxLength
  12863. /*
  12864. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12867. */
  12868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12869. // MeterValuesSampledData
  12870. /*
  12871. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12874. */
  12875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12876. // MeterValuesSampledDataMaxLength
  12877. /*
  12878. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12880. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12881. */
  12882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12883. // MeterValueSampleInterval
  12884. /*
  12885. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12888. */
  12889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12890. // MinimumStatusDuration
  12891. /*
  12892. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12895. */
  12896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12897. // NumberOfConnectors
  12898. /*
  12899. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12901. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12902. {
  12903. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12904. }
  12905. else
  12906. {
  12907. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12908. }
  12909. */
  12910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12911. // ResetRetries
  12912. /*
  12913. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12916. */
  12917. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12918. // ConnectorPhaseRotation
  12919. /*
  12920. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12923. */
  12924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12925. // ConnectorPhaseRotationMaxLength
  12926. /*
  12927. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12930. */
  12931. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12932. // StopTransactionOnEVSideDisconnect
  12933. /*
  12934. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12937. */
  12938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12939. // StopTransactionOnInvalidId
  12940. /*
  12941. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12944. */
  12945. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12946. // StopTxnAlignedData
  12947. /*
  12948. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12949. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12951. */
  12952. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12953. // StopTxnAlignedDataMaxLength
  12954. /*
  12955. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12958. */
  12959. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12960. // StopTxnSampledData
  12961. /*
  12962. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12965. */
  12966. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12967. // StopTxnSampledDataMaxLength
  12968. /*
  12969. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12972. */
  12973. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12974. // SupportedFeatureProfiles
  12975. /*
  12976. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12979. */
  12980. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12981. // SupportedFeatureProfilesMaxLength
  12982. /*
  12983. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12986. */
  12987. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12988. // TransactionMessageAttempts
  12989. /*
  12990. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12993. */
  12994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12995. // TransactionMessageRetryInterval
  12996. /*
  12997. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13000. */
  13001. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13002. // UnlockConnectorOnEVSideDisconnect
  13003. /*
  13004. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13007. */
  13008. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13009. // WebSocketPingInterval
  13010. /*
  13011. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13014. */
  13015. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13016. // QueueOffLineStartTransactionMessage
  13017. /*
  13018. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  13019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  13020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  13021. */
  13022. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  13023. // AuthorizationKey
  13024. /*
  13025. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13028. */
  13029. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13030. // SecurityProfile
  13031. /*
  13032. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13035. */
  13036. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13037. // DefaultPrice
  13038. /*
  13039. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13042. */
  13043. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13044. // CustomDisplayCostAndPrice
  13045. /*
  13046. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13049. */
  13050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13051. // CustomIdleFeeAfterStop
  13052. /*
  13053. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13056. */
  13057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13058. // TimeOffset
  13059. /*
  13060. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  13063. */
  13064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13065. // NextTimeOffsetTransitionDateTime
  13066. /*
  13067. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  13070. */
  13071. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13072. // TimeOffsetNextTransition
  13073. /*
  13074. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  13077. */
  13078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13079. // ConfigurationVersion
  13080. /*
  13081. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13084. */
  13085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13086. //* Local Auth List Management Profile*/
  13087. //LocalAuthListEnabled
  13088. /*
  13089. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13092. */
  13093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13094. //LocalAuthListMaxLength
  13095. /*
  13096. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13099. */
  13100. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13101. //SendLocalListMaxLength
  13102. /*
  13103. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13106. */
  13107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13108. //ReserveConnectorZeroSupported
  13109. /*
  13110. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13113. */
  13114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13115. //* Smart Charging Profile */
  13116. //ChargeProfileMaxStackLevel
  13117. /*
  13118. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13121. */
  13122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13123. // ChargingScheduleAllowedChargingRateUnit
  13124. /*
  13125. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13128. */
  13129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13130. // ChargingScheduleMaxPeriods
  13131. /*
  13132. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13135. */
  13136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13137. // ConnectorSwitch3to1PhaseSupported
  13138. /*
  13139. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13142. */
  13143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13144. // MaxChargingProfilesInstalled
  13145. /*
  13146. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13149. */
  13150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13151. fclose(outfile);
  13152. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13153. }
  13154. void getKeyValue(char *keyReq)
  13155. {
  13156. int isEmpty = FALSE;
  13157. int isKnowKey = FALSE;
  13158. DEBUG_INFO("keyReq = %s\n", keyReq);
  13159. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13160. isEmpty = TRUE;
  13161. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13162. {
  13163. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13165. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13166. {
  13167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13168. }
  13169. else
  13170. {
  13171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13172. }
  13173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13174. isKnowKey = TRUE;
  13175. }
  13176. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13177. {
  13178. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13180. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13181. {
  13182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13183. }
  13184. else
  13185. {
  13186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13187. }
  13188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13189. isKnowKey = TRUE;
  13190. }
  13191. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13192. {
  13193. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13195. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13196. {
  13197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13198. }
  13199. else
  13200. {
  13201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13202. }
  13203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13204. isKnowKey = TRUE;
  13205. }
  13206. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13207. {
  13208. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  13209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  13210. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13211. {
  13212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  13213. }
  13214. else
  13215. {
  13216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  13217. }
  13218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  13219. isKnowKey = TRUE;
  13220. }
  13221. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  13222. {
  13223. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  13224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  13225. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13226. {
  13227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  13228. }
  13229. else
  13230. {
  13231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  13232. }
  13233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  13234. isKnowKey = TRUE;
  13235. }
  13236. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  13237. {
  13238. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  13239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  13240. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13241. {
  13242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  13243. }
  13244. else
  13245. {
  13246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  13247. }
  13248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  13249. isKnowKey = TRUE;
  13250. }
  13251. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  13252. {
  13253. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  13254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  13255. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13256. {
  13257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  13258. }
  13259. else
  13260. {
  13261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  13262. }
  13263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  13264. isKnowKey = TRUE;
  13265. }
  13266. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13267. {
  13268. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13270. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13271. {
  13272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13273. }
  13274. else
  13275. {
  13276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13277. }
  13278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13279. isKnowKey = TRUE;
  13280. }
  13281. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13282. {
  13283. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13285. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13286. {
  13287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13288. }
  13289. else
  13290. {
  13291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13292. }
  13293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13294. isKnowKey = TRUE;
  13295. }
  13296. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13297. {
  13298. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13300. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13301. {
  13302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13303. }
  13304. else
  13305. {
  13306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13307. }
  13308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13309. isKnowKey = TRUE;
  13310. }
  13311. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13312. {
  13313. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13316. {
  13317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13318. }
  13319. else
  13320. {
  13321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13322. }
  13323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13324. isKnowKey = TRUE;
  13325. }
  13326. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13327. {
  13328. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13330. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13331. {
  13332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13333. }
  13334. else
  13335. {
  13336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13337. }
  13338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13339. isKnowKey = TRUE;
  13340. }
  13341. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13342. {
  13343. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13345. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13346. {
  13347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13348. }
  13349. else
  13350. {
  13351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13352. }
  13353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13354. isKnowKey = TRUE;
  13355. }
  13356. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13357. {
  13358. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13360. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13361. {
  13362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13363. }
  13364. else
  13365. {
  13366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13367. }
  13368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13369. isKnowKey = TRUE;
  13370. }
  13371. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13372. {
  13373. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13375. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13376. {
  13377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13378. }
  13379. else
  13380. {
  13381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13382. }
  13383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13384. isKnowKey = TRUE;
  13385. }
  13386. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13387. {
  13388. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13390. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13391. {
  13392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13393. }
  13394. else
  13395. {
  13396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13397. }
  13398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13399. isKnowKey = TRUE;
  13400. }
  13401. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13402. {
  13403. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13405. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13406. {
  13407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13408. }
  13409. else
  13410. {
  13411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13412. }
  13413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13414. isKnowKey = TRUE;
  13415. }
  13416. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13417. {
  13418. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13420. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13421. {
  13422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13423. }
  13424. else
  13425. {
  13426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13427. }
  13428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  13429. isKnowKey = TRUE;
  13430. }
  13431. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13432. {
  13433. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13435. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13436. {
  13437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13438. }
  13439. else
  13440. {
  13441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13442. }
  13443. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13445. isKnowKey = TRUE;
  13446. }
  13447. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13448. {
  13449. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13451. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13452. {
  13453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13454. }
  13455. else
  13456. {
  13457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13458. }
  13459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13460. isKnowKey = TRUE;
  13461. }
  13462. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13463. {
  13464. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13466. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13467. {
  13468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13469. }
  13470. else
  13471. {
  13472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13473. }
  13474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13475. isKnowKey = TRUE;
  13476. }
  13477. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13478. {
  13479. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13481. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13482. {
  13483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13484. }
  13485. else
  13486. {
  13487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13488. }
  13489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13490. isKnowKey = TRUE;
  13491. }
  13492. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13493. {
  13494. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13496. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13497. {
  13498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13499. }
  13500. else
  13501. {
  13502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13503. }
  13504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13505. isKnowKey = TRUE;
  13506. }
  13507. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13508. {
  13509. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13511. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13512. {
  13513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13514. }
  13515. else
  13516. {
  13517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13518. }
  13519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13520. isKnowKey = TRUE;
  13521. }
  13522. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13523. {
  13524. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13526. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13527. {
  13528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13529. }
  13530. else
  13531. {
  13532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13533. }
  13534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13535. isKnowKey = TRUE;
  13536. }
  13537. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13538. {
  13539. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13541. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13542. {
  13543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13544. }
  13545. else
  13546. {
  13547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13548. }
  13549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13550. isKnowKey = TRUE;
  13551. }
  13552. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13553. {
  13554. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13556. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13557. {
  13558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13559. }
  13560. else
  13561. {
  13562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13563. }
  13564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13565. isKnowKey = TRUE;
  13566. }
  13567. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13568. {
  13569. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13571. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13572. {
  13573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13574. }
  13575. else
  13576. {
  13577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13578. }
  13579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13580. isKnowKey = TRUE;
  13581. }
  13582. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13583. {
  13584. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13586. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13587. {
  13588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13589. }
  13590. else
  13591. {
  13592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13593. }
  13594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13595. isKnowKey = TRUE;
  13596. }
  13597. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13598. {
  13599. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13602. {
  13603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13604. }
  13605. else
  13606. {
  13607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13608. }
  13609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13610. isKnowKey = TRUE;
  13611. }
  13612. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13613. {
  13614. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13616. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13617. {
  13618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13619. }
  13620. else
  13621. {
  13622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13623. }
  13624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13625. isKnowKey = TRUE;
  13626. }
  13627. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13628. {
  13629. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13631. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13632. {
  13633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13634. }
  13635. else
  13636. {
  13637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13638. }
  13639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13640. isKnowKey = TRUE;
  13641. }
  13642. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13643. {
  13644. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13646. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13647. {
  13648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13649. }
  13650. else
  13651. {
  13652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13653. }
  13654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13655. isKnowKey = TRUE;
  13656. }
  13657. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13658. {
  13659. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13661. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13662. {
  13663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13664. }
  13665. else
  13666. {
  13667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13668. }
  13669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13670. isKnowKey = TRUE;
  13671. }
  13672. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  13673. {
  13674. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  13675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  13676. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13677. {
  13678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  13679. }
  13680. else
  13681. {
  13682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  13683. }
  13684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  13685. isKnowKey = TRUE;
  13686. }
  13687. /*
  13688. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13689. {
  13690. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13692. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13693. {
  13694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13695. }
  13696. else
  13697. {
  13698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13699. }
  13700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13701. isKnowKey = TRUE;
  13702. }*/
  13703. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13704. {
  13705. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  13706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  13707. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13708. {
  13709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  13710. }
  13711. else
  13712. {
  13713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  13714. }
  13715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  13716. isKnowKey = TRUE;
  13717. }
  13718. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  13719. {
  13720. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  13721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  13722. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  13723. {
  13724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  13725. }
  13726. else
  13727. {
  13728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  13729. }
  13730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  13731. isKnowKey = TRUE;
  13732. }
  13733. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  13734. {
  13735. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  13736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  13737. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13738. {
  13739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  13740. }
  13741. else
  13742. {
  13743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  13744. }
  13745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  13746. isKnowKey = TRUE;
  13747. }
  13748. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  13749. {
  13750. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  13751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  13752. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13753. {
  13754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  13755. }
  13756. else
  13757. {
  13758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  13759. }
  13760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  13761. isKnowKey = TRUE;
  13762. }
  13763. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  13764. {
  13765. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  13766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  13767. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  13768. {
  13769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  13770. }
  13771. else
  13772. {
  13773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  13774. }
  13775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  13776. isKnowKey = TRUE;
  13777. }
  13778. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  13779. {
  13780. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  13781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  13782. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  13783. {
  13784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  13785. }
  13786. else
  13787. {
  13788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  13789. }
  13790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  13791. isKnowKey = TRUE;
  13792. }
  13793. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  13794. {
  13795. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  13796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  13797. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  13798. {
  13799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  13800. }
  13801. else
  13802. {
  13803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  13804. }
  13805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  13806. isKnowKey = TRUE;
  13807. }
  13808. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  13809. {
  13810. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  13811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  13812. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  13813. {
  13814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  13815. }
  13816. else
  13817. {
  13818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  13819. }
  13820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  13821. isKnowKey = TRUE;
  13822. }
  13823. #if 1
  13824. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  13825. {
  13826. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  13827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  13828. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13829. {
  13830. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  13831. }
  13832. else
  13833. {
  13834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  13835. }
  13836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  13837. isKnowKey = TRUE;
  13838. }
  13839. #endif
  13840. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  13841. {
  13842. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  13843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  13844. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13845. {
  13846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13847. }
  13848. else
  13849. {
  13850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13851. }
  13852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  13853. isKnowKey = TRUE;
  13854. }
  13855. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  13856. {
  13857. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  13858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  13859. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13860. {
  13861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13862. }
  13863. else
  13864. {
  13865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13866. }
  13867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  13868. isKnowKey = TRUE;
  13869. }
  13870. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  13871. {
  13872. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  13873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  13874. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13875. {
  13876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  13877. }
  13878. else
  13879. {
  13880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  13881. }
  13882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13883. isKnowKey = TRUE;
  13884. }
  13885. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  13886. {
  13887. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  13888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  13889. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13890. {
  13891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  13892. }
  13893. else
  13894. {
  13895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  13896. }
  13897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13898. isKnowKey = TRUE;
  13899. }
  13900. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  13901. {
  13902. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  13903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  13904. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13905. {
  13906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  13907. }
  13908. else
  13909. {
  13910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13911. }
  13912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13913. isKnowKey = TRUE;
  13914. }
  13915. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13916. {
  13917. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13919. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13920. {
  13921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13922. }
  13923. else
  13924. {
  13925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13926. }
  13927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13928. isKnowKey = TRUE;
  13929. }
  13930. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13931. {
  13932. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13934. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13935. {
  13936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13937. }
  13938. else
  13939. {
  13940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13941. }
  13942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13943. isKnowKey = TRUE;
  13944. }
  13945. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13946. {
  13947. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13949. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13950. {
  13951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13952. }
  13953. else
  13954. {
  13955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13956. }
  13957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13958. isKnowKey = TRUE;
  13959. }
  13960. //=========================================================
  13961. if(!isEmpty && !isKnowKey)
  13962. {
  13963. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13964. strcpy(unknownkey[UnknownKeynum], keyReq);
  13965. UnknownKeynum = UnknownKeynum + 1;
  13966. }
  13967. }
  13968. void processUnkownKey(void)
  13969. {
  13970. DEBUG_INFO("processUnkownKey...\n");
  13971. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13972. for(int index=0; index < UnknownKeynum; index++)
  13973. {
  13974. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13975. {
  13976. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13977. }
  13978. }
  13979. }
  13980. int setKeyValue(char *key, char *value)
  13981. {
  13982. int isSuccess = NotSupported;
  13983. int check_ascii=0;
  13984. char str[256]={0};
  13985. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13986. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13987. {
  13988. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13989. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13990. {
  13991. strcpy(str, (const char*)value);
  13992. for(int i = 0; str[i]; i++){
  13993. str[i] = tolower(str[i]);
  13994. }
  13995. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13996. isSuccess = ConfigurationStatus_Accepted;
  13997. }
  13998. else
  13999. {
  14000. isSuccess = ConfigurationStatus_Rejected;
  14001. }
  14002. }
  14003. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  14004. {
  14005. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14006. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14007. {
  14008. strcpy(str, (const char*)value);
  14009. for(int i = 0; str[i]; i++){
  14010. str[i] = tolower(str[i]);
  14011. }
  14012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14013. isSuccess = ConfigurationStatus_Accepted;
  14014. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  14015. }
  14016. else
  14017. {
  14018. isSuccess = ConfigurationStatus_Rejected;
  14019. }
  14020. }
  14021. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  14022. {
  14023. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14024. {
  14025. strcpy(str, (const char*)value);
  14026. for(int i = 0; str[i]; i++)
  14027. {
  14028. str[i] = tolower(str[i]);
  14029. }
  14030. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  14031. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14032. isSuccess = ConfigurationStatus_Accepted;
  14033. }
  14034. else
  14035. {
  14036. isSuccess = ConfigurationStatus_Rejected;
  14037. }
  14038. }
  14039. if(strcmp(key, "BlinkRepeat") == 0)
  14040. {
  14041. //Charger.BlinkRepeat = Integer.parseInt(value);
  14042. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14043. {
  14044. check_ascii = value[0];
  14045. if( (check_ascii < 48) || (check_ascii > 57) )
  14046. {
  14047. isSuccess = ConfigurationStatus_Rejected;
  14048. }
  14049. else
  14050. {
  14051. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14052. isSuccess = ConfigurationStatus_Accepted;
  14053. }
  14054. }
  14055. else
  14056. {
  14057. isSuccess = ConfigurationStatus_Rejected;
  14058. }
  14059. }
  14060. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14061. {
  14062. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14063. {
  14064. check_ascii = value[0];
  14065. if( (check_ascii < 48) || (check_ascii > 57) )
  14066. {
  14067. isSuccess = ConfigurationStatus_Rejected;
  14068. }
  14069. else
  14070. {
  14071. if((atoi(value) == 0) || (atoi(value) >= 10))
  14072. {
  14073. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14074. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14075. isSuccess = ConfigurationStatus_Accepted;
  14076. }
  14077. else
  14078. isSuccess = ConfigurationStatus_Rejected;
  14079. }
  14080. }
  14081. else
  14082. {
  14083. isSuccess = ConfigurationStatus_Rejected;
  14084. }
  14085. }
  14086. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14087. {
  14088. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14089. {
  14090. check_ascii = value[0];
  14091. if( (check_ascii < 48) || (check_ascii > 57) )
  14092. {
  14093. isSuccess = ConfigurationStatus_Rejected;
  14094. }
  14095. else
  14096. {
  14097. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14098. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14099. isSuccess = ConfigurationStatus_Accepted;
  14100. }
  14101. }
  14102. else
  14103. {
  14104. isSuccess = ConfigurationStatus_Rejected;
  14105. }
  14106. }
  14107. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14108. {
  14109. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14110. {
  14111. check_ascii = value[0];
  14112. if( (check_ascii < 48) || (check_ascii > 57) )
  14113. {
  14114. isSuccess = ConfigurationStatus_Rejected;
  14115. }
  14116. else
  14117. {
  14118. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14119. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14120. isSuccess = ConfigurationStatus_Accepted;
  14121. }
  14122. }
  14123. else
  14124. {
  14125. isSuccess = ConfigurationStatus_Rejected;
  14126. }
  14127. }
  14128. if(strcmp(key, "HeartbeatInterval") == 0)
  14129. {
  14130. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14131. {
  14132. check_ascii = value[0];
  14133. if( (check_ascii < 48) || (check_ascii > 57) )
  14134. {
  14135. isSuccess = ConfigurationStatus_Rejected;
  14136. }
  14137. else
  14138. {
  14139. if((atoi(value) == 0) || (atoi(value) >= 10))
  14140. {
  14141. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14142. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  14143. HeartBeatWaitTime = atoi(value);
  14144. isSuccess = ConfigurationStatus_Accepted;
  14145. }
  14146. else
  14147. {
  14148. isSuccess = ConfigurationStatus_Rejected;
  14149. }
  14150. }
  14151. }
  14152. else
  14153. {
  14154. isSuccess = ConfigurationStatus_Rejected;
  14155. }
  14156. }
  14157. if(strcmp(key, "LightIntensity") == 0)
  14158. {
  14159. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14160. {
  14161. check_ascii = value[0];
  14162. if( (check_ascii < 48) || (check_ascii > 57) )
  14163. {
  14164. isSuccess = ConfigurationStatus_Rejected;
  14165. }
  14166. else
  14167. {
  14168. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14169. isSuccess = ConfigurationStatus_Accepted;
  14170. }
  14171. }
  14172. else
  14173. {
  14174. isSuccess = ConfigurationStatus_Rejected;
  14175. }
  14176. }
  14177. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14178. {
  14179. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14180. {
  14181. strcpy(str, (const char*)value);
  14182. for(int i = 0; str[i]; i++)
  14183. {
  14184. str[i] = tolower(str[i]);
  14185. }
  14186. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14187. isSuccess = ConfigurationStatus_Accepted;
  14188. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14189. }
  14190. else
  14191. {
  14192. isSuccess = ConfigurationStatus_Rejected;
  14193. }
  14194. }
  14195. if(strcmp(key, "LocalPreAuthorize") == 0)
  14196. {
  14197. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14198. {
  14199. strcpy(str, (const char*)value);
  14200. for(int i = 0; str[i]; i++)
  14201. {
  14202. str[i] = tolower(str[i]);
  14203. }
  14204. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14205. isSuccess = ConfigurationStatus_Accepted;
  14206. }
  14207. else
  14208. {
  14209. isSuccess = ConfigurationStatus_Rejected;
  14210. }
  14211. }
  14212. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14213. {
  14214. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14215. {
  14216. check_ascii = value[0];
  14217. if( (check_ascii < 48) || (check_ascii > 57) )
  14218. {
  14219. isSuccess = ConfigurationStatus_Rejected;
  14220. }
  14221. else
  14222. {
  14223. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  14224. isSuccess = ConfigurationStatus_Accepted;
  14225. }
  14226. }
  14227. else
  14228. {
  14229. isSuccess = ConfigurationStatus_Rejected;
  14230. }
  14231. }
  14232. if(strcmp(key, "MeterValuesAlignedData") == 0)
  14233. {
  14234. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14235. {
  14236. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  14237. isSuccess = ConfigurationStatus_Accepted;
  14238. }
  14239. else
  14240. {
  14241. isSuccess = ConfigurationStatus_Rejected;
  14242. }
  14243. }
  14244. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  14245. {
  14246. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14247. {
  14248. check_ascii = value[0];
  14249. if( (check_ascii < 48) || (check_ascii > 57) )
  14250. {
  14251. isSuccess = ConfigurationStatus_Rejected;
  14252. }
  14253. else
  14254. {
  14255. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  14257. isSuccess = ConfigurationStatus_Accepted;
  14258. }
  14259. }
  14260. else
  14261. {
  14262. isSuccess = ConfigurationStatus_Rejected;
  14263. }
  14264. }
  14265. if(strcmp(key, "MeterValuesSampledData") == 0 )
  14266. {
  14267. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14268. {
  14269. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  14270. isSuccess = ConfigurationStatus_Accepted;
  14271. }
  14272. else
  14273. {
  14274. isSuccess = ConfigurationStatus_Rejected;
  14275. }
  14276. }
  14277. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  14278. {
  14279. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14280. {
  14281. check_ascii = value[0];
  14282. if( (check_ascii < 48) || (check_ascii > 57) )
  14283. {
  14284. isSuccess = ConfigurationStatus_Rejected;
  14285. }
  14286. else
  14287. {
  14288. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14289. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  14290. isSuccess = ConfigurationStatus_Accepted;
  14291. }
  14292. }
  14293. else
  14294. {
  14295. isSuccess = ConfigurationStatus_Rejected;
  14296. }
  14297. }
  14298. if(strcmp(key, "MeterValueSampleInterval") == 0)
  14299. {
  14300. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14301. {
  14302. check_ascii = value[0];
  14303. if( (check_ascii < 48) || (check_ascii > 57) )
  14304. {
  14305. isSuccess = ConfigurationStatus_Rejected;
  14306. }
  14307. else
  14308. {
  14309. if((atoi(value) == 0) || (atoi(value) >= 10))
  14310. {
  14311. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14312. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14313. isSuccess = ConfigurationStatus_Accepted;
  14314. }
  14315. else
  14316. {
  14317. isSuccess = ConfigurationStatus_Rejected;
  14318. }
  14319. }
  14320. }
  14321. else
  14322. {
  14323. isSuccess = ConfigurationStatus_Rejected;
  14324. }
  14325. }
  14326. if(strcmp(key, "MinimumStatusDuration") == 0)
  14327. {
  14328. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14329. {
  14330. check_ascii = value[0];
  14331. if( (check_ascii < 48) || (check_ascii > 57) )
  14332. {
  14333. isSuccess = ConfigurationStatus_Rejected;
  14334. }
  14335. else
  14336. {
  14337. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14338. {
  14339. isSuccess = ConfigurationStatus_Rejected;
  14340. }
  14341. else
  14342. {
  14343. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14344. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14345. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14346. isSuccess = ConfigurationStatus_Accepted;
  14347. }
  14348. }
  14349. }
  14350. else
  14351. {
  14352. isSuccess = ConfigurationStatus_Rejected;
  14353. }
  14354. }
  14355. if(strcmp(key, "NumberOfConnectors") == 0)
  14356. {
  14357. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14358. {
  14359. check_ascii = value[0];
  14360. if( (check_ascii < 48) || (check_ascii > 57) )
  14361. {
  14362. isSuccess = ConfigurationStatus_Rejected;
  14363. }
  14364. else
  14365. {
  14366. //Charger.ResetRetries = Integer.parseInt(value);
  14367. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14368. isSuccess = ConfigurationStatus_Accepted;
  14369. }
  14370. }
  14371. else
  14372. {
  14373. isSuccess = ConfigurationStatus_Rejected;
  14374. }
  14375. }
  14376. if(strcmp(key, "ResetRetries") == 0)
  14377. {
  14378. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14379. {
  14380. check_ascii = value[0];
  14381. if( (check_ascii < 48) || (check_ascii > 57) )
  14382. {
  14383. isSuccess = ConfigurationStatus_Rejected;
  14384. }
  14385. else
  14386. {
  14387. //Charger.ResetRetries = Integer.parseInt(value);
  14388. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14389. isSuccess = ConfigurationStatus_Accepted;
  14390. }
  14391. }
  14392. else
  14393. {
  14394. isSuccess = ConfigurationStatus_Rejected;
  14395. }
  14396. }
  14397. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14398. {
  14399. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14400. {
  14401. strcpy(str, (const char*)value);
  14402. for(int i = 0; str[i]; i++)
  14403. {
  14404. str[i] = tolower(str[i]);
  14405. }
  14406. if(strcmp(str, "notapplicable")== 0)
  14407. {
  14408. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14409. isSuccess = ConfigurationStatus_Accepted;
  14410. }
  14411. else if(strcmp(str, "unknown")== 0)
  14412. {
  14413. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14414. isSuccess = ConfigurationStatus_Accepted;
  14415. }
  14416. else if(strcmp(str, "rst")== 0)
  14417. {
  14418. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14419. isSuccess = ConfigurationStatus_Accepted;
  14420. }
  14421. else if(strcmp(str, "rts")== 0)
  14422. {
  14423. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14424. isSuccess = ConfigurationStatus_Accepted;
  14425. }
  14426. else if(strcmp(str, "srt")== 0)
  14427. {
  14428. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14429. isSuccess = ConfigurationStatus_Accepted;
  14430. }
  14431. else if(strcmp(str, "str")== 0)
  14432. {
  14433. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14434. isSuccess = ConfigurationStatus_Accepted;
  14435. }
  14436. else if(strcmp(str, "trs")== 0)
  14437. {
  14438. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14439. isSuccess = ConfigurationStatus_Accepted;
  14440. }
  14441. else if(strcmp(str, "tsr")== 0)
  14442. {
  14443. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14444. isSuccess = ConfigurationStatus_Accepted;
  14445. }
  14446. else
  14447. {
  14448. isSuccess = ConfigurationStatus_Rejected;
  14449. }
  14450. }
  14451. else
  14452. {
  14453. isSuccess = ConfigurationStatus_Rejected;
  14454. }
  14455. }
  14456. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14457. {
  14458. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14459. {
  14460. check_ascii = value[0];
  14461. if( (check_ascii < 48) || (check_ascii > 57) )
  14462. {
  14463. isSuccess = ConfigurationStatus_Rejected;
  14464. }
  14465. else
  14466. {
  14467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14468. isSuccess = ConfigurationStatus_Accepted;
  14469. }
  14470. }
  14471. else
  14472. {
  14473. isSuccess = ConfigurationStatus_Rejected;
  14474. }
  14475. }
  14476. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14477. {
  14478. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14479. {
  14480. strcpy(str, (const char*)value);
  14481. for(int i = 0; str[i]; i++)
  14482. {
  14483. str[i] = tolower(str[i]);
  14484. }
  14485. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14486. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14487. isSuccess = ConfigurationStatus_Accepted;
  14488. }
  14489. else
  14490. {
  14491. isSuccess = ConfigurationStatus_Rejected;
  14492. }
  14493. }
  14494. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14495. {
  14496. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14497. {
  14498. strcpy(str, (const char*)value);
  14499. for(int i = 0; str[i]; i++)
  14500. {
  14501. str[i] = tolower(str[i]);
  14502. }
  14503. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14505. isSuccess = ConfigurationStatus_Accepted;
  14506. }
  14507. else
  14508. {
  14509. isSuccess = ConfigurationStatus_Rejected;
  14510. }
  14511. }
  14512. if(strcmp(key, "StopTxnAlignedData") == 0)
  14513. {
  14514. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14515. {
  14516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14517. isSuccess = ConfigurationStatus_Accepted;
  14518. }
  14519. else
  14520. {
  14521. isSuccess = ConfigurationStatus_Rejected;
  14522. }
  14523. }
  14524. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14525. {
  14526. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14527. {
  14528. check_ascii = value[0];
  14529. if( (check_ascii < 48) || (check_ascii > 57) )
  14530. {
  14531. isSuccess = ConfigurationStatus_Rejected;
  14532. }
  14533. else
  14534. {
  14535. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14536. isSuccess = ConfigurationStatus_Accepted;
  14537. }
  14538. }
  14539. else
  14540. {
  14541. isSuccess = ConfigurationStatus_Rejected;
  14542. }
  14543. }
  14544. if(strcmp(key, "StopTxnSampledData") == 0)
  14545. {
  14546. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14547. {
  14548. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14549. isSuccess = ConfigurationStatus_Accepted;
  14550. }
  14551. else
  14552. {
  14553. isSuccess = ConfigurationStatus_Rejected;
  14554. }
  14555. }
  14556. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14557. {
  14558. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14559. {
  14560. check_ascii = value[0];
  14561. if( (check_ascii < 48) || (check_ascii > 57) )
  14562. {
  14563. isSuccess = ConfigurationStatus_Rejected;
  14564. }
  14565. else
  14566. {
  14567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14568. isSuccess = ConfigurationStatus_Accepted;
  14569. }
  14570. }
  14571. else
  14572. {
  14573. isSuccess = ConfigurationStatus_Rejected;
  14574. }
  14575. }
  14576. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14577. {
  14578. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14579. {
  14580. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14581. isSuccess = ConfigurationStatus_Accepted;
  14582. }
  14583. else
  14584. {
  14585. isSuccess = ConfigurationStatus_Rejected;
  14586. }
  14587. }
  14588. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14589. {
  14590. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14591. {
  14592. check_ascii = value[0];
  14593. if( (check_ascii < 48) || (check_ascii > 57) )
  14594. {
  14595. isSuccess = ConfigurationStatus_Rejected;
  14596. }
  14597. else
  14598. {
  14599. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14600. isSuccess = ConfigurationStatus_Accepted;
  14601. }
  14602. }
  14603. else
  14604. {
  14605. isSuccess = ConfigurationStatus_Rejected;
  14606. }
  14607. }
  14608. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14609. {
  14610. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14611. {
  14612. check_ascii = value[0];
  14613. if( (check_ascii < 48) || (check_ascii > 57) )
  14614. {
  14615. isSuccess = ConfigurationStatus_Rejected;
  14616. }
  14617. else
  14618. {
  14619. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14620. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14621. TransactionMessageAttemptsValue = atoi(value);
  14622. isSuccess = ConfigurationStatus_Accepted;
  14623. }
  14624. }
  14625. else
  14626. {
  14627. isSuccess = ConfigurationStatus_Rejected;
  14628. }
  14629. }
  14630. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14631. {
  14632. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14633. {
  14634. check_ascii = value[0];
  14635. if( (check_ascii < 48) || (check_ascii > 57) )
  14636. {
  14637. isSuccess = ConfigurationStatus_Rejected;
  14638. }
  14639. else
  14640. {
  14641. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14642. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14643. TransactionMessageRetryIntervalValue = atoi(value);
  14644. isSuccess = ConfigurationStatus_Accepted;
  14645. }
  14646. }
  14647. else
  14648. {
  14649. isSuccess = ConfigurationStatus_Rejected;
  14650. }
  14651. }
  14652. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14653. {
  14654. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14655. {
  14656. strcpy(str, (const char*)value);
  14657. for(int i = 0; str[i]; i++)
  14658. {
  14659. str[i] = tolower(str[i]);
  14660. }
  14661. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14662. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14663. isSuccess = ConfigurationStatus_Accepted;
  14664. }
  14665. else
  14666. {
  14667. isSuccess = ConfigurationStatus_Rejected;
  14668. }
  14669. }
  14670. if(strcmp(key, "WebSocketPingInterval") == 0)
  14671. {
  14672. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14673. {
  14674. check_ascii = value[0];
  14675. if( (check_ascii < 48) || (check_ascii > 57) )
  14676. {
  14677. isSuccess = ConfigurationStatus_Rejected;
  14678. }
  14679. else
  14680. {
  14681. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  14682. isSuccess = ConfigurationStatus_Accepted;
  14683. }
  14684. }
  14685. else
  14686. {
  14687. isSuccess = ConfigurationStatus_Rejected;
  14688. }
  14689. }
  14690. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  14691. {
  14692. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  14693. {
  14694. strcpy(str, (const char*)value);
  14695. for(int i = 0; str[i]; i++)
  14696. {
  14697. str[i] = tolower(str[i]);
  14698. }
  14699. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14700. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14701. isSuccess = ConfigurationStatus_Accepted;
  14702. }
  14703. else
  14704. {
  14705. isSuccess = ConfigurationStatus_Rejected;
  14706. }
  14707. }
  14708. if(strcmp(key, "AuthorizationKey") == 0)
  14709. {
  14710. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  14711. {
  14712. strcpy(str, (const char*)value);
  14713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  14714. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14715. isSuccess = ConfigurationStatus_Accepted;
  14716. }
  14717. else
  14718. {
  14719. isSuccess = ConfigurationStatus_Rejected;
  14720. }
  14721. }
  14722. if(strcmp(key, "SecurityProfile") == 0)
  14723. {
  14724. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14725. {
  14726. check_ascii = value[0];
  14727. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  14728. {
  14729. isSuccess = ConfigurationStatus_Rejected;
  14730. }
  14731. else if(check_ascii == 0x33)
  14732. {
  14733. isSuccess = NotSupported;
  14734. }
  14735. else
  14736. {
  14737. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  14738. {
  14739. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  14740. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  14741. isSuccess = ConfigurationStatus_Accepted;
  14742. }
  14743. else
  14744. isSuccess = ConfigurationStatus_Rejected;
  14745. }
  14746. }
  14747. else
  14748. {
  14749. isSuccess = ConfigurationStatus_Rejected;
  14750. }
  14751. }
  14752. if(strcmp(key, "DefaultPrice") == 0)
  14753. {
  14754. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  14755. {
  14756. strcpy(str, (const char*)value);
  14757. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  14758. isSuccess = ConfigurationStatus_Accepted;
  14759. }
  14760. else
  14761. {
  14762. isSuccess = ConfigurationStatus_Rejected;
  14763. }
  14764. }
  14765. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  14766. {
  14767. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14768. {
  14769. strcpy(str, (const char*)value);
  14770. for(int i = 0; str[i]; i++)
  14771. {
  14772. str[i] = tolower(str[i]);
  14773. }
  14774. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14775. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14776. isSuccess = ConfigurationStatus_Accepted;
  14777. }
  14778. else
  14779. {
  14780. isSuccess = ConfigurationStatus_Rejected;
  14781. }
  14782. }
  14783. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  14784. {
  14785. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14786. {
  14787. strcpy(str, (const char*)value);
  14788. for(int i = 0; str[i]; i++)
  14789. {
  14790. str[i] = tolower(str[i]);
  14791. }
  14792. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14793. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14794. isSuccess = ConfigurationStatus_Accepted;
  14795. }
  14796. else
  14797. {
  14798. isSuccess = ConfigurationStatus_Rejected;
  14799. }
  14800. }
  14801. if(strcmp(key, "TimeOffset") == 0)
  14802. {
  14803. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  14804. {
  14805. strcpy(str, (const char*)value);
  14806. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  14807. isSuccess = ConfigurationStatus_Accepted;
  14808. }
  14809. else
  14810. {
  14811. isSuccess = ConfigurationStatus_Rejected;
  14812. }
  14813. }
  14814. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  14815. {
  14816. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  14817. {
  14818. strcpy(str, (const char*)value);
  14819. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  14820. isSuccess = ConfigurationStatus_Accepted;
  14821. }
  14822. else
  14823. {
  14824. isSuccess = ConfigurationStatus_Rejected;
  14825. }
  14826. }
  14827. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  14828. {
  14829. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  14830. {
  14831. strcpy(str, (const char*)value);
  14832. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  14833. isSuccess = ConfigurationStatus_Accepted;
  14834. }
  14835. else
  14836. {
  14837. isSuccess = ConfigurationStatus_Rejected;
  14838. }
  14839. }
  14840. #if 0
  14841. //For OCPP Test Case
  14842. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  14843. {
  14844. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14845. {
  14846. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  14847. isSuccess = ConfigurationStatus_Accepted;
  14848. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14849. }
  14850. else
  14851. {
  14852. isSuccess = ConfigurationStatus_Rejected;
  14853. }
  14854. }
  14855. #endif
  14856. #if 1
  14857. if(strcmp(key, "LocalAuthListEnabled") == 0)
  14858. {
  14859. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14860. {
  14861. strcpy(str, (const char*)value);
  14862. for(int i = 0; str[i]; i++)
  14863. {
  14864. str[i] = tolower(str[i]);
  14865. }
  14866. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14867. isSuccess = ConfigurationStatus_Accepted;
  14868. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14869. }
  14870. else
  14871. {
  14872. isSuccess = ConfigurationStatus_Rejected;
  14873. }
  14874. }
  14875. #endif
  14876. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  14877. {
  14878. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14879. {
  14880. check_ascii = value[0];
  14881. if( (check_ascii < 48) || (check_ascii > 57) )
  14882. {
  14883. isSuccess = ConfigurationStatus_Rejected;
  14884. }
  14885. else
  14886. {
  14887. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  14888. isSuccess = ConfigurationStatus_Accepted;
  14889. }
  14890. }
  14891. else
  14892. {
  14893. isSuccess = ConfigurationStatus_Rejected;
  14894. }
  14895. }
  14896. if(strcmp(key, "SendLocalListMaxLength") == 0)
  14897. {
  14898. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14899. {
  14900. check_ascii = value[0];
  14901. if( (check_ascii < 48) || (check_ascii > 57) )
  14902. {
  14903. isSuccess = ConfigurationStatus_Rejected;
  14904. }
  14905. else
  14906. {
  14907. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  14908. isSuccess = ConfigurationStatus_Accepted;
  14909. }
  14910. }
  14911. else
  14912. {
  14913. isSuccess = ConfigurationStatus_Rejected;
  14914. }
  14915. }
  14916. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  14917. {
  14918. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14919. {
  14920. strcpy(str, (const char*)value);
  14921. for(int i = 0; str[i]; i++)
  14922. {
  14923. str[i] = tolower(str[i]);
  14924. }
  14925. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14926. isSuccess = ConfigurationStatus_Accepted;
  14927. }
  14928. else
  14929. {
  14930. isSuccess = ConfigurationStatus_Rejected;
  14931. }
  14932. }
  14933. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  14934. {
  14935. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14936. {
  14937. check_ascii = value[0];
  14938. if( (check_ascii < 48) || (check_ascii > 57) )
  14939. {
  14940. isSuccess = ConfigurationStatus_Rejected;
  14941. }
  14942. else
  14943. {
  14944. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  14945. isSuccess = ConfigurationStatus_Accepted;
  14946. }
  14947. }
  14948. else
  14949. {
  14950. isSuccess = ConfigurationStatus_Rejected;
  14951. }
  14952. }
  14953. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14954. {
  14955. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14956. {
  14957. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14958. isSuccess = ConfigurationStatus_Accepted;
  14959. }
  14960. else
  14961. {
  14962. isSuccess = ConfigurationStatus_Rejected;
  14963. }
  14964. }
  14965. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14966. {
  14967. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14968. {
  14969. check_ascii = value[0];
  14970. if( (check_ascii < 48) || (check_ascii > 57) )
  14971. {
  14972. isSuccess = ConfigurationStatus_Rejected;
  14973. }
  14974. else
  14975. {
  14976. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14977. isSuccess = ConfigurationStatus_Accepted;
  14978. }
  14979. }
  14980. else
  14981. {
  14982. isSuccess = ConfigurationStatus_Rejected;
  14983. }
  14984. }
  14985. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14986. {
  14987. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14988. {
  14989. strcpy(str, (const char*)value);
  14990. for(int i = 0; str[i]; i++)
  14991. {
  14992. str[i] = tolower(str[i]);
  14993. }
  14994. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14995. isSuccess = ConfigurationStatus_Accepted;
  14996. }
  14997. else
  14998. {
  14999. isSuccess = ConfigurationStatus_Rejected;
  15000. }
  15001. }
  15002. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  15003. {
  15004. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15005. {
  15006. check_ascii = value[0];
  15007. if( (check_ascii < 48) || (check_ascii > 57) )
  15008. {
  15009. isSuccess = ConfigurationStatus_Rejected;
  15010. }
  15011. else
  15012. {
  15013. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  15014. isSuccess = ConfigurationStatus_Accepted;
  15015. }
  15016. }
  15017. else
  15018. {
  15019. isSuccess = ConfigurationStatus_Rejected;
  15020. }
  15021. }
  15022. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15023. return isSuccess;
  15024. }
  15025. int TransactionMessageAttemptsGet(void)
  15026. {
  15027. return TransactionMessageAttemptsValue;
  15028. }
  15029. int FirstHeartBeatResponse(void)
  15030. {
  15031. return FirstHeartBeat;
  15032. }
  15033. int TransactionMessageRetryIntervalGet(void)
  15034. {
  15035. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15036. }
  15037. int ReadHttpStatus(int sock)
  15038. {
  15039. //char c;
  15040. char buff[1024]="",*ptr=buff+1;
  15041. int bytes_received, status;
  15042. DEBUG_INFO("Begin Response ..\n");
  15043. while((bytes_received = recv(sock, ptr, 1, 0))){
  15044. if(bytes_received==-1){
  15045. perror("ReadHttpStatus");
  15046. exit(1);
  15047. }
  15048. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  15049. ptr++;
  15050. }
  15051. *ptr=0;
  15052. ptr=buff+1;
  15053. sscanf(ptr,"%*s %d ", &status);
  15054. DEBUG_INFO("%s\n",ptr);
  15055. DEBUG_INFO("status=%d\n",status);
  15056. DEBUG_INFO("End Response ..\n");
  15057. return (bytes_received>0)?status:0;
  15058. }
  15059. //the only filed that it parsed is 'Content-Length'
  15060. int ParseHeader(int sock)
  15061. {
  15062. //char c;
  15063. char buff[1024]="",*ptr=buff+4;
  15064. int bytes_received;
  15065. DEBUG_INFO("Begin HEADER ..\n");
  15066. while((bytes_received = recv(sock, ptr, 1, 0))){
  15067. if(bytes_received==-1){
  15068. perror("Parse Header");
  15069. exit(1);
  15070. }
  15071. if(
  15072. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  15073. (ptr[-1]=='\r') && (*ptr=='\n' )
  15074. ) break;
  15075. ptr++;
  15076. }
  15077. *ptr=0;
  15078. ptr=buff+4;
  15079. //printf("%s",ptr);
  15080. if(bytes_received){
  15081. ptr=strstr(ptr,"Content-Length:");
  15082. if(ptr){
  15083. sscanf(ptr,"%*s %d",&bytes_received);
  15084. }else
  15085. bytes_received=-1; //unknown size
  15086. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15087. }
  15088. DEBUG_INFO("End HEADER ..\n");
  15089. return bytes_received ;
  15090. }
  15091. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15092. {
  15093. int result = TRUE;
  15094. char rmFileCmd[100]={0};
  15095. char FilePath[100]={0};
  15096. char ftpbuf[200];
  15097. int systemresult;
  15098. //DEBUG_INFO("filename=%s\n",filename);
  15099. //DEBUG_INFO("url=%s\n",url);
  15100. sprintf(FilePath,"/mnt/%s",filename);
  15101. system("ping 8.8.8.8 &");
  15102. if((access(FilePath,F_OK))!=-1)
  15103. {
  15104. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15105. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15106. system(rmFileCmd);
  15107. }
  15108. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15109. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15110. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15111. systemresult = system(ftpbuf);
  15112. //DEBUG_INFO("systemresult=%d\n",systemresult);
  15113. if(systemresult != 0)
  15114. {
  15115. DEBUG_INFO("http DownLoad error!\n");
  15116. result = FALSE;
  15117. }
  15118. system("pkill ping");
  15119. return result;
  15120. }
  15121. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15122. {
  15123. int result = TRUE;
  15124. char rmFileCmd[100]={0};
  15125. char FilePath[100]={0};
  15126. char ftpbuf[200];
  15127. int systemresult;
  15128. //char temp[100];
  15129. sprintf(FilePath,"/mnt/%s",filename);
  15130. system("ping 8.8.8.8 &");
  15131. if((access(FilePath,F_OK))!=-1)
  15132. {
  15133. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15134. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15135. system(rmFileCmd);
  15136. }
  15137. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15138. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15139. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  15140. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15141. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15142. systemresult = system(ftpbuf);
  15143. //DEBUG_INFO("systemresult=%d\n",systemresult);
  15144. if(systemresult != 0)
  15145. {
  15146. DEBUG_WARN("wget error!\n");
  15147. result = FALSE;
  15148. }
  15149. system("pkill ping");
  15150. return result;
  15151. }
  15152. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15153. {
  15154. char rmFileCmd[100]={0};
  15155. char FilePath[100]={0};
  15156. char buf[512];
  15157. int systemresult = 0;
  15158. //DEBUG_INFO("filename=%s\n",filename);
  15159. //DEBUG_INFO("url=%s\n",url);
  15160. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15161. if((access(FilePath,F_OK))!=-1)
  15162. {
  15163. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15164. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15165. system(rmFileCmd);
  15166. }
  15167. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15168. if(fp == NULL)
  15169. {
  15170. DEBUG_INFO("log is NULL\n");
  15171. return FALSE;
  15172. }
  15173. else
  15174. {
  15175. fprintf(fp, "%s\n", url);
  15176. fprintf(fp, "%s\n", filename);
  15177. fclose(fp);
  15178. }
  15179. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15180. if(phpFP == NULL)
  15181. {
  15182. DEBUG_INFO("PHP upload fail.\n");
  15183. return FALSE;
  15184. }
  15185. else
  15186. {
  15187. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15188. {
  15189. if(strstr(buf, "result") != NULL)
  15190. {
  15191. sscanf(buf, "result: %d", &systemresult);
  15192. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15193. }
  15194. }
  15195. pclose(phpFP);
  15196. }
  15197. if(systemresult != 1)
  15198. {
  15199. DEBUG_INFO("HTTP upload error!\n");
  15200. return FALSE;
  15201. }
  15202. return TRUE;
  15203. }
  15204. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15205. {
  15206. struct hostent* server;
  15207. char *IPbuffer;
  15208. char ftpbuf[200];
  15209. int systemresult;
  15210. // To retrieve host information
  15211. server = gethostbyname(location);
  15212. // To convert an Internet network
  15213. // address into ASCII string
  15214. IPbuffer = inet_ntoa(*((struct in_addr*)
  15215. server->h_addr_list[0]));
  15216. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15217. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  15218. /* format : ftpput -u username -p passwd IP target source*/
  15219. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  15220. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15221. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15222. systemresult = system(ftpbuf);
  15223. DEBUG_INFO("systemresult=%d\n",systemresult);
  15224. if(systemresult != 0)
  15225. {
  15226. DEBUG_INFO("ftpput error!\n");
  15227. return FALSE;
  15228. }
  15229. return TRUE;
  15230. }
  15231. int GetOcppServerURL()
  15232. {
  15233. int result = FALSE;
  15234. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  15235. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  15236. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  15237. struct yuarel url;
  15238. char urlStr[512];
  15239. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  15240. {
  15241. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  15242. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15243. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15244. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  15245. if(yuarel_parse(&url, urlStr) != -1)
  15246. {
  15247. sprintf(OcppProtocol, "%s", url.scheme);
  15248. sprintf(OcppHost, "%s", url.host);
  15249. if(url.path == NULL)
  15250. OcppTempPath[0] = '\0';
  15251. else
  15252. {
  15253. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  15254. {
  15255. sprintf(OcppTempPath, "%s/", url.path);
  15256. }
  15257. else
  15258. {
  15259. sprintf(OcppTempPath, "%s", url.path);
  15260. }
  15261. }
  15262. if(url.port == 0)
  15263. {
  15264. if(strcmp(OcppProtocol, "wss") == 0)
  15265. OcppPort = 443;
  15266. else
  15267. OcppPort = 80;
  15268. }
  15269. else
  15270. OcppPort = url.port;
  15271. result = TRUE;
  15272. }
  15273. }
  15274. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  15275. {
  15276. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  15277. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15278. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15279. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  15280. if(yuarel_parse(&url, urlStr) != -1)
  15281. {
  15282. sprintf(OcppProtocol, "%s", url.scheme);
  15283. sprintf(OcppHost, "%s", url.host);
  15284. if(url.path == NULL)
  15285. OcppTempPath[0] = '\0';
  15286. else
  15287. sprintf(OcppTempPath, "%s", url.path);
  15288. if(url.port == 0)
  15289. {
  15290. if(strcmp(OcppProtocol, "wss") == 0)
  15291. OcppPort = 443;
  15292. else
  15293. OcppPort = 80;
  15294. }
  15295. else
  15296. OcppPort = url.port;
  15297. result = TRUE;
  15298. }
  15299. }
  15300. else
  15301. {
  15302. strcpy(OcppHost,"");
  15303. }
  15304. return result;
  15305. }
  15306. int GetOcppPath()
  15307. {
  15308. int result = FALSE;
  15309. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  15310. {
  15311. if(OcppTempPath == NULL)
  15312. {
  15313. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15314. }
  15315. else
  15316. {
  15317. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15318. }
  15319. result = TRUE;
  15320. goto End;
  15321. }
  15322. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  15323. {
  15324. if(OcppTempPath == NULL)
  15325. {
  15326. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  15327. }
  15328. else
  15329. {
  15330. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  15331. }
  15332. result = TRUE;
  15333. goto End;
  15334. }
  15335. else
  15336. {
  15337. strcpy(OcppPath,"");
  15338. }
  15339. End:
  15340. return result;
  15341. }
  15342. int GetOcppPort()
  15343. {
  15344. return OcppPort;
  15345. }
  15346. int GetOcppConnStatus(void)
  15347. {
  15348. return ShmOCPP16Data->OcppConnStatus;
  15349. }
  15350. void SetOcppConnStatus(uint8_t status)
  15351. {
  15352. ShmOCPP16Data->OcppConnStatus = status;
  15353. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  15354. }
  15355. int GetHeartBeatWithNOResponse(void)
  15356. {
  15357. return HeartBeatWithNOResponse;
  15358. }
  15359. void SetHeartBeatWithNOResponse(void)
  15360. {
  15361. HeartBeatWithNOResponse = 0;
  15362. }
  15363. void GetStartTransactionIdTag(int gun_index)
  15364. {
  15365. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  15366. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15367. }
  15368. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  15369. {
  15370. char ch;
  15371. FILE *fptr1;
  15372. int temptransactionId;
  15373. char str[100]={0};
  15374. temptransactionId = 0;
  15375. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  15376. {
  15377. DEBUG_INFO("IdTag is empty.\n");
  15378. return temptransactionId;
  15379. }
  15380. /*------ Read the file ----------------*/
  15381. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  15382. if (!fptr1)
  15383. {
  15384. DEBUG_INFO("QueueTransactionId file open error.\n");
  15385. //printf(" File not found or unable to open the input file!!\n");
  15386. return temptransactionId;
  15387. }
  15388. ch=fgetc(fptr1);
  15389. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  15390. rewind(fptr1);
  15391. if(ch!=EOF)
  15392. {
  15393. // printf("%c",ch);
  15394. while (fgets(str, 100, fptr1) != NULL)
  15395. {
  15396. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15397. if(str[0]=='\0')
  15398. {
  15399. break;
  15400. }
  15401. char *revbuf[8] = {0}; // Variable store string split
  15402. int num = 0;// Quantity after string split
  15403. DEBUG_INFO("Transaction queue data= %s\n", str);
  15404. splitstring(str,",",revbuf,&num); // String split
  15405. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15406. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15407. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15408. DEBUG_INFO("------------------------------\n");
  15409. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15410. {
  15411. if(isStopTransaction)
  15412. {
  15413. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15414. {
  15415. temptransactionId = atoi(revbuf[2]);
  15416. //break;
  15417. }
  15418. }
  15419. else
  15420. {
  15421. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15422. {
  15423. temptransactionId = atoi(revbuf[2]);
  15424. //break;
  15425. }
  15426. }
  15427. }
  15428. }
  15429. }
  15430. else
  15431. DEBUG_INFO("EOF\n");
  15432. fclose(fptr1);
  15433. /*------- End of reading ---------------*/
  15434. return temptransactionId;
  15435. }
  15436. void SetTransactionIdZero(int transactionId)
  15437. {
  15438. char ch;
  15439. FILE *fptr1, *fptr2;
  15440. int temptransactionId = 0;
  15441. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  15442. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  15443. if (!fptr1)
  15444. {
  15445. //printf(" File not found or unable to open the input file!!\n");
  15446. return ;
  15447. }
  15448. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15449. if (!fptr2)
  15450. {
  15451. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15452. fclose(fptr1);
  15453. return ;
  15454. }
  15455. ch=fgetc(fptr1);
  15456. rewind(fptr1);
  15457. if(ch!=EOF)
  15458. {
  15459. // copy all contents to the temporary file except the specific line
  15460. while (fgets(str, 100, fptr1) != NULL)
  15461. {
  15462. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15463. if(str[0]=='\0')
  15464. {
  15465. break;
  15466. }
  15467. char *revbuf[8] = {0};
  15468. int num = 0;
  15469. strcpy(strtemp, str);
  15470. splitstring(str,",",revbuf,&num);
  15471. if(revbuf[2][0] != '\0')
  15472. {
  15473. temptransactionId = atoi(revbuf[2]);
  15474. if(transactionId != temptransactionId)
  15475. {
  15476. fprintf(fptr2, "%s\n", strtemp);
  15477. }
  15478. }
  15479. }
  15480. }
  15481. fclose(fptr1);
  15482. fclose(fptr2);
  15483. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  15484. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  15485. /*------ Read the file ----------------*/
  15486. }
  15487. int InternetDisconnect(void)
  15488. {
  15489. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15490. }
  15491. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15492. void storeTempStopTransaction(int gun_index)
  15493. {
  15494. char guid[37]={0};
  15495. int tempIndex = 0;
  15496. char TempStopTransaction[256];
  15497. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15498. DEBUG_INFO("storeTempStopTransaction...\n");
  15499. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15500. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  15501. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15502. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15503. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15504. {
  15505. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15506. {
  15507. tempIndex = ((gun_index==2) ? 1: 0);
  15508. }
  15509. else
  15510. {
  15511. tempIndex = gun_index;
  15512. }
  15513. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15514. {
  15515. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15516. {
  15517. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15518. }
  15519. }// END OF CHAdeMO_QUANTITY
  15520. }
  15521. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15522. {
  15523. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15524. {
  15525. tempIndex = ((gun_index==2) ? 1: 0);
  15526. }
  15527. else
  15528. {
  15529. tempIndex = gun_index;
  15530. }
  15531. for (int index = 0; index < CCS_QUANTITY; index++)
  15532. {
  15533. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15534. {
  15535. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15536. }
  15537. }// END OF CCS_QUANTITY
  15538. }
  15539. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15540. {
  15541. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15542. {
  15543. tempIndex = ((gun_index==2) ? 1: 0);
  15544. }
  15545. else
  15546. {
  15547. tempIndex = gun_index;
  15548. }
  15549. for (int index = 0; index < GB_QUANTITY; index++)
  15550. {
  15551. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15552. {
  15553. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15554. }
  15555. }// END OF GB_QUANTITY
  15556. }
  15557. else if(gunType[gun_index] == GUN_TYPE_DO)
  15558. {
  15559. tempIndex = gun_index;
  15560. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15561. {
  15562. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15563. {
  15564. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15565. }
  15566. }
  15567. }
  15568. else
  15569. {
  15570. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15571. {
  15572. tempIndex = 2;
  15573. }
  15574. else
  15575. {
  15576. tempIndex = gun_index;
  15577. }
  15578. for (int index = 0; index < AC_QUANTITY; index++)
  15579. {
  15580. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15581. {
  15582. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15583. }
  15584. }// END OF AC_QUANTITY
  15585. }
  15586. //Stop Transaction Time
  15587. struct timeval tmnow;
  15588. struct tm *tm;
  15589. char buf[28];//, usec_buf[6];
  15590. gettimeofday(&tmnow, NULL);
  15591. time_t t;
  15592. t = time(NULL);
  15593. /*UTC time and date*/
  15594. tm = gmtime(&t);
  15595. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  15597. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  15598. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15599. random_uuid(guid);
  15600. /***********************************transactionData******************************************************/
  15601. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15602. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15603. //=================================
  15604. //1. Transaction_Begin
  15605. //=================================
  15606. //============================== Energy.Active.Import.Interval ===========================================
  15607. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15608. {
  15609. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15610. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15611. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15612. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  15613. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15614. 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))
  15615. {
  15616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15617. }
  15618. else
  15619. {
  15620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15621. }
  15622. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15623. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15624. }
  15625. //=================================
  15626. //2. Transaction_End
  15627. //=================================
  15628. //2.1====================================== Current.Import L1 ==============================================
  15629. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15630. {
  15631. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15632. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15633. {
  15634. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15635. {
  15636. tempIndex = ((gun_index==2) ? 1: 0);
  15637. }
  15638. else
  15639. {
  15640. tempIndex = gun_index;
  15641. }
  15642. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15643. {
  15644. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15645. {
  15646. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15647. }
  15648. }// End of for CHAdeMO_QUANTITY
  15649. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15650. }
  15651. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15652. {
  15653. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15654. {
  15655. tempIndex = ((gun_index==2) ? 1: 0);
  15656. }
  15657. else
  15658. {
  15659. tempIndex = gun_index;
  15660. }
  15661. for (int index = 0; index < CCS_QUANTITY; index++)
  15662. {
  15663. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15664. {
  15665. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15666. }
  15667. }// End of for CCS_QUANTITY
  15668. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15669. }
  15670. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15671. {
  15672. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15673. {
  15674. tempIndex = ((gun_index==2) ? 1: 0);
  15675. }
  15676. else
  15677. {
  15678. tempIndex = gun_index;
  15679. }
  15680. for (int index = 0; index < GB_QUANTITY; index++)
  15681. {
  15682. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15683. {
  15684. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15685. }
  15686. }// End of for GB_QUANTITY
  15687. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15688. }
  15689. else if(gunType[gun_index] == GUN_TYPE_DO)
  15690. {
  15691. tempIndex = gun_index;
  15692. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15693. {
  15694. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15695. {
  15696. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15697. }
  15698. }
  15699. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15700. }
  15701. else
  15702. {
  15703. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15704. {
  15705. tempIndex = 2;
  15706. }
  15707. else
  15708. {
  15709. tempIndex = gun_index;
  15710. }
  15711. for (int index = 0; index < AC_QUANTITY; index++)
  15712. {
  15713. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15714. {
  15715. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15716. }
  15717. }// End of for AC_QUANTITY
  15718. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15719. }
  15720. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15721. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15722. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15723. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15724. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15725. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15726. }
  15727. //2.2===================================== Energy.Active.Import.Interval ==========================================
  15728. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15729. {
  15730. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15731. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15732. {
  15733. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15734. {
  15735. tempIndex = ((gun_index==2) ? 1: 0);
  15736. }
  15737. else
  15738. {
  15739. tempIndex = gun_index;
  15740. }
  15741. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15742. {
  15743. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15744. {
  15745. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15746. }
  15747. }// END OF CHAdeMO_QUANTITY
  15748. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15749. }
  15750. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15751. {
  15752. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15753. {
  15754. tempIndex = ((gun_index==2) ? 1: 0);
  15755. }
  15756. else
  15757. {
  15758. tempIndex = gun_index;
  15759. }
  15760. for (int index = 0; index < CCS_QUANTITY; index++)
  15761. {
  15762. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15763. {
  15764. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15765. }
  15766. }// END OF CCS_QUANTITY
  15767. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15768. }
  15769. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15770. {
  15771. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15772. {
  15773. tempIndex = ((gun_index==2) ? 1: 0);
  15774. }
  15775. else
  15776. {
  15777. tempIndex = gun_index;
  15778. }
  15779. for (int index = 0; index < GB_QUANTITY; index++)
  15780. {
  15781. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15782. {
  15783. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15784. }
  15785. }// END OF GB_QUANTITY
  15786. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15787. }
  15788. else if(gunType[gun_index] == GUN_TYPE_DO)
  15789. {
  15790. tempIndex = gun_index;
  15791. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15792. {
  15793. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15794. {
  15795. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15796. }
  15797. }
  15798. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15799. }
  15800. else
  15801. {
  15802. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15803. {
  15804. tempIndex = 2;
  15805. }
  15806. else
  15807. {
  15808. tempIndex = gun_index;
  15809. }
  15810. for (int index = 0; index < AC_QUANTITY; index++)
  15811. {
  15812. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15813. {
  15814. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15815. }
  15816. }// END OF AC_QUANTITY
  15817. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15818. }
  15819. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15820. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15821. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15822. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15823. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15824. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15825. }
  15826. //2.3====================================== Power.Active.Import =========================================
  15827. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  15828. {
  15829. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15830. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15831. {
  15832. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15833. {
  15834. tempIndex = ((gun_index==2) ? 1: 0);
  15835. }
  15836. else
  15837. {
  15838. tempIndex = gun_index;
  15839. }
  15840. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15841. {
  15842. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15843. {
  15844. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15845. }
  15846. } // End for CHAdeMO_QUANTITY
  15847. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15848. }
  15849. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15850. {
  15851. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15852. {
  15853. tempIndex = ((gun_index==2) ? 1: 0);
  15854. }
  15855. else
  15856. {
  15857. tempIndex = gun_index;
  15858. }
  15859. for (int index = 0; index < CCS_QUANTITY; index++)
  15860. {
  15861. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15862. {
  15863. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15864. }
  15865. } // END for CCS_QUANTITY
  15866. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15867. }
  15868. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15869. {
  15870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15871. {
  15872. tempIndex = ((gun_index==2) ? 1: 0);
  15873. }
  15874. else
  15875. {
  15876. tempIndex = gun_index;
  15877. }
  15878. for (int index = 0; index < GB_QUANTITY; index++)
  15879. {
  15880. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15881. {
  15882. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15883. }
  15884. }// END for GB_QUANTITY
  15885. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15886. }
  15887. else if(gunType[gun_index] == GUN_TYPE_DO)
  15888. {
  15889. tempIndex = gun_index;
  15890. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15891. {
  15892. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15893. {
  15894. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15895. }
  15896. }
  15897. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15898. }
  15899. else
  15900. {
  15901. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15902. {
  15903. tempIndex = 2;
  15904. }
  15905. else
  15906. {
  15907. tempIndex = gun_index;
  15908. }
  15909. for (int index = 0; index < AC_QUANTITY; index++)
  15910. {
  15911. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15912. {
  15913. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15914. }
  15915. } // END for AC_QUANTITY
  15916. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15917. }
  15918. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15919. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15920. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15921. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15922. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15923. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15924. }
  15925. //2.4====================================== Voltage L1 ====================================================
  15926. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15927. {
  15928. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15929. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15930. {
  15931. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15932. {
  15933. tempIndex = ((gun_index==2) ? 1: 0);
  15934. }
  15935. else
  15936. {
  15937. tempIndex = gun_index;
  15938. }
  15939. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15940. {
  15941. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15942. {
  15943. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15944. }
  15945. } // END OF FOR CHAdeMO_QUANTITY
  15946. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15947. }
  15948. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15949. {
  15950. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15951. {
  15952. tempIndex = ((gun_index==2) ? 1: 0);
  15953. }
  15954. else
  15955. {
  15956. tempIndex = gun_index;
  15957. }
  15958. for (int index = 0; index < CCS_QUANTITY; index++)
  15959. {
  15960. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15961. {
  15962. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15963. }
  15964. } // END OF FOR CCS_QUANTITY
  15965. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15966. }
  15967. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15968. {
  15969. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15970. {
  15971. tempIndex = ((gun_index==2) ? 1: 0);
  15972. }
  15973. else
  15974. {
  15975. tempIndex = gun_index;
  15976. }
  15977. for (int index = 0; index < GB_QUANTITY; index++)
  15978. {
  15979. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15980. {
  15981. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15982. }
  15983. } // END OF FOR GB_QUANTITY
  15984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15985. }
  15986. else if(gunType[gun_index] == GUN_TYPE_DO)
  15987. {
  15988. tempIndex = gun_index;
  15989. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15990. {
  15991. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15992. {
  15993. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15994. }
  15995. }
  15996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15997. }
  15998. else
  15999. {
  16000. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16001. {
  16002. tempIndex = 2;
  16003. }
  16004. else
  16005. {
  16006. tempIndex = gun_index;
  16007. }
  16008. for (int index = 0; index < AC_QUANTITY; index++)
  16009. {
  16010. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16011. {
  16012. 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
  16013. }
  16014. } // END OF FOR AC_QUANTITY
  16015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16016. }
  16017. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16018. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  16019. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  16020. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16021. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  16022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16023. }
  16024. //2.5============================================== End SoC =========================================================
  16025. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  16026. {
  16027. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16028. 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))
  16029. {
  16030. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16031. {
  16032. tempIndex = ((gun_index==2) ? 1: 0);
  16033. }
  16034. else
  16035. {
  16036. tempIndex = gun_index;
  16037. }
  16038. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16039. {
  16040. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16041. {
  16042. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16043. {
  16044. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  16045. }
  16046. }
  16047. }
  16048. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16049. {
  16050. for (int index = 0; index < CCS_QUANTITY; index++)
  16051. {
  16052. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16053. {
  16054. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  16055. }
  16056. }
  16057. }
  16058. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16059. {
  16060. for (int index = 0; index < GB_QUANTITY; index++)
  16061. {
  16062. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16063. {
  16064. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  16065. }
  16066. }
  16067. }
  16068. else if(gunType[gun_index] == GUN_TYPE_DO)
  16069. {
  16070. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16071. {
  16072. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16073. {
  16074. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  16075. }
  16076. }
  16077. }
  16078. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  16080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16081. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  16082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  16083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16084. } // END FOR DC CASE
  16085. }
  16086. //2.6====================================== Current.Import L2 ==============================================
  16087. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16088. {
  16089. // AC 3 phase L2 current
  16090. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16091. {
  16092. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16093. {
  16094. tempIndex = 2;
  16095. }
  16096. else
  16097. {
  16098. tempIndex = gun_index;
  16099. }
  16100. for (int index = 0; index < AC_QUANTITY; index++)
  16101. {
  16102. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16103. {
  16104. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  16105. }
  16106. }// End of for AC_QUANTITY
  16107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  16108. }
  16109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16110. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  16111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  16112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  16113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16114. }
  16115. //2.7====================================== Current.Import L3 ==============================================
  16116. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16117. {
  16118. // AC 3 phase L3 current
  16119. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16120. {
  16121. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16122. {
  16123. tempIndex = 2;
  16124. }
  16125. else
  16126. {
  16127. tempIndex = gun_index;
  16128. }
  16129. for (int index = 0; index < AC_QUANTITY; index++)
  16130. {
  16131. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16132. {
  16133. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16134. }
  16135. }// End of for AC_QUANTITY
  16136. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16137. }
  16138. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16143. }
  16144. //2.9====================================== Voltage L2 ====================================================
  16145. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16146. {
  16147. // AC 3 phase L2 volatge
  16148. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16149. {
  16150. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16151. {
  16152. tempIndex = 2;
  16153. }
  16154. else
  16155. {
  16156. tempIndex = gun_index;
  16157. }
  16158. for (int index = 0; index < AC_QUANTITY; index++)
  16159. {
  16160. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16161. {
  16162. 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
  16163. }
  16164. } // END OF FOR AC_QUANTITY
  16165. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16166. }
  16167. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16168. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16169. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  16170. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  16171. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16172. }
  16173. //2.10====================================== Voltage L3 ====================================================
  16174. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16175. {
  16176. // AC 3 phase L3 volatge
  16177. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16178. {
  16179. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16180. {
  16181. tempIndex = 2;
  16182. }
  16183. else
  16184. {
  16185. tempIndex = gun_index;
  16186. }
  16187. for (int index = 0; index < AC_QUANTITY; index++)
  16188. {
  16189. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16190. {
  16191. 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
  16192. }
  16193. } // END OF FOR AC_QUANTITY
  16194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  16195. }
  16196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  16198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  16199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  16200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16201. }
  16202. //====================== Start SoC ================================
  16203. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  16204. {
  16205. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16206. 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))
  16207. {
  16208. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16209. {
  16210. tempIndex = ((gun_index==2) ? 1: 0);
  16211. }
  16212. else
  16213. {
  16214. tempIndex = gun_index;
  16215. }
  16216. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16217. {
  16218. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16219. {
  16220. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16221. {
  16222. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  16223. }
  16224. }
  16225. }
  16226. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16227. {
  16228. for (int index = 0; index < CCS_QUANTITY; index++)
  16229. {
  16230. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16231. {
  16232. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  16233. }
  16234. }
  16235. }
  16236. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16237. {
  16238. for (int index = 0; index < GB_QUANTITY; index++)
  16239. {
  16240. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16241. {
  16242. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16243. }
  16244. }
  16245. }
  16246. else if(gunType[gun_index] == GUN_TYPE_DO)
  16247. {
  16248. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16249. {
  16250. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16251. {
  16252. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16253. }
  16254. }
  16255. }
  16256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16261. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16262. } // END FOR DC CASE
  16263. }
  16264. //======================================== Message create ==============================================
  16265. json_object *StopTransaction = json_object_new_object();
  16266. json_object *transactionDatas = json_object_new_array();
  16267. json_object *sampledValues = json_object_new_array();
  16268. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  16269. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  16270. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  16271. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  16272. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  16273. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16274. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  16275. {
  16276. json_object *transactionData = json_object_new_object();
  16277. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  16278. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  16279. {
  16280. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  16281. {
  16282. json_object *sampledValue = json_object_new_object();
  16283. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  16284. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  16285. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  16286. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  16287. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  16288. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  16289. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  16290. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  16291. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  16292. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  16293. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  16294. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  16295. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  16296. json_object_array_add(sampledValues, sampledValue);
  16297. }
  16298. }
  16299. json_object_object_add(transactionData, "sampledValue", sampledValues);
  16300. json_object_array_add(transactionDatas, transactionData);
  16301. }
  16302. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  16303. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  16304. ,MESSAGE_TYPE_CALL
  16305. ,guid
  16306. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  16307. json_object_put(StopTransaction);
  16308. // Check File "TempStopTransaction" Exist
  16309. if((access(TempStopTransaction,F_OK))!=-1)
  16310. {
  16311. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16312. fclose(fopen(TempStopTransaction, "w"));
  16313. }
  16314. else
  16315. {
  16316. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16317. FILE *log = fopen(TempStopTransaction, "w+");
  16318. if(log == NULL)
  16319. {
  16320. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16321. return ;
  16322. }
  16323. else
  16324. {
  16325. fclose(log);
  16326. }
  16327. }
  16328. //Add TempStopTransaction | Update TempStopTransaction
  16329. // open file for writing
  16330. FILE *outfile;
  16331. outfile = fopen (TempStopTransaction, "a");
  16332. //DEBUG_INFO("data = %s\n", queuedata);
  16333. fputs(queuedata, outfile);
  16334. fputs("\n", outfile);
  16335. fclose (outfile);
  16336. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16337. }
  16338. void checkTempStopTransaction(int gun_index)
  16339. {
  16340. FILE *fptr1;
  16341. char ch;
  16342. char str[QUEUE_MESSAGE_LENGTH]={0};
  16343. char guid[37]={0};
  16344. char tempdata[65]={0};
  16345. char connectorStr[2]={0};
  16346. char TempStopTransaction[256];
  16347. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  16348. fptr1 = fopen(TempStopTransaction, "r");
  16349. //TempStopTransaction格式: 槍號,StopTransaction封包
  16350. if (!fptr1)
  16351. {
  16352. //printf(" File not found or unable to open the input file!!\n");
  16353. return ;
  16354. }
  16355. ch=fgetc(fptr1);
  16356. //printf(" Now the content of the file %s is : \n",fname);
  16357. rewind(fptr1);
  16358. if(ch!=EOF)
  16359. {
  16360. // copy all contents to the temporary file except the specific line
  16361. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16362. {
  16363. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16364. if(str[0]=='\0')
  16365. {
  16366. break;
  16367. }
  16368. //TempStopTransaction格式: 槍號,StopTransaction封包
  16369. strncpy(connectorStr, str, 1);
  16370. if(atoi(connectorStr) != (gun_index+1))
  16371. {
  16372. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  16373. fclose(fptr1);
  16374. return ;
  16375. }
  16376. //random_uuid(guid);
  16377. strncpy(guid, str+6, 36); //copy guid
  16378. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16379. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16380. {
  16381. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16382. }
  16383. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16384. OCPP_insert_transaction_msg(NO, str);
  16385. memset(str,0,ARRAY_SIZE(str));
  16386. }
  16387. }
  16388. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16389. fclose(fptr1);
  16390. remove(TempStopTransaction); // remove the original file
  16391. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16392. }
  16393. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16394. {
  16395. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16396. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16397. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16398. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16399. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16400. }
  16401. int GetWebSocketPingInterval(void)
  16402. {
  16403. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16404. }
  16405. int GetServerSign(void)
  16406. {
  16407. return server_sign;
  16408. }
  16409. uint8_t GetOcppSecurityProfile()
  16410. {
  16411. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16412. }
  16413. void GetOcppChargerBoxId(uint8_t *data)
  16414. {
  16415. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16416. }
  16417. void GetOcppSecurityPassword(uint8_t *data)
  16418. {
  16419. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16420. }
  16421. void SetOcppVersion(uint8_t *version)
  16422. {
  16423. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16424. DEBUG_INFO("ocpp version: %s\n", version);
  16425. if(strstr((char*)version, "ocpp1.6") != NULL)
  16426. {
  16427. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16428. }
  16429. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16430. {
  16431. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16432. system("pkill OcppBackend");
  16433. }
  16434. }
  16435. void SetServerSign(int value)
  16436. {
  16437. server_sign = value;
  16438. }
  16439. int GetBootNotificationInterval(void)
  16440. {
  16441. return BootNotificationInterval;
  16442. }
  16443. int GetInternetConn(void)
  16444. {
  16445. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16446. }
  16447. int GetBackendConnectionTimeout(void)
  16448. {
  16449. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16450. }
  16451. int isConnectorInitMode(int gun_index)
  16452. {
  16453. int tempIndex = 0;
  16454. int result = TRUE;
  16455. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16456. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16457. {
  16458. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16459. {
  16460. tempIndex = ((gun_index==2) ? 1: 0);
  16461. }
  16462. else
  16463. {
  16464. tempIndex = gun_index;
  16465. }
  16466. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16467. {
  16468. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16469. {
  16470. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16471. } //end of the same index
  16472. }//end of for CHAdeMO_QUANTITY
  16473. }
  16474. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16475. {
  16476. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16477. {
  16478. tempIndex = ((gun_index==2) ? 1: 0);
  16479. }
  16480. else
  16481. {
  16482. tempIndex = gun_index;
  16483. }
  16484. for (int index = 0; index < CCS_QUANTITY; index++)
  16485. {
  16486. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16487. {
  16488. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16489. } //end of the same index
  16490. } // end of for CCS_QUANTITY
  16491. }
  16492. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16493. {
  16494. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16495. {
  16496. tempIndex = ((gun_index==2) ? 1: 0);
  16497. }
  16498. else
  16499. {
  16500. tempIndex = gun_index;
  16501. }
  16502. for (int index = 0; index < GB_QUANTITY; index++)
  16503. {
  16504. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16505. {
  16506. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16507. } //end of the same index
  16508. } // end of for GB_QUANTITY
  16509. }
  16510. else if(gunType[gun_index] == GUN_TYPE_DO)
  16511. {
  16512. tempIndex = gun_index;
  16513. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16514. {
  16515. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16516. {
  16517. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16518. } //end of the same index
  16519. }
  16520. }
  16521. else
  16522. {
  16523. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16524. {
  16525. tempIndex = 2;
  16526. }
  16527. else
  16528. {
  16529. tempIndex = gun_index;
  16530. }
  16531. for (int index = 0; index < AC_QUANTITY; index++)
  16532. {
  16533. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16534. {
  16535. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16536. }//end of the same index
  16537. }//end of for AC_QUANTITY
  16538. }
  16539. return result;
  16540. }
  16541. void refreshProcDogTimer()
  16542. {
  16543. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  16544. }
  16545. void InitialSystemValue(void)
  16546. {
  16547. int connectorIndex = 0;
  16548. //int valueASCII = 0;
  16549. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16550. gunTotalNumber=0;
  16551. SystemInitial = 0;
  16552. locallistVersion=0;
  16553. BootNotificationInterval = 0;
  16554. authorizeRetryTimes = 0;
  16555. GunStatusInterval = 10;
  16556. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16557. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16558. //Hear Beat
  16559. HeartBeatWithNOResponse = 0;
  16560. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16561. FirstHeartBeat = 0;
  16562. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16563. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16564. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16565. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16566. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16567. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16568. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16569. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16570. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16571. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16572. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16573. memset(gunType, 0, ARRAY_SIZE(gunType));
  16574. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16575. {
  16576. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  16577. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  16578. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  16579. {
  16580. // DO series
  16581. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  16582. {
  16583. SystemInitial = SystemInitial + 1;
  16584. gunTotalNumber = gunTotalNumber + 1;
  16585. gunType[connectorIndex] = GUN_TYPE_DO;
  16586. connectorIndex = connectorIndex + 1;
  16587. }
  16588. }
  16589. else
  16590. {
  16591. // DM, DW, DS series
  16592. //check connector / socket type (index: 8, 9, 10)
  16593. for(int index=7; index <10 ; index++)
  16594. {
  16595. if(index != 8)
  16596. {
  16597. // DC Connector
  16598. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  16599. {
  16600. SystemInitial = SystemInitial + 1;
  16601. gunTotalNumber = gunTotalNumber + 1;
  16602. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  16603. connectorIndex = connectorIndex + 1;
  16604. }
  16605. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  16606. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  16607. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  16608. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  16609. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  16610. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  16611. {
  16612. SystemInitial = SystemInitial + 1;
  16613. gunTotalNumber = gunTotalNumber + 1;
  16614. gunType[connectorIndex] = GUN_TYPE_CCS;
  16615. connectorIndex = connectorIndex + 1;
  16616. }
  16617. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  16618. {
  16619. SystemInitial = SystemInitial + 1;
  16620. gunTotalNumber = gunTotalNumber + 1;
  16621. gunType[connectorIndex] = GUN_TYPE_GBT;
  16622. connectorIndex = connectorIndex + 1;
  16623. }
  16624. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  16625. {
  16626. SystemInitial = SystemInitial + 1;
  16627. gunTotalNumber = gunTotalNumber + 1;
  16628. gunType[connectorIndex] = GUN_TYPE_DO;
  16629. connectorIndex = connectorIndex + 1;
  16630. }
  16631. }
  16632. else
  16633. {
  16634. // AC Connector
  16635. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16636. {
  16637. SystemInitial = SystemInitial + 1;
  16638. gunTotalNumber = gunTotalNumber + 1;
  16639. gunType[connectorIndex] = GUN_TYPE_AC;
  16640. connectorIndex = connectorIndex + 1;
  16641. }
  16642. }
  16643. }
  16644. }
  16645. //DEBUG_INFO("DC ...\n");
  16646. }
  16647. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16648. {
  16649. //check connector / socket type (index: 8, 9, 10)
  16650. for(int index=7; index <10 ; index++)
  16651. {
  16652. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16653. {
  16654. SystemInitial = SystemInitial + 1;
  16655. gunTotalNumber = gunTotalNumber + 1;
  16656. gunType[connectorIndex] = GUN_TYPE_AC;
  16657. connectorIndex = connectorIndex + 1;
  16658. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16659. }
  16660. }
  16661. }
  16662. //Status && ConnectorPlugIn Setting
  16663. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16664. {
  16665. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16666. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16667. }
  16668. for (int index = 0; index < CCS_QUANTITY; index++)
  16669. {
  16670. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16671. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16672. }
  16673. for (int index = 0; index < GB_QUANTITY; index++)
  16674. {
  16675. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16676. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16677. }
  16678. for (int index = 0; index < AC_QUANTITY; index++)
  16679. {
  16680. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16681. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16682. }
  16683. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16684. {
  16685. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16686. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16687. }
  16688. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16689. {
  16690. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16691. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16692. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16693. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16694. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16695. }
  16696. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16697. clientTime.Heartbeat=time((time_t*)NULL);
  16698. sleep(1);
  16699. }
  16700. void LWS_Send(char *str)
  16701. {
  16702. //=====================================================
  16703. // Check InternetConn 0: disconnected, 1: connected
  16704. //====================================================
  16705. if(GetOcppConnStatus() == 0)
  16706. {
  16707. DEBUG_INFO("offline now !!!\n");
  16708. return;
  16709. }
  16710. // Only disable isWebsocketSendable operation initiated by charger
  16711. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16712. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16713. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16714. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16715. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16716. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16717. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16718. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16719. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16720. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16721. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16722. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16723. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16724. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16725. {
  16726. isWebsocketSendable = 0;
  16727. }
  16728. pthread_mutex_lock(&lock_send);
  16729. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16730. sprintf((char *)SendBuffer, "%s", str);
  16731. SendBufLen = strlen(str);
  16732. pthread_mutex_unlock(&lock_send);
  16733. lws_callback_on_writable(wsi_client);
  16734. //lws_service(context, 0);
  16735. //sleep(1);
  16736. }
  16737. void LWS_SendNow(char *str)
  16738. {
  16739. //=====================================================
  16740. // Check InternetConn 0: disconnected, 1: connected
  16741. //====================================================
  16742. if(GetOcppConnStatus() == 0)
  16743. {
  16744. DEBUG_INFO("offline now !!!\n");
  16745. return;
  16746. }
  16747. // Only disable isWebsocketSendable operation initiated by charger
  16748. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16749. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16750. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16751. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16752. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16753. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16754. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16755. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16756. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16757. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16758. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16759. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16760. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16761. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16762. {
  16763. isWebsocketSendable = 0;
  16764. }
  16765. pthread_mutex_lock(&lock_send);
  16766. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16767. sprintf((char *)SendBuffer, "%s", str);
  16768. SendBufLen = strlen(str);
  16769. pthread_mutex_unlock(&lock_send);
  16770. lws_callback_on_writable(wsi_client);
  16771. lws_service(context, 0);
  16772. //sleep(1);
  16773. }