MessageHandler.c 773 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193
  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: unknownkey
  21. //===============================
  22. static char unknownkey[10][20] = {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 localversion=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 statusModeChage[CONNECTOR_QUANTITY] = {FALSE};
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[21];
  75. char parentIdTag[21];
  76. char expiryDate[36];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //=============================================
  80. // OCPP HeartBeat Response Not Receive Counts
  81. //============================================
  82. static int HeartBeatWithNOResponse = 0;
  83. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct StructOCPPMeterValue
  93. {
  94. unsigned char TimeStamp[28];
  95. struct StructSampledValue SampledValue[10];
  96. };
  97. struct ClientTime
  98. {
  99. unsigned int Heartbeat;
  100. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  101. unsigned int StartTransaction;
  102. unsigned int StopTransaction;
  103. unsigned int MeterValues[CONNECTOR_QUANTITY];
  104. }clientTime;
  105. typedef union
  106. {
  107. //Operations Initiated by Central System
  108. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  109. struct
  110. {
  111. //CsMsgValue[0]
  112. unsigned char StatusNotificationReq:1; //bit 0,
  113. unsigned char StatusNotificationConf:1; //bit 1,
  114. unsigned char TriggerMeterValue:1; //bit 2,
  115. unsigned char :5; //bit 5~7
  116. }bits[CONNECTOR_QUANTITY];
  117. }CpinitiateMsg;
  118. CpinitiateMsg cpinitateMsg;
  119. //GetConfiguration Array
  120. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  121. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  123. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  124. #if 0
  125. static char *ChargePointErrorCodeStr[] = {
  126. MACROSTR(ConnectorLockFailure),
  127. MACROSTR(EVCommunicationError),
  128. MACROSTR(GroundFailure),
  129. MACROSTR(HighTemperature),
  130. MACROSTR(InternalError),
  131. MACROSTR(LocalListConflict),
  132. MACROSTR(NoError),
  133. MACROSTR(OtherError),
  134. MACROSTR(OverCurrentFailure),
  135. MACROSTR(OverVoltage),
  136. MACROSTR(PowerMeterFailure),
  137. MACROSTR(PowerSwitchFailure),
  138. MACROSTR(ReaderFailure),
  139. MACROSTR(ResetFailure),
  140. MACROSTR(UnderVoltage),
  141. MACROSTR(WeakSignal)
  142. };
  143. #endif
  144. static char * ChargePointStatusStr[] = {
  145. MACROSTR(Available),
  146. MACROSTR(Preparing),
  147. MACROSTR(Charging),
  148. MACROSTR(SuspendedEVSE),
  149. MACROSTR(SuspendedEV),
  150. MACROSTR(Finishing),
  151. MACROSTR(Reserved),
  152. MACROSTR(Unavailable),
  153. MACROSTR(Faulted)
  154. };
  155. static char *RegistrationStatusStr[] = {
  156. MACROSTR(Accepted),
  157. MACROSTR(Pending),
  158. MACROSTR(Rejected)
  159. };
  160. static char *AvailabilityTypeStr[] = {
  161. MACROSTR(Inoperative),
  162. MACROSTR(Operative)
  163. };
  164. static char *AvailabilityStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Rejected),
  167. MACROSTR(Scheduled)
  168. };
  169. static char *ConfigurationStatusStr[] = {
  170. MACROSTR(Accepted),
  171. MACROSTR(Rejected),
  172. MACROSTR(RebootRequired),
  173. MACROSTR(NotSupported)
  174. };
  175. static char *ClearCacheStatusStr[] = {
  176. MACROSTR(Accepted),
  177. MACROSTR(Rejected)
  178. };
  179. static char *ChargingProfilePurposeTypeStr[] = {
  180. MACROSTR(ChargePointMaxProfile),
  181. MACROSTR(TxDefaultProfile),
  182. MACROSTR(TxProfile)
  183. };
  184. static char *ChargingProfileStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected),
  187. MACROSTR(NotSupported)
  188. };
  189. static char *ClearChargingProfileStatusStr[] = {
  190. MACROSTR(Accepted),
  191. MACROSTR(Unknown)
  192. };
  193. static char *GetCompositeScheduleStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected)
  196. };
  197. static char *UpdateTypeStr[] = {
  198. MACROSTR(Differential),
  199. MACROSTR(Full)
  200. };
  201. static char *UpdateStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Failed),
  204. MACROSTR(NotSupported),
  205. MACROSTR(VersionMismatch)
  206. };
  207. static char *RemoteStartStopStatusStr[] = {
  208. MACROSTR(Accepted),
  209. MACROSTR(Rejected)
  210. };
  211. static char *ReservationStatusStr[] = {
  212. MACROSTR(Accepted),
  213. MACROSTR(Faulted),
  214. MACROSTR(Occupied),
  215. MACROSTR(Rejected),
  216. MACROSTR(Unavailable)
  217. };
  218. static char *ResetTypeStr[] = {
  219. MACROSTR(Hard),
  220. MACROSTR(Soft)
  221. };
  222. static char *ResetStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Rejected)
  225. };
  226. static char * DiagnosticsStatusStr[] = {
  227. MACROSTR(Idle),
  228. MACROSTR(Uploaded),
  229. MACROSTR(UploadFailed),
  230. MACROSTR(Uploading)
  231. };
  232. static char * FirmwareStatusStr[] = {
  233. MACROSTR(Downloaded),
  234. MACROSTR(DownloadFailed),
  235. MACROSTR(Downloading),
  236. MACROSTR(Idle),
  237. MACROSTR(InstallationFailed),
  238. MACROSTR(Installing),
  239. MACROSTR(Installed)
  240. };
  241. static char * MessageTriggerStr[] = {
  242. MACROSTR(BootNotification),
  243. MACROSTR(DiagnosticsStatusNotification),
  244. MACROSTR(FirmwareStatusNotification),
  245. MACROSTR(Heartbeat),
  246. MACROSTR(MeterValues),
  247. MACROSTR(StatusNotification)
  248. };
  249. static char * TriggerMessageStatusStr[] = {
  250. MACROSTR(Accepted),
  251. MACROSTR(Rejected),
  252. MACROSTR(NotImplemented)
  253. };
  254. static char * UnlockStatusStr[] = {
  255. MACROSTR(Unlocked),
  256. MACROSTR(UnlockFailed),
  257. MACROSTR(NotSupported)
  258. };
  259. #if 0
  260. static char * StopTransactionReasonStr[] = {
  261. MACROSTR(EmergencyStop),
  262. MACROSTR(EVDisconnected),
  263. MACROSTR(HardReset),
  264. MACROSTR(Local),
  265. MACROSTR(Other),
  266. MACROSTR(PowerLoss),
  267. MACROSTR(Reboot),
  268. MACROSTR(Remote),
  269. MACROSTR(SoftReset),
  270. MACROSTR(UnlockCommand),
  271. MACROSTR(DeAuthorized)
  272. };
  273. #endif
  274. static char * CancelReservationStatusStr[] = {
  275. MACROSTR(Accepted),
  276. MACROSTR(Rejected)
  277. };
  278. static char * ReadingContextStr[] = {
  279. MACROSTR(Interruption.Begin),
  280. MACROSTR(Interruption.End),
  281. MACROSTR(Other),
  282. MACROSTR(Sample.Clock),
  283. MACROSTR(Sample.Periodic),
  284. MACROSTR(Transaction.Begin),
  285. MACROSTR(Transaction.End),
  286. MACROSTR(Trigger)
  287. };
  288. static char * ValueFormatStr[] = {
  289. MACROSTR(Raw),
  290. MACROSTR(SignedData)
  291. };
  292. static char * MeasurandStr[] = {
  293. MACROSTR(Current.Export),
  294. MACROSTR(Current.Import),
  295. MACROSTR(Current.Offered),
  296. MACROSTR(Energy.Active.Export.Register),
  297. MACROSTR(Energy.Active.Import.Register),
  298. MACROSTR(Energy.Reactive.Export.Register),
  299. MACROSTR(Energy.Reactive.Import.Register),
  300. MACROSTR(Energy.Active.Export.Interval),
  301. MACROSTR(Energy.Active.Import.Interval),
  302. MACROSTR(Energy.Reactive.Export.Interval),
  303. MACROSTR(Energy.Reactive.Import.Interval),
  304. MACROSTR(Frequency),
  305. MACROSTR(Power.Active.Export),
  306. MACROSTR(Power.Active.Import),
  307. MACROSTR(Power.Factor),
  308. MACROSTR(Power.Offered),
  309. MACROSTR(Power.Reactive.ExportMACROSTR),
  310. MACROSTR(Power.Reactive.Import),
  311. MACROSTR(RPM),
  312. MACROSTR(SoC),
  313. MACROSTR(Temperature),
  314. MACROSTR(Voltage)
  315. };
  316. static char * LocationStr[] = {
  317. MACROSTR(Body),
  318. MACROSTR(Cable),
  319. MACROSTR(EV),
  320. MACROSTR(Inlet),
  321. MACROSTR(Outlet)
  322. };
  323. static char * PhaseStr[] = {
  324. MACROSTR(L1),
  325. MACROSTR(L2),
  326. MACROSTR(L3),
  327. MACROSTR(N),
  328. MACROSTR(L1-N),
  329. MACROSTR(L2-N),
  330. MACROSTR(L3-N),
  331. MACROSTR(L1-L2),
  332. MACROSTR(L2-L3),
  333. MACROSTR(L3-L1)
  334. };
  335. static char * UnitOfMeasureStr[] = {
  336. MACROSTR(Wh),
  337. MACROSTR(kWh),
  338. MACROSTR(varh),
  339. MACROSTR(kvarh),
  340. MACROSTR(W),
  341. MACROSTR(kW),
  342. MACROSTR(VA),
  343. MACROSTR(kVA),
  344. MACROSTR(var),
  345. MACROSTR(kvar),
  346. MACROSTR(A),
  347. MACROSTR(V),
  348. MACROSTR(Celsius),
  349. MACROSTR(Fahrenheit),
  350. MACROSTR(K),
  351. MACROSTR(Percent)
  352. };
  353. //=========================================
  354. // Save configuration
  355. //=========================================
  356. int runShellCmd(const char*cmd)
  357. {
  358. int result = FAIL;
  359. char buf[256];
  360. FILE *fp;
  361. fp = popen(cmd, "r");
  362. if(fp != NULL)
  363. {
  364. while(fgets(buf, sizeof(buf), fp) != NULL)
  365. {
  366. DEBUG_INFO("%s\n", buf);
  367. }
  368. result = PASS;
  369. }
  370. pclose(fp);
  371. return result;
  372. }
  373. int StoreUsrConfigData(struct SysConfigData *UsrData)
  374. {
  375. int result = PASS;
  376. int fd,wrd;
  377. unsigned int i,Chk;
  378. unsigned char *ptr, *BufTmp;
  379. int MtdBlockSize = 0x300000;
  380. Chk=0;
  381. ptr=(unsigned char *)UsrData;
  382. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  383. {
  384. memset(BufTmp,0,MtdBlockSize);
  385. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  386. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  387. Chk+=*(BufTmp+i);
  388. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  389. // Output configuration to file.
  390. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  391. if (fd < 0)
  392. {
  393. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  394. free(BufTmp);
  395. return 0;
  396. }
  397. wrd=write(fd, BufTmp, MtdBlockSize);
  398. close(fd);
  399. if(wrd<MtdBlockSize)
  400. {
  401. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  402. free(BufTmp);
  403. return 0;
  404. }
  405. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  406. DEBUG_INFO("Erase /dev/mtd10.\n");
  407. runShellCmd("flash_erase /dev/mtd10 0 0");
  408. DEBUG_INFO("Write /dev/mtd10.\n");
  409. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  410. DEBUG_INFO("Erase /dev/mtd11.\n");
  411. runShellCmd("flash_erase /dev/mtd11 0 0");
  412. DEBUG_INFO("Write /dev/mtd11.\n");
  413. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  414. system("rm -f /mnt/EvseConfig.bin");
  415. DEBUG_INFO("EvseConfig write to flash OK\n");
  416. }
  417. else
  418. {
  419. DEBUG_ERROR("alloc BlockSize NG\r\n");
  420. result = FAIL;
  421. }
  422. if(BufTmp!=NULL)
  423. free(BufTmp);
  424. return result;
  425. }
  426. //=========================================
  427. // Sqlite3 related function
  428. //=========================================
  429. static int selectSqlCount = 0;
  430. static int callback(void *data, int argc, char **argv, char **azColName){
  431. int i;
  432. //printf("%s: ", (const char*)data);
  433. selectSqlCount = argc;
  434. for(i = 0; i<argc; i++){
  435. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  436. }
  437. //printf("\n");
  438. return 0;
  439. }
  440. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  441. //int i;
  442. //printf("%s:\n", (const char*)data);
  443. localversion = argv[5] ? atoi(argv[5]) : 0;
  444. //printf("localversion=%d\n", localversion);
  445. return 0;
  446. }
  447. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  448. //printf("%s:\n", (const char*)data);
  449. //idTag
  450. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  451. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  452. //parentIdTag
  453. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  454. //expir_date
  455. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  456. //status
  457. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  458. //version
  459. if(columenCount > 5)
  460. idTagQuery.listVersionInt = atoi(columnValue[5]);
  461. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  462. return 0;
  463. }
  464. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  465. {
  466. // localversion = argv[5] ? atoi(argv[5]) : 0;
  467. // printf("localversion=%d\n", localversion);
  468. return 0;
  469. }
  470. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  471. {
  472. for (int i = 0; i < n_columns; i++)
  473. {
  474. DEBUG_INFO("%s\t", col_values[i]);
  475. }
  476. DEBUG_INFO("\n");
  477. return 0;
  478. }
  479. int OCPP_cleanLocalCache()
  480. {
  481. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  482. char *errMsg = 0;
  483. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  484. if (SQLITE_OK != rc)
  485. {
  486. DEBUG_INFO("SQL error: %s\n",errMsg);
  487. return FALSE;
  488. }
  489. return TRUE;
  490. }
  491. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  492. {
  493. int isSuccess = TRUE;
  494. int ret = 0;
  495. //const char* data = "Callback function called";
  496. char sql[300];
  497. char zErrMsg[200];
  498. memset(sql, 0, 300);
  499. memset(zErrMsg, 0, 200);
  500. 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);
  501. //* Execute SQL statement */
  502. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  503. if( ret != SQLITE_OK )
  504. {
  505. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  506. isSuccess = FALSE;
  507. }
  508. return isSuccess;
  509. }
  510. void OCPP_getIdTagFromLocalCache(char idTag[])
  511. {
  512. int rc = 0;
  513. char sql[100];
  514. char zErrMsg[100];
  515. memset(sql, 0, 100);
  516. memset(zErrMsg, 0, 100);
  517. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  518. memset(&idTagQuery, 0, sizeof(idTagQuery));
  519. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  520. /* Execute SQL statement */
  521. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  522. if( rc != SQLITE_OK )
  523. {
  524. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  525. }
  526. }
  527. void OCPP_getListVerion()
  528. {
  529. int rc = 0;
  530. // const char* data = "Callback function called";
  531. char sql[100];
  532. char zErrMsg[100];
  533. memset(sql, 0, 100);
  534. memset(zErrMsg, 0, 100);
  535. strcpy(sql, "select * from ocpp_auth_local order by idx");
  536. /* Execute SQL statement */
  537. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  538. if( rc != SQLITE_OK )
  539. {
  540. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  541. }
  542. }
  543. void OCPP_get_TableAuthlocalAllData(void)
  544. {
  545. int rc = 0;
  546. char sql[100];
  547. char zErrMsg[100];
  548. memset(sql, 0, 100);
  549. memset(zErrMsg, 0, 100);
  550. sprintf(sql,"select * from ocpp_auth_local ");
  551. /* Execute SQL statement */
  552. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  553. if( rc != SQLITE_OK )
  554. {
  555. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  556. }
  557. //return ver;
  558. }
  559. int OCPP_cleanLocalList()
  560. {
  561. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  562. char *errMsg = 0;
  563. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  564. if (SQLITE_OK != rc)
  565. {
  566. DEBUG_INFO("%s\n",errMsg);
  567. return FALSE;
  568. }
  569. return TRUE;
  570. }
  571. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  572. {
  573. int isSuccess = FALSE;
  574. int ret = 0;
  575. //const char* data = "Callback function called";
  576. char sql[300];
  577. char zErrMsg[200];
  578. memset(sql, 0, 300);
  579. memset(zErrMsg, 0, 200);
  580. 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);
  581. //* Execute SQL statement */
  582. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  583. if( ret != SQLITE_OK )
  584. {
  585. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  586. return isSuccess;
  587. }
  588. memset(sql, 0, 300);
  589. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  590. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  591. if( ret != SQLITE_OK )
  592. {
  593. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  594. return isSuccess;
  595. }
  596. isSuccess = TRUE;
  597. return isSuccess;
  598. }
  599. void OCPP_getIdTagFromLocalList(char idTag[])
  600. {
  601. int rc = 0;
  602. // const char* data = "Callback function called";
  603. char sql[100];
  604. char zErrMsg[100];
  605. memset(sql, 0, 100);
  606. memset(zErrMsg, 0, 100);
  607. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  608. memset(&idTagQuery, 0, sizeof(idTagQuery));
  609. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  610. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  611. /* Execute SQL statement */
  612. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  613. if( rc != SQLITE_OK )
  614. {
  615. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  616. }
  617. //return ver;
  618. }
  619. void OCPP_deleteIdTagFromLocalList(char idTag[])
  620. {
  621. //int ver = 0;
  622. //int isSuccess = FALSE;
  623. int rc = 0;
  624. char sql[100];
  625. char zErrMsg[100];
  626. memset(sql, 0, 100);
  627. memset(zErrMsg, 0, 100);
  628. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  629. //* Execute SQL statement */
  630. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  631. if( rc != SQLITE_OK )
  632. {
  633. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  634. }
  635. }
  636. int getCurrentYear()
  637. {
  638. int result = 0;
  639. time_t CurrentTime;
  640. struct tm *tm;
  641. CurrentTime = time(NULL);
  642. tm=localtime(&CurrentTime);
  643. result = (tm->tm_year + 1900);
  644. return result;
  645. }
  646. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  647. {
  648. int result = PASS;
  649. char* errMsg = NULL;
  650. char sqlStr[8192];
  651. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  652. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  653. {
  654. result = FAIL;
  655. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  656. }
  657. 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));
  658. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  659. {
  660. result = FAIL;
  661. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  662. }
  663. return result;
  664. }
  665. //==========================================
  666. // Check time passed since today
  667. //==========================================
  668. long long DiffTimebWithNow(struct timeb ST)
  669. {
  670. //return milli-second
  671. struct timeb ET;
  672. long long StartTime,StopTime;
  673. ftime(&ET);
  674. StartTime=(long long)ST.time;
  675. StopTime=(long long)ET.time;
  676. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  677. }
  678. int getTimePassSinceToday()
  679. {
  680. int result = -1;
  681. static time_t lastTime;
  682. time_t t;
  683. struct tm *tmStartToday;
  684. struct timeb tbStartToday;
  685. t=time(NULL);
  686. if(difftime(t, lastTime)>0)
  687. {
  688. tmStartToday=localtime(&t);
  689. tmStartToday->tm_hour = 0;
  690. tmStartToday->tm_min = 0;
  691. tmStartToday->tm_sec = 0;
  692. tbStartToday.time = mktime(tmStartToday);
  693. tbStartToday.millitm = 0;
  694. result = DiffTimebWithNow(tbStartToday)/1000;
  695. lastTime = t;
  696. }
  697. return result;
  698. }
  699. void getNowDatetime(uint8_t *data)
  700. {
  701. time_t t = time(NULL);
  702. struct tm tm = *localtime(&t);
  703. 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);
  704. }
  705. int syncDateTimeRTC(uint8_t *data)
  706. {
  707. struct ParsingResult
  708. {
  709. int result;
  710. int scanedElement;
  711. int year;
  712. int month;
  713. int mday;
  714. int hour;
  715. int min;
  716. int sec;
  717. int tz_hour;
  718. int tz_min;
  719. float minSec;
  720. }result;
  721. struct tm tmOrg;
  722. struct tm *tmTarget;
  723. struct timeb tbTarget;
  724. char buf[128];
  725. memset(&result, 0x00, sizeof(struct ParsingResult));
  726. result.result = PASS;
  727. if(strstr((char*)data, ".") != NULL)
  728. {
  729. // Original data with mini second
  730. if(strstr((char*)data, "Z") != NULL)
  731. {
  732. // Original data with Z
  733. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  734. &result.year,
  735. &result.month,
  736. &result.mday,
  737. &result.hour,
  738. &result.min,
  739. &result.sec,
  740. &result.minSec);
  741. }
  742. else
  743. {
  744. // Original data without Z
  745. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  746. &result.year,
  747. &result.month,
  748. &result.mday,
  749. &result.hour,
  750. &result.min,
  751. &result.sec,
  752. &result.minSec,
  753. &result.tz_hour,
  754. &result.tz_min);
  755. }
  756. }
  757. else
  758. {
  759. // Original data without mini second
  760. if(strstr((char*)data, "Z") != NULL)
  761. {
  762. // Original data with Z
  763. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  764. &result.year,
  765. &result.month,
  766. &result.mday,
  767. &result.hour,
  768. &result.min,
  769. &result.sec);
  770. }
  771. else
  772. {
  773. // Original data without Z
  774. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  775. &result.year,
  776. &result.month,
  777. &result.mday,
  778. &result.hour,
  779. &result.min,
  780. &result.sec,
  781. &result.tz_hour,
  782. &result.tz_min);
  783. }
  784. }
  785. tmOrg.tm_year = result.year - 1900;
  786. tmOrg.tm_mon = result.month - 1;
  787. tmOrg.tm_mday = result.mday;
  788. tmOrg.tm_hour = result.hour;
  789. tmOrg.tm_min = result.min;
  790. tmOrg.tm_sec = result.sec;
  791. tmOrg.tm_gmtoff = 0;
  792. tbTarget.time = mktime(&tmOrg);
  793. tbTarget.timezone = 0;
  794. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  795. tmTarget = gmtime(&tbTarget.time);
  796. 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);
  797. //DEBUG_INFO(" org date time: %s\n", data);
  798. //DEBUG_INFO("parse date time: %s\n", buf);
  799. system(buf);
  800. system("/sbin/hwclock -w --systohc");
  801. if(result.scanedElement < 6)
  802. result.result = FAIL;
  803. return result.result;
  804. }
  805. //==========================================
  806. // GetCompositeSchedule logic related function
  807. //==========================================
  808. int DiffTimebSec(struct timeb ST, struct timeb ET)
  809. {
  810. //return milli-second
  811. unsigned int StartTime,StopTime;
  812. StartTime=(unsigned int)ST.time;
  813. StopTime=(unsigned int)ET.time;
  814. return (StopTime-StartTime);
  815. }
  816. int DiffTimebWithNowSec(struct timeb ST)
  817. {
  818. //return milli-second
  819. struct timeb ET;
  820. unsigned int StartTime,StopTime;
  821. ftime(&ET);
  822. StartTime=(unsigned int)ST.time;
  823. StopTime=(unsigned int)ET.time;
  824. return (StopTime-StartTime);
  825. }
  826. int getStartStop(uint8_t *start, uint8_t *stop)
  827. {
  828. int result = -1;
  829. struct tm tmStart;
  830. struct timeb tbStart;
  831. struct tm tmStop;
  832. struct timeb tbStop;
  833. 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) &&
  834. (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))
  835. {
  836. //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);
  837. //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);
  838. tmStart.tm_year -= 1900;
  839. tmStart.tm_mon -= 1;
  840. tbStart.time = mktime(&tmStart);
  841. tbStart.millitm = 0;
  842. tmStop.tm_year -= 1900;
  843. tmStop.tm_mon -= 1;
  844. tbStop.time = mktime(&tmStop);
  845. tbStop.millitm = 0;
  846. result = DiffTimebSec(tbStart, tbStop);
  847. //DEBUG_INFO("getStartStop(): %d\n", result);
  848. }
  849. else
  850. {
  851. DEBUG_WARN("Start or stop date parsing error.\r\n");
  852. }
  853. return result;
  854. }
  855. int isOvertNow(uint8_t *start)
  856. {
  857. int result = NO;
  858. struct tm tmStart;
  859. struct timeb tbStart;
  860. 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))
  861. {
  862. //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);
  863. tmStart.tm_year -= 1900;
  864. tmStart.tm_mon -= 1;
  865. tbStart.time = mktime(&tmStart);
  866. tbStart.millitm = 0;
  867. if(DiffTimebWithNowSec(tbStart) <= 0)
  868. result = NO;
  869. else
  870. result = YES;
  871. }
  872. else
  873. {
  874. DEBUG_WARN("Start date parsing error.\n");
  875. }
  876. return result;
  877. }
  878. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  879. {
  880. int result = -1;
  881. struct tm tmStart;
  882. struct timeb tbStart;
  883. struct tm tmStop;
  884. struct timeb tbStop;
  885. 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) &&
  886. (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))
  887. {
  888. tmStart.tm_year -= 1900;
  889. tmStart.tm_mon -= 1;
  890. tbStart.time = mktime(&tmStart);
  891. tbStart.millitm = 0;
  892. tmStop.tm_year -= 1900;
  893. tmStop.tm_mon -= 1;
  894. tbStop.time = mktime(&tmStop);
  895. tbStop.millitm = 0;
  896. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  897. }
  898. return result;
  899. }
  900. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  901. {
  902. FILE *fp;
  903. char profileFileName[128];
  904. char *line = NULL;
  905. size_t len = 0;
  906. time_t CurrentTime;
  907. struct tm *tmComposite;
  908. struct StructChargingProfile maxProfile;
  909. struct StructChargingProfile defaultTxProfile;
  910. struct StructChargingProfile txProfile;
  911. struct StructChargingSchedulePeriod tmpPeriod;
  912. uint8_t limitMax=0;
  913. uint8_t limitDef=0;
  914. uint8_t limitTx=0;
  915. int compositePeriodIdx = 0;
  916. CurrentTime = time(NULL);
  917. tmComposite=localtime(&CurrentTime);
  918. 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);
  919. if(isUnitA)
  920. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  921. else
  922. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  923. compositeProfile->ChargingSchedule.Duration = durationReq;
  924. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  925. {
  926. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  927. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  928. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  929. }
  930. compositeProfile->ChargingProfileId = 0;
  931. compositeProfile->StackLevel = 99 ;
  932. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  933. maxProfile.ChargingProfileId = -1;
  934. defaultTxProfile.ChargingProfileId = -1;
  935. txProfile.ChargingProfileId = -1;
  936. maxProfile.ChargingSchedule.Duration = -1;
  937. defaultTxProfile.ChargingSchedule.Duration = -1;
  938. txProfile.ChargingSchedule.Duration = -1;
  939. system("rm -f /tmp/*.json");
  940. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  941. /*
  942. * Search valid charging profile
  943. */
  944. //DEBUG_INFO("====================================\n");
  945. // Search tx profile
  946. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  947. if((access(profileFileName, F_OK))!=-1)
  948. {
  949. fp = fopen(profileFileName, "r");
  950. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  951. {
  952. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  953. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  954. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  955. }
  956. txProfile.ChargingProfileId = -1;
  957. txProfile.StackLevel = -1;
  958. while(getline(&line, &len, fp) != -1)
  959. {
  960. json_object *obj = NULL;
  961. obj = json_tokener_parse(line);
  962. if(is_error(obj))
  963. {
  964. DEBUG_ERROR("Parse txProfile from file error.\n");
  965. }
  966. else
  967. {
  968. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  969. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  970. )
  971. {
  972. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  973. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  974. )
  975. {
  976. struct tm tmFrom, tmTo;
  977. struct timeb tbFrom, tbTo;
  978. 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) &&
  979. (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))
  980. {
  981. tmFrom.tm_year -= 1900;
  982. tmFrom.tm_mon -= 1;
  983. tbFrom.time = mktime(&tmFrom);
  984. tmTo.tm_year -= 1900;
  985. tmTo.tm_mon -= 1;
  986. tbTo.time = mktime(&tmTo);
  987. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  988. {
  989. if(txProfile.ChargingProfileId == -1)
  990. DEBUG_INFO("TxProfile found.\n");
  991. else
  992. DEBUG_INFO("TxProfile updated.\n");
  993. // Required item
  994. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  995. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  996. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  997. if(isUnitA)
  998. {
  999. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1000. 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++)
  1001. {
  1002. 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"));
  1003. 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?
  1004. 3:
  1005. 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")));
  1006. 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")));
  1007. }
  1008. }
  1009. else
  1010. {
  1011. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1012. 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++)
  1013. {
  1014. 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"));
  1015. 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?
  1016. 3:
  1017. 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")));
  1018. 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));
  1019. }
  1020. }
  1021. // Optional item
  1022. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1023. {
  1024. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1025. }
  1026. else
  1027. {
  1028. sprintf((char*)txProfile.ValidFrom, " ");
  1029. }
  1030. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1031. {
  1032. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1033. }
  1034. else
  1035. {
  1036. sprintf((char*)txProfile.ValidTo, " ");
  1037. }
  1038. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1039. {
  1040. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1041. }
  1042. else
  1043. {
  1044. sprintf((char*)txProfile.RecurrencyKind, " ");
  1045. }
  1046. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1047. {
  1048. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1049. }
  1050. else
  1051. {
  1052. txProfile.TransactionId = -1;
  1053. }
  1054. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1055. {
  1056. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1057. }
  1058. else
  1059. {
  1060. txProfile.ChargingSchedule.Duration = 86400;
  1061. }
  1062. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1063. {
  1064. 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")));
  1065. }
  1066. else
  1067. {
  1068. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1069. }
  1070. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1071. {
  1072. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1073. }
  1074. else
  1075. {
  1076. txProfile.ChargingSchedule.MinChargingRate = -1;
  1077. }
  1078. }
  1079. }
  1080. }
  1081. else
  1082. {
  1083. if(txProfile.ChargingProfileId == -1)
  1084. DEBUG_INFO("TxProfile found.\n");
  1085. else
  1086. DEBUG_INFO("TxProfile updated.\n");
  1087. // Required item
  1088. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1089. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1090. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1091. if(isUnitA)
  1092. {
  1093. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1094. 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++)
  1095. {
  1096. 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"));
  1097. 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?
  1098. 3:
  1099. 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")));
  1100. 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")));
  1101. }
  1102. }
  1103. else
  1104. {
  1105. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1106. 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++)
  1107. {
  1108. 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"));
  1109. 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?
  1110. 3:
  1111. 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")));
  1112. 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));
  1113. }
  1114. }
  1115. // Optional item
  1116. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1117. {
  1118. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1119. }
  1120. else
  1121. {
  1122. sprintf((char*)txProfile.ValidFrom, " ");
  1123. }
  1124. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1125. {
  1126. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1127. }
  1128. else
  1129. {
  1130. sprintf((char*)txProfile.ValidTo, " ");
  1131. }
  1132. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1133. {
  1134. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1135. }
  1136. else
  1137. {
  1138. sprintf((char*)txProfile.RecurrencyKind, " ");
  1139. }
  1140. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1141. {
  1142. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1143. }
  1144. else
  1145. {
  1146. txProfile.TransactionId = -1;
  1147. }
  1148. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1149. {
  1150. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1151. }
  1152. else
  1153. {
  1154. txProfile.ChargingSchedule.Duration = 86400;
  1155. }
  1156. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1157. {
  1158. 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")));
  1159. }
  1160. else
  1161. {
  1162. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1163. }
  1164. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1165. {
  1166. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1167. }
  1168. else
  1169. {
  1170. txProfile.ChargingSchedule.MinChargingRate = -1;
  1171. }
  1172. }
  1173. }
  1174. }
  1175. json_object_put(obj);
  1176. }
  1177. fclose(fp);
  1178. /*
  1179. if(txProfile.ChargingProfileId != -1)
  1180. {
  1181. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1182. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1183. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1184. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1185. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1186. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1187. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1188. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1189. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1190. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1191. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1192. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1193. {
  1194. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1195. {
  1196. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1197. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1198. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1199. }
  1200. }
  1201. }
  1202. else
  1203. DEBUG_INFO("TxProfile not found.\n");*/
  1204. }
  1205. // Search default tx profile
  1206. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1207. if((access(profileFileName, F_OK))==-1)
  1208. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1209. if((access(profileFileName, F_OK))!=-1)
  1210. {
  1211. fp = fopen(profileFileName, "r");
  1212. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1213. {
  1214. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1215. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1216. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1217. }
  1218. defaultTxProfile.ChargingProfileId = -1;
  1219. defaultTxProfile.StackLevel = -1;
  1220. while(getline(&line, &len, fp) != -1)
  1221. {
  1222. json_object *obj = NULL;
  1223. obj = json_tokener_parse(line);
  1224. if(is_error(obj))
  1225. {
  1226. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1227. }
  1228. else
  1229. {
  1230. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1231. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1232. )
  1233. {
  1234. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1235. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1236. )
  1237. {
  1238. struct tm tmFrom, tmTo;
  1239. struct timeb tbFrom, tbTo;
  1240. 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) &&
  1241. (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))
  1242. {
  1243. tmFrom.tm_year -= 1900;
  1244. tmFrom.tm_mon -= 1;
  1245. tbFrom.time = mktime(&tmFrom);
  1246. tmTo.tm_year -= 1900;
  1247. tmTo.tm_mon -= 1;
  1248. tbTo.time = mktime(&tmTo);
  1249. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1250. {
  1251. if(defaultTxProfile.ChargingProfileId == -1)
  1252. DEBUG_INFO("TxDefaultProfile found.\n");
  1253. else
  1254. DEBUG_INFO("TxDefaultProfile updated.\n");
  1255. // Required item
  1256. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1257. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1258. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1259. if(isUnitA)
  1260. {
  1261. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1262. 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++)
  1263. {
  1264. 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"));
  1265. 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?
  1266. 3:
  1267. 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")));
  1268. 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")));
  1269. }
  1270. }
  1271. else
  1272. {
  1273. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1274. 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++)
  1275. {
  1276. 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"));
  1277. 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?
  1278. 3:
  1279. 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")));
  1280. 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));
  1281. }
  1282. }
  1283. // Optional item
  1284. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1285. {
  1286. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1287. }
  1288. else
  1289. {
  1290. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1291. }
  1292. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1293. {
  1294. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1295. }
  1296. else
  1297. {
  1298. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1299. }
  1300. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1301. {
  1302. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1303. }
  1304. else
  1305. {
  1306. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1307. }
  1308. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1309. {
  1310. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1311. }
  1312. else
  1313. {
  1314. defaultTxProfile.TransactionId = -1;
  1315. }
  1316. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1317. {
  1318. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1319. }
  1320. else
  1321. {
  1322. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1323. }
  1324. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1325. {
  1326. 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")));
  1327. }
  1328. else
  1329. {
  1330. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1331. }
  1332. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1333. {
  1334. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1335. }
  1336. else
  1337. {
  1338. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1339. }
  1340. }
  1341. }
  1342. }
  1343. else
  1344. {
  1345. if(defaultTxProfile.ChargingProfileId == -1)
  1346. DEBUG_INFO("TxDefaultProfile found.\n");
  1347. else
  1348. DEBUG_INFO("TxDefaultProfile updated.\n");
  1349. // Required item
  1350. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1351. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1352. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1353. if(isUnitA)
  1354. {
  1355. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1356. 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++)
  1357. {
  1358. 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"));
  1359. 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?
  1360. 3:
  1361. 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")));
  1362. 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")));
  1363. }
  1364. }
  1365. else
  1366. {
  1367. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1368. 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++)
  1369. {
  1370. 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"));
  1371. 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?
  1372. 3:
  1373. 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")));
  1374. 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));
  1375. }
  1376. }
  1377. // Optional item
  1378. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1379. {
  1380. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1381. }
  1382. else
  1383. {
  1384. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1385. }
  1386. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1387. {
  1388. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1389. }
  1390. else
  1391. {
  1392. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1393. }
  1394. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1395. {
  1396. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1397. }
  1398. else
  1399. {
  1400. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1401. }
  1402. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1403. {
  1404. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1405. }
  1406. else
  1407. {
  1408. defaultTxProfile.TransactionId = -1;
  1409. }
  1410. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1411. {
  1412. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1413. }
  1414. else
  1415. {
  1416. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1417. }
  1418. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1419. {
  1420. 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")));
  1421. }
  1422. else
  1423. {
  1424. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1425. }
  1426. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1427. {
  1428. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1429. }
  1430. else
  1431. {
  1432. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1433. }
  1434. }
  1435. }
  1436. }
  1437. json_object_put(obj);
  1438. }
  1439. fclose(fp);
  1440. /*
  1441. if(defaultTxProfile.ChargingProfileId != -1)
  1442. {
  1443. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1444. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1445. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1446. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1447. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1448. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1449. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1450. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1451. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1452. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1453. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1454. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1455. {
  1456. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1457. {
  1458. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1459. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1460. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1461. }
  1462. }
  1463. }
  1464. else
  1465. DEBUG_INFO("TxDefaultProfile not found.\n");
  1466. DEBUG_INFO("------------------------------------\n");*/
  1467. }
  1468. // Search max profile
  1469. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1470. if((access(profileFileName, F_OK))!=-1)
  1471. {
  1472. fp = fopen(profileFileName, "r");
  1473. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1474. {
  1475. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1476. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1477. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1478. }
  1479. maxProfile.ChargingProfileId = -1;
  1480. maxProfile.StackLevel = -1;
  1481. while(getline(&line, &len, fp) != -1)
  1482. {
  1483. json_object *obj = NULL;
  1484. obj = json_tokener_parse(line);
  1485. if(is_error(obj))
  1486. {
  1487. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1488. }
  1489. else
  1490. {
  1491. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1492. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1493. )
  1494. {
  1495. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1496. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1497. )
  1498. {
  1499. struct tm tmFrom, tmTo;
  1500. struct timeb tbFrom, tbTo;
  1501. 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) &&
  1502. (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))
  1503. {
  1504. tmFrom.tm_year -= 1900;
  1505. tmFrom.tm_mon -= 1;
  1506. tbFrom.time = mktime(&tmFrom);
  1507. tmTo.tm_year -= 1900;
  1508. tmTo.tm_mon -= 1;
  1509. tbTo.time = mktime(&tmTo);
  1510. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1511. {
  1512. if(maxProfile.ChargingProfileId == -1)
  1513. DEBUG_INFO("MaxProfile found.\n");
  1514. else
  1515. DEBUG_INFO("MaxProfile updated.\n");
  1516. // Required item
  1517. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1518. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1519. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1520. if(isUnitA)
  1521. {
  1522. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1523. 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++)
  1524. {
  1525. 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"));
  1526. 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?
  1527. 3:
  1528. 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")));
  1529. 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")));
  1530. }
  1531. }
  1532. else
  1533. {
  1534. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1535. 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++)
  1536. {
  1537. 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"));
  1538. 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?
  1539. 3:
  1540. 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")));
  1541. 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));
  1542. }
  1543. }
  1544. // Optional item
  1545. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1546. {
  1547. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1548. }
  1549. else
  1550. {
  1551. sprintf((char*)maxProfile.ValidFrom, " ");
  1552. }
  1553. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1554. {
  1555. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1556. }
  1557. else
  1558. {
  1559. sprintf((char*)maxProfile.ValidTo, " ");
  1560. }
  1561. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1562. {
  1563. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1564. }
  1565. else
  1566. {
  1567. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1568. }
  1569. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1570. {
  1571. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1572. }
  1573. else
  1574. {
  1575. maxProfile.TransactionId = -1;
  1576. }
  1577. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1578. {
  1579. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1580. }
  1581. else
  1582. {
  1583. maxProfile.ChargingSchedule.Duration = 86400;
  1584. }
  1585. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1586. {
  1587. 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")));
  1588. }
  1589. else
  1590. {
  1591. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1592. }
  1593. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1594. {
  1595. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1596. }
  1597. else
  1598. {
  1599. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1600. }
  1601. }
  1602. }
  1603. }
  1604. else
  1605. {
  1606. if(maxProfile.ChargingProfileId == -1)
  1607. DEBUG_INFO("MaxProfile found.\n");
  1608. else
  1609. DEBUG_INFO("MaxProfile updated.\n");
  1610. // Required item
  1611. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1612. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1613. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1614. if(isUnitA)
  1615. {
  1616. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1617. 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++)
  1618. {
  1619. 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"));
  1620. 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?
  1621. 3:
  1622. 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")));
  1623. 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")));
  1624. }
  1625. }
  1626. else
  1627. {
  1628. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1629. 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++)
  1630. {
  1631. 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"));
  1632. 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?
  1633. 3:
  1634. 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")));
  1635. 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));
  1636. }
  1637. }
  1638. // Optional item
  1639. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1640. {
  1641. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1642. }
  1643. else
  1644. {
  1645. sprintf((char*)maxProfile.ValidFrom, " ");
  1646. }
  1647. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1648. {
  1649. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1650. }
  1651. else
  1652. {
  1653. sprintf((char*)maxProfile.ValidTo, " ");
  1654. }
  1655. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1656. {
  1657. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1658. }
  1659. else
  1660. {
  1661. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1662. }
  1663. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1664. {
  1665. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1666. }
  1667. else
  1668. {
  1669. maxProfile.TransactionId = -1;
  1670. }
  1671. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1672. {
  1673. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1674. }
  1675. else
  1676. {
  1677. maxProfile.ChargingSchedule.Duration = 86400;
  1678. }
  1679. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1680. {
  1681. 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")));
  1682. }
  1683. else
  1684. {
  1685. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1686. }
  1687. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1688. {
  1689. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1690. }
  1691. else
  1692. {
  1693. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1694. }
  1695. }
  1696. }
  1697. }
  1698. json_object_put(obj);
  1699. }
  1700. fclose(fp);
  1701. /*
  1702. if(maxProfile.ChargingProfileId !=-1)
  1703. {
  1704. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1705. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1706. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1707. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1708. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1709. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1710. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1711. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1712. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1713. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1714. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1715. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1716. {
  1717. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1718. {
  1719. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1720. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1721. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1722. }
  1723. }
  1724. }
  1725. else
  1726. DEBUG_INFO("MaxProfile not found.\n");
  1727. DEBUG_INFO("------------------------------------\n");*/
  1728. }
  1729. /*
  1730. * Align found profile start schedule & periods
  1731. */
  1732. //DEBUG_INFO("====================================\n");
  1733. /*
  1734. // For local test usage, force modify found profile start schedule info
  1735. 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);
  1736. 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);
  1737. 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);
  1738. */
  1739. if(txProfile.ChargingProfileId != -1)
  1740. {
  1741. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1742. {
  1743. if(txProfile.ChargingSchedule.Duration != -1)
  1744. {
  1745. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1746. 0:
  1747. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1748. }
  1749. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1750. {
  1751. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1752. {
  1753. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1754. 0:
  1755. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1756. if(idxPeriod > 0)
  1757. {
  1758. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1759. {
  1760. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1761. }
  1762. }
  1763. }
  1764. }
  1765. }
  1766. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1767. {
  1768. if(txProfile.ChargingSchedule.Duration != -1)
  1769. {
  1770. txProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1771. 0:
  1772. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1773. }
  1774. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1775. {
  1776. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1777. {
  1778. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1779. 0:
  1780. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1781. if(idxPeriod > 0)
  1782. {
  1783. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1784. {
  1785. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1786. }
  1787. }
  1788. }
  1789. }
  1790. }
  1791. else
  1792. {
  1793. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1794. {
  1795. if(txProfile.ChargingSchedule.Duration != -1)
  1796. {
  1797. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1798. 0:
  1799. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1800. }
  1801. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1802. {
  1803. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1804. {
  1805. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1806. 0:
  1807. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1808. if(idxPeriod > 0)
  1809. {
  1810. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1811. {
  1812. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1813. }
  1814. }
  1815. }
  1816. }
  1817. }
  1818. else
  1819. {
  1820. if(txProfile.ChargingSchedule.Duration != -1)
  1821. {
  1822. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1823. 0:
  1824. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1825. }
  1826. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1827. {
  1828. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1829. {
  1830. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1831. 0:
  1832. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1833. if(idxPeriod > 0)
  1834. {
  1835. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1836. {
  1837. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1838. }
  1839. }
  1840. }
  1841. }
  1842. }
  1843. }
  1844. /*
  1845. DEBUG_INFO("txProfile after align.\n");
  1846. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1847. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1848. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1849. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1850. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1851. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1852. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1853. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1854. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1855. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1856. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1857. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1858. {
  1859. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1860. {
  1861. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1862. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1863. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1864. }
  1865. }*/
  1866. }
  1867. if(defaultTxProfile.ChargingProfileId != -1)
  1868. {
  1869. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1870. {
  1871. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1872. {
  1873. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1874. 0:
  1875. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1876. }
  1877. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1878. {
  1879. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1880. {
  1881. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1882. 0:
  1883. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1884. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1885. {
  1886. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1887. }
  1888. if(idxPeriod > 0)
  1889. {
  1890. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1891. {
  1892. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1893. }
  1894. }
  1895. }
  1896. }
  1897. }
  1898. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1899. {
  1900. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1901. {
  1902. defaultTxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1903. 0:
  1904. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1905. }
  1906. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1907. {
  1908. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1909. {
  1910. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1911. 0:
  1912. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1913. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1914. {
  1915. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1916. }
  1917. if(idxPeriod > 0)
  1918. {
  1919. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1920. {
  1921. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1922. }
  1923. }
  1924. }
  1925. }
  1926. }
  1927. else
  1928. {
  1929. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1930. {
  1931. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1932. {
  1933. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1934. 0:
  1935. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1936. }
  1937. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1938. {
  1939. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1940. {
  1941. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1942. 0:
  1943. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1944. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1945. {
  1946. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1947. }
  1948. if(idxPeriod > 0)
  1949. {
  1950. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1951. {
  1952. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1953. }
  1954. }
  1955. }
  1956. }
  1957. }
  1958. else
  1959. {
  1960. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1961. {
  1962. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1963. 0:
  1964. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1965. }
  1966. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1967. {
  1968. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1969. {
  1970. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1971. 0:
  1972. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1973. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1974. {
  1975. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1976. }
  1977. if(idxPeriod > 0)
  1978. {
  1979. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1980. {
  1981. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1982. }
  1983. }
  1984. }
  1985. }
  1986. }
  1987. }
  1988. /*
  1989. DEBUG_INFO("defaultTxProfile after align.\n");
  1990. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1991. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1992. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1993. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1994. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1995. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1996. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1997. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1998. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1999. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2000. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2001. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2002. {
  2003. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2004. {
  2005. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2006. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2007. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2008. }
  2009. }
  2010. DEBUG_INFO("------------------------------------\n");*/
  2011. }
  2012. if(maxProfile.ChargingProfileId != -1)
  2013. {
  2014. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2015. {
  2016. if(maxProfile.ChargingSchedule.Duration != -1)
  2017. {
  2018. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2019. 0:
  2020. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2021. }
  2022. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2023. {
  2024. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2025. {
  2026. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2027. 0:
  2028. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2029. if(idxPeriod > 0)
  2030. {
  2031. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2032. {
  2033. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2034. }
  2035. }
  2036. }
  2037. }
  2038. }
  2039. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2040. {
  2041. if(maxProfile.ChargingSchedule.Duration != -1)
  2042. {
  2043. maxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2044. 0:
  2045. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2046. }
  2047. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2048. {
  2049. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2050. {
  2051. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2052. 0:
  2053. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2054. if(idxPeriod > 0)
  2055. {
  2056. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2057. {
  2058. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2059. }
  2060. }
  2061. }
  2062. }
  2063. }
  2064. else
  2065. {
  2066. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2067. {
  2068. if(maxProfile.ChargingSchedule.Duration != -1)
  2069. {
  2070. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2071. 0:
  2072. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2073. }
  2074. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2075. {
  2076. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2077. {
  2078. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2079. 0:
  2080. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2081. if(idxPeriod > 0)
  2082. {
  2083. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2084. {
  2085. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2086. }
  2087. }
  2088. }
  2089. }
  2090. }
  2091. else
  2092. {
  2093. if(maxProfile.ChargingSchedule.Duration != -1)
  2094. {
  2095. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2096. 0:
  2097. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2098. }
  2099. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2100. {
  2101. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2102. {
  2103. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2104. 0:
  2105. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2106. if(idxPeriod > 0)
  2107. {
  2108. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2109. {
  2110. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2111. }
  2112. }
  2113. }
  2114. }
  2115. }
  2116. }
  2117. /*
  2118. DEBUG_INFO("MaxProfile after align.\n");
  2119. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2120. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2121. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2122. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2123. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2124. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2125. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2126. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2127. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2128. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2129. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2130. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2131. {
  2132. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2133. {
  2134. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2135. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2136. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2137. }
  2138. }
  2139. DEBUG_INFO("------------------------------------\n");*/
  2140. }
  2141. /*
  2142. * Merge to conposite schedule
  2143. */
  2144. //DEBUG_INFO("====================================\n");
  2145. // Find each profile period quantity
  2146. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2147. {
  2148. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2149. limitMax = idx+1;
  2150. }
  2151. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2152. {
  2153. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2154. limitDef = idx+1;
  2155. }
  2156. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2157. {
  2158. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2159. limitTx = idx+1;
  2160. }
  2161. // TxProfile found, composite schedule based on it
  2162. if(txProfile.ChargingProfileId != -1)
  2163. {
  2164. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2165. {
  2166. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2167. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2168. (txProfile.ChargingSchedule.Duration > 0))
  2169. {
  2170. if(maxProfile.ChargingProfileId != -1)
  2171. {
  2172. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2173. {
  2174. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2175. {
  2176. if((maxProfile.ChargingSchedule.Duration > 0))
  2177. {
  2178. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2179. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2180. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2181. }
  2182. else
  2183. {
  2184. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2185. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2186. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2187. }
  2188. }
  2189. if(idxMaxPeriod == (limitMax-1))
  2190. {
  2191. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2192. {
  2193. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2194. {
  2195. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2196. compositePeriodIdx++;
  2197. }
  2198. else
  2199. {
  2200. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2201. }
  2202. }
  2203. }
  2204. }
  2205. }
  2206. else
  2207. {
  2208. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2209. {
  2210. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2211. compositePeriodIdx++;
  2212. }
  2213. else
  2214. {
  2215. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2216. }
  2217. }
  2218. }
  2219. if(idxTxPeriod == (limitTx-1))
  2220. {
  2221. if(defaultTxProfile.ChargingProfileId != -1)
  2222. {
  2223. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2224. {
  2225. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2226. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2227. (defaultTxProfile.ChargingSchedule.Duration>0))
  2228. {
  2229. if(maxProfile.ChargingProfileId != -1)
  2230. {
  2231. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2232. {
  2233. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2234. {
  2235. if((maxProfile.ChargingSchedule.Duration > 0))
  2236. {
  2237. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2238. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2239. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2240. }
  2241. else
  2242. {
  2243. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2244. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2245. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2246. }
  2247. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2248. {
  2249. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2250. {
  2251. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2252. compositePeriodIdx++;
  2253. }
  2254. else
  2255. {
  2256. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2257. }
  2258. }
  2259. // Delete duplicate period
  2260. if(compositePeriodIdx > 1)
  2261. {
  2262. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2263. {
  2264. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2265. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2266. compositePeriodIdx -= 1;
  2267. }
  2268. }
  2269. }
  2270. else
  2271. break;
  2272. }
  2273. }
  2274. else
  2275. {
  2276. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2277. {
  2278. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2279. compositePeriodIdx++;
  2280. }
  2281. else
  2282. {
  2283. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2284. }
  2285. }
  2286. }
  2287. }
  2288. }
  2289. }
  2290. }
  2291. }
  2292. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2293. else if(defaultTxProfile.ChargingProfileId != -1)
  2294. {
  2295. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2296. {
  2297. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2298. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2299. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2300. {
  2301. if(maxProfile.ChargingProfileId != -1)
  2302. {
  2303. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2304. {
  2305. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2306. {
  2307. if((maxProfile.ChargingSchedule.Duration > 0))
  2308. {
  2309. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2310. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2311. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2312. }
  2313. else
  2314. {
  2315. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2316. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2317. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2318. }
  2319. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2320. {
  2321. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2322. {
  2323. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2324. compositePeriodIdx++;
  2325. }
  2326. else
  2327. {
  2328. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2329. }
  2330. }
  2331. // Delete duplicate period
  2332. if(compositePeriodIdx > 1)
  2333. {
  2334. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2335. {
  2336. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2337. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2338. compositePeriodIdx -= 1;
  2339. }
  2340. }
  2341. }
  2342. else
  2343. break;
  2344. }
  2345. }
  2346. else
  2347. {
  2348. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2349. {
  2350. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2351. compositePeriodIdx++;
  2352. }
  2353. else
  2354. {
  2355. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2356. }
  2357. }
  2358. }
  2359. }
  2360. }
  2361. // Fill other period by MaxProfile
  2362. if(maxProfile.ChargingProfileId != -1)
  2363. {
  2364. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2365. {
  2366. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2367. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2368. (maxProfile.ChargingSchedule.Duration > 0))
  2369. {
  2370. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2371. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2372. {
  2373. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2374. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2375. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2376. }
  2377. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2378. {
  2379. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  2380. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2381. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2382. }
  2383. if(tmpPeriod.Limit != -1)
  2384. {
  2385. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2386. {
  2387. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2388. {
  2389. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2390. compositePeriodIdx++;
  2391. }
  2392. else
  2393. {
  2394. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2395. }
  2396. }
  2397. // Delete duplicate period
  2398. if(compositePeriodIdx > 1)
  2399. {
  2400. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2401. {
  2402. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2403. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2404. compositePeriodIdx -= 1;
  2405. }
  2406. }
  2407. }
  2408. }
  2409. }
  2410. }
  2411. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  2412. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2413. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2414. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2415. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2416. {
  2417. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2418. {
  2419. compositeProfile->ChargingProfileId = 1;
  2420. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2421. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2422. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2423. }
  2424. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2425. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2426. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2427. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2428. }
  2429. if(line)
  2430. free(line);
  2431. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  2432. }
  2433. //==========================================
  2434. // Init all share memory
  2435. //==========================================
  2436. int InitShareMemory()
  2437. {
  2438. int result = PASS;
  2439. int MeterSMId;
  2440. //creat ShmSysConfigAndInfo
  2441. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2442. {
  2443. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2444. result = FAIL;
  2445. }
  2446. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2447. {
  2448. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2449. result = FAIL;
  2450. }
  2451. else
  2452. {}
  2453. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2454. {
  2455. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2456. result = FAIL;
  2457. }
  2458. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2459. {
  2460. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2461. result = FAIL;
  2462. }
  2463. else
  2464. {}
  2465. //creat ShmPsuData
  2466. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2467. {
  2468. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2469. result = FAIL;
  2470. }
  2471. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2472. {
  2473. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2474. result = FAIL;
  2475. }
  2476. else
  2477. {}
  2478. //creat ShmOCPP16Data
  2479. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2480. {
  2481. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2482. result = FAIL;
  2483. }
  2484. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2485. {
  2486. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2487. result = FAIL;
  2488. }
  2489. else
  2490. {}
  2491. /****************************** For Initial Settings************************************************/
  2492. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2493. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2494. // allocate Configuration memory address
  2495. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2496. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2497. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2498. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2499. //offline MeterValue Interval
  2500. TempMeterValueInterval = 0;
  2501. return result;
  2502. }
  2503. int ProcessShareMemory()
  2504. {
  2505. if(InitShareMemory() == FAIL)
  2506. {
  2507. DEBUG_ERROR("InitShareMemory NG\n");
  2508. if(ShmStatusCodeData!=NULL)
  2509. {
  2510. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2511. }
  2512. sleep(5);
  2513. return FAIL;
  2514. }
  2515. return PASS;
  2516. }
  2517. void CheckSystemValue(void)
  2518. {
  2519. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2520. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2521. char filenmae[100]={0};
  2522. char str[100]={0};
  2523. int tempIndex = 0;
  2524. //===============================
  2525. // send Heartbeat
  2526. //===============================
  2527. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2528. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2529. {
  2530. clientTime.Heartbeat=time((time_t*)NULL);
  2531. if(server_sign == TRUE)
  2532. {
  2533. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2534. }
  2535. else
  2536. {
  2537. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2538. }
  2539. }
  2540. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2541. {
  2542. //parameter for test
  2543. sendHeartbeatRequest(0);
  2544. //==============================================
  2545. // Reset Waiting Time
  2546. //==============================================
  2547. HeartBeatWithNOResponse += 1;
  2548. }
  2549. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2550. {
  2551. //==========================================
  2552. // csu trigger DataTransferReq
  2553. //==========================================
  2554. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2555. {
  2556. sendDataTransferRequest(gun_index);
  2557. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2558. }
  2559. //===============================
  2560. // CSU Trigger Authorize Request
  2561. //===============================
  2562. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2563. {
  2564. sendAuthorizeRequest(0);
  2565. authorizeRetryTimes = authorizeRetryTimes + 1;
  2566. if(authorizeRetryTimes < 3)
  2567. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2568. }
  2569. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2570. {
  2571. authorizeRetryTimes = 0;
  2572. SetOcppConnStatus(FALSE);
  2573. server_sign = FALSE;
  2574. }
  2575. 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))
  2576. {
  2577. sendAuthorizeRequest(0);
  2578. }
  2579. //==============================================
  2580. // CSU Trigger Smart Charging Profilw
  2581. //==============================================
  2582. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2583. {
  2584. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  2585. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2586. }
  2587. //==============================================
  2588. // Charger start transaction
  2589. //==============================================
  2590. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2591. {
  2592. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2593. sendStartTransactionRequest(gun_index);
  2594. clientTime.StartTransaction = time((time_t*)NULL);
  2595. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2596. storeTempStopTransaction(gun_index);
  2597. }
  2598. //==============================================
  2599. // Charger stop transaction
  2600. //==============================================
  2601. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2602. {
  2603. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2604. sendStopTransactionRequest(gun_index);
  2605. clientTime.StopTransaction = time((time_t*)NULL);
  2606. }
  2607. //==============================================
  2608. // Charger status report
  2609. //==============================================
  2610. //--- Check Mode Change ---//
  2611. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2612. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2613. {
  2614. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2615. {
  2616. tempIndex = ((gun_index==2) ? 1: 0);
  2617. }
  2618. else
  2619. {
  2620. tempIndex = gun_index;
  2621. }
  2622. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2623. {
  2624. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2625. {
  2626. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2627. {
  2628. // Sent unplug message for California pricing logic
  2629. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2630. {
  2631. uint8_t ts[20];
  2632. getNowDatetime(ts);
  2633. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2634. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2635. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2636. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2637. }
  2638. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2639. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2640. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2641. statusModeChage[gun_index] = TRUE;
  2642. }
  2643. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2644. {
  2645. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2646. if((access(filenmae,F_OK))!=-1)
  2647. {
  2648. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2649. sprintf(str,"rm -f %s",filenmae);
  2650. system(str);
  2651. }
  2652. }
  2653. #if 1 // for TempStopTransaction
  2654. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2655. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2656. {
  2657. checkTempStopTransaction(gun_index);
  2658. }
  2659. #endif
  2660. }
  2661. }
  2662. }
  2663. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2664. {
  2665. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2666. {
  2667. tempIndex = ((gun_index==2) ? 1: 0);
  2668. }
  2669. else
  2670. {
  2671. tempIndex = gun_index;
  2672. }
  2673. for (int index = 0; index < CCS_QUANTITY; index++)
  2674. {
  2675. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2676. {
  2677. 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]*/ )
  2678. {
  2679. // Sent unplug message for California pricing logic
  2680. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2681. {
  2682. uint8_t ts[20];
  2683. getNowDatetime(ts);
  2684. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2685. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2686. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2687. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2688. }
  2689. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2690. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2691. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2692. statusModeChage[gun_index] = TRUE;
  2693. }
  2694. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2695. {
  2696. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2697. if((access(filenmae,F_OK))!=-1)
  2698. {
  2699. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2700. sprintf(str,"rm -f %s",filenmae);
  2701. system(str);
  2702. }
  2703. }
  2704. #if 1 // for TempStopTransaction
  2705. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2706. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2707. {
  2708. checkTempStopTransaction(gun_index);
  2709. }
  2710. #endif
  2711. }
  2712. }
  2713. }
  2714. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2715. {
  2716. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2717. {
  2718. tempIndex = ((gun_index==2) ? 1: 0);
  2719. }
  2720. else
  2721. {
  2722. tempIndex = gun_index;
  2723. }
  2724. for (int index = 0; index < GB_QUANTITY; index++)
  2725. {
  2726. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2727. {
  2728. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2729. {
  2730. // Sent unplug message for California pricing logic
  2731. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2732. {
  2733. uint8_t ts[20];
  2734. getNowDatetime(ts);
  2735. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2736. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2737. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2738. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2739. }
  2740. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2741. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2742. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2743. statusModeChage[gun_index] = TRUE;
  2744. }
  2745. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2746. {
  2747. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2748. if((access(filenmae,F_OK))!=-1)
  2749. {
  2750. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2751. sprintf(str,"rm -f %s",filenmae);
  2752. system(str);
  2753. }
  2754. }
  2755. #if 1 // for TempStopTransaction
  2756. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2757. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2758. {
  2759. checkTempStopTransaction(gun_index);
  2760. }
  2761. #endif
  2762. }
  2763. }
  2764. }
  2765. else if(gunType[gun_index] == GUN_TYPE_DO)
  2766. {
  2767. tempIndex = gun_index;
  2768. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2769. {
  2770. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2771. {
  2772. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2773. {
  2774. // Sent unplug message for California pricing logic
  2775. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2776. {
  2777. uint8_t ts[20];
  2778. getNowDatetime(ts);
  2779. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2780. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2781. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2782. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2783. }
  2784. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2785. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2786. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2787. statusModeChage[gun_index] = TRUE;
  2788. }
  2789. 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
  2790. {
  2791. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2792. if((access(filenmae,F_OK))!=-1)
  2793. {
  2794. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2795. sprintf(str,"rm -f %s",filenmae);
  2796. system(str);
  2797. }
  2798. }
  2799. #if 1 // for TempStopTransaction
  2800. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  2801. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2802. {
  2803. checkTempStopTransaction(gun_index);
  2804. }
  2805. #endif
  2806. }
  2807. }
  2808. }
  2809. else
  2810. {
  2811. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2812. {
  2813. tempIndex = 2;
  2814. }
  2815. else
  2816. {
  2817. tempIndex = gun_index;
  2818. }
  2819. for (int index = 0; index < AC_QUANTITY; index++)
  2820. {
  2821. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2822. {
  2823. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2824. {
  2825. // Sent unplug message for California pricing logic
  2826. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2827. {
  2828. uint8_t ts[20];
  2829. getNowDatetime(ts);
  2830. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2831. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2832. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  2833. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  2834. }
  2835. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2836. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2837. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2838. statusModeChage[gun_index] = TRUE;
  2839. }
  2840. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2841. {
  2842. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2843. if((access(filenmae,F_OK))!=-1)
  2844. {
  2845. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2846. sprintf(str,"rm -f %s",filenmae);
  2847. system(str);
  2848. }
  2849. }
  2850. #if 1 // for TempStopTransaction
  2851. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2852. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2853. {
  2854. checkTempStopTransaction(gun_index);
  2855. }
  2856. #endif
  2857. }
  2858. }// END
  2859. }
  2860. if(isWebsocketSendable && (server_sign == TRUE) &&
  2861. (
  2862. (statusModeChage[gun_index] == TRUE) ||
  2863. //((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
  2864. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5))
  2865. )
  2866. )
  2867. {
  2868. if(SystemInitial > 0)
  2869. SystemInitial -= 1;
  2870. sendStatusNotificationRequest(gun_index);
  2871. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2872. statusModeChage[gun_index] = FALSE;
  2873. }
  2874. //==============================================
  2875. // Meter report
  2876. //==============================================
  2877. // Trigger MeterValue
  2878. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2879. {
  2880. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2881. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2882. }
  2883. // ClockAlign MeterValue
  2884. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2885. {
  2886. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2887. {
  2888. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2889. {
  2890. tempIndex = ((gun_index==2) ? 1: 0);
  2891. }
  2892. else
  2893. {
  2894. tempIndex = gun_index;
  2895. }
  2896. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2897. {
  2898. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2899. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2900. {
  2901. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2902. {
  2903. reqClockAlignMeter[gun_index] = 1;
  2904. }
  2905. }
  2906. }// End for CHAdeMO
  2907. }
  2908. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2909. {
  2910. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2911. {
  2912. tempIndex = ((gun_index==2) ? 1: 0);
  2913. }
  2914. else
  2915. {
  2916. tempIndex = gun_index;
  2917. }
  2918. for (int index = 0; index < CCS_QUANTITY; index++)
  2919. {
  2920. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2921. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2922. {
  2923. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2924. {
  2925. reqClockAlignMeter[gun_index] = 1;
  2926. }
  2927. }
  2928. } // End for CCS
  2929. }
  2930. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2931. {
  2932. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2933. {
  2934. tempIndex = ((gun_index==2) ? 1: 0);
  2935. }
  2936. else
  2937. {
  2938. tempIndex = gun_index;
  2939. }
  2940. for (int index = 0; index < GB_QUANTITY; index++)
  2941. {
  2942. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2943. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2944. {
  2945. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2946. {
  2947. reqClockAlignMeter[gun_index] = 1;
  2948. }
  2949. }
  2950. }// End for GB
  2951. }
  2952. else if(gunType[gun_index] == GUN_TYPE_DO)
  2953. {
  2954. tempIndex = gun_index;
  2955. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2956. {
  2957. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2958. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2959. {
  2960. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  2961. {
  2962. reqClockAlignMeter[gun_index] = 1;
  2963. }
  2964. }
  2965. }
  2966. }
  2967. else
  2968. {
  2969. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2970. {
  2971. tempIndex = 2;
  2972. }
  2973. else
  2974. {
  2975. tempIndex = gun_index;
  2976. }
  2977. for (int index = 0; index < AC_QUANTITY; index++)
  2978. {
  2979. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2980. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2981. {
  2982. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2983. {
  2984. reqClockAlignMeter[gun_index] = 1;
  2985. }
  2986. }
  2987. }//End for AC
  2988. }
  2989. if(reqClockAlignMeter[gun_index] == 1)
  2990. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2991. }
  2992. // Sample period MeterValue
  2993. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1))))
  2994. {
  2995. //check Transaction active
  2996. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2997. {
  2998. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2999. {
  3000. tempIndex = ((gun_index==2) ? 1: 0);
  3001. }
  3002. else
  3003. {
  3004. tempIndex = gun_index;
  3005. }
  3006. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3007. {
  3008. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3009. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3010. {
  3011. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3012. {
  3013. reqSampleMeter[gun_index] = 1;
  3014. }
  3015. }
  3016. }// End for CHAdeMO
  3017. }
  3018. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3019. {
  3020. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3021. {
  3022. tempIndex = ((gun_index==2) ? 1: 0);
  3023. }
  3024. else
  3025. {
  3026. tempIndex = gun_index;
  3027. }
  3028. for (int index = 0; index < CCS_QUANTITY; index++)
  3029. {
  3030. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3031. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3032. {
  3033. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3034. {
  3035. reqSampleMeter[gun_index] = 1;
  3036. }
  3037. }
  3038. } // End for CCS
  3039. }
  3040. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3041. {
  3042. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3043. {
  3044. tempIndex = ((gun_index==2) ? 1: 0);
  3045. }
  3046. else
  3047. {
  3048. tempIndex = gun_index;
  3049. }
  3050. for (int index = 0; index < GB_QUANTITY; index++)
  3051. {
  3052. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3053. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3054. {
  3055. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3056. {
  3057. reqSampleMeter[gun_index] = 1;
  3058. }
  3059. }
  3060. }// End for GB
  3061. }
  3062. else if(gunType[gun_index] == GUN_TYPE_DO)
  3063. {
  3064. tempIndex = gun_index;
  3065. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3066. {
  3067. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3068. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3069. {
  3070. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3071. {
  3072. reqSampleMeter[gun_index] = 1;
  3073. }
  3074. }
  3075. }
  3076. }
  3077. else
  3078. {
  3079. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3080. {
  3081. tempIndex = 2;
  3082. }
  3083. else
  3084. {
  3085. tempIndex = gun_index;
  3086. }
  3087. for (int index = 0; index < AC_QUANTITY; index++)
  3088. {
  3089. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3090. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3091. {
  3092. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3093. {
  3094. reqSampleMeter[gun_index] = 1;
  3095. }
  3096. }
  3097. }//End for AC
  3098. }
  3099. if(reqSampleMeter[gun_index] == 1)
  3100. {
  3101. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3102. storeTempStopTransaction(gun_index);
  3103. }
  3104. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3105. }
  3106. //==============================================
  3107. // Check Connector reserved
  3108. //==============================================
  3109. //===============================
  3110. // Check if Reserve is expired
  3111. //===============================
  3112. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3113. {
  3114. double diff_t;
  3115. struct tm tp;
  3116. // current time
  3117. time_t t = time(NULL);
  3118. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3119. tp.tm_isdst = -1;
  3120. time_t utc = mktime(&tp);
  3121. diff_t = difftime(utc, t);
  3122. if(diff_t <= 0)
  3123. {
  3124. DEBUG_INFO("reserve expired.\n");
  3125. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3126. }
  3127. }//END OF Check if Reserve is expired
  3128. //==========================================
  3129. // csu trigger FirmwareStatusNotificationReq
  3130. //==========================================
  3131. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3132. {
  3133. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3134. }
  3135. //==========================================
  3136. // csu trigger DiagnosticsStatusNotificationReq
  3137. //==========================================
  3138. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3139. {
  3140. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3141. }
  3142. //==========================================
  3143. // csu trigger CancelReservationConf
  3144. //==========================================
  3145. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3146. {
  3147. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3148. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3149. }
  3150. //==========================================
  3151. // csu trigger ChangeAvailabilityConf
  3152. //==========================================
  3153. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3154. {
  3155. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3156. }
  3157. //==========================================
  3158. // csu trigger UnlockConnectorConf
  3159. //==========================================
  3160. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3161. {
  3162. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3163. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3164. }
  3165. //==========================================
  3166. // csu trigger ReserveNowConf
  3167. //==========================================
  3168. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3169. {
  3170. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3171. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3172. }
  3173. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3174. {
  3175. sendSignCertificateRequest();
  3176. }
  3177. }
  3178. }
  3179. //==========================================
  3180. // send request routine
  3181. //==========================================
  3182. int sendAuthorizeRequest(int gun_index)
  3183. {
  3184. mtrace();
  3185. int result = FAIL;
  3186. char message[100]={0};
  3187. char guid[37];
  3188. char tempdata[65]={0};
  3189. DEBUG_INFO("sendAuthorizeRequest...\n");
  3190. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3191. //Local Authorize
  3192. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3193. {
  3194. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3195. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3196. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3197. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3198. result = PASS;
  3199. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3200. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3201. authorizeRetryTimes = 0;
  3202. return result;
  3203. }
  3204. 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))||
  3205. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3206. {
  3207. // Query from cache
  3208. DEBUG_INFO("Authorize from cache.\n");
  3209. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3210. // Query from list
  3211. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3212. {
  3213. DEBUG_INFO("Authorize from list.\n");
  3214. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3215. }
  3216. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3217. {
  3218. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3219. {
  3220. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3221. }
  3222. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3223. {
  3224. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  3225. }
  3226. if(!GetOcppConnStatus())
  3227. {
  3228. DEBUG_INFO("off-line Local Authorization Fail.\n");
  3229. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3230. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3231. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3232. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3233. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3234. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3235. authorizeRetryTimes = 0;
  3236. return result;
  3237. }
  3238. }
  3239. else
  3240. {
  3241. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3242. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3243. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3244. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3245. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  3246. else
  3247. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3248. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  3249. result = PASS;
  3250. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3251. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3252. authorizeRetryTimes = 0;
  3253. return result;
  3254. }
  3255. }
  3256. //initialize struct Authorize
  3257. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  3258. //get data from shared memory
  3259. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3260. random_uuid(guid);
  3261. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  3262. LWS_Send(message);
  3263. sprintf(tempdata, "Authorize,%d", gun_index);
  3264. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3265. {
  3266. result = PASS;
  3267. DEBUG_INFO("Authorize mapItem pass\n");
  3268. }
  3269. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3270. return result;
  3271. }
  3272. int sendBootNotificationRequest(void)
  3273. {
  3274. mtrace();
  3275. int result = FAIL;
  3276. char message[500]={0}, payload[700]={0};
  3277. char guid[37]={0};
  3278. char tempdata[65]={0};
  3279. // Fill BootNotification fields
  3280. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  3281. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3282. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3283. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3284. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3285. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3286. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3287. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3288. ShmOCPP16Data->ChargeBoxId
  3289. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3290. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3291. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3292. ,ShmOCPP16Data->BootNotification.CpFwVersion
  3293. ,ShmOCPP16Data->BootNotification.CpIccid
  3294. ,ShmOCPP16Data->BootNotification.CpImsi);
  3295. random_uuid(guid);
  3296. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3297. LWS_Send(message);
  3298. sprintf(tempdata, "BootNotification,0");
  3299. 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*/)
  3300. {
  3301. result = PASS;
  3302. }
  3303. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3304. strcpy(queuedata,message);
  3305. return result;
  3306. }
  3307. int sendDataTransferRequest(int gun_index)
  3308. {
  3309. mtrace();
  3310. char message[1000]={0};
  3311. char guid[37]={0};
  3312. char tempdata[65]={0};
  3313. int result = FAIL;
  3314. random_uuid(guid);
  3315. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3316. MESSAGE_TYPE_CALL,
  3317. guid,
  3318. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  3319. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  3320. ShmOCPP16Data->DataTransfer[gun_index].Data);
  3321. LWS_Send(message);
  3322. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3323. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3324. {
  3325. result = PASS;
  3326. DEBUG_INFO("DataTransfer mapItem pass\n");
  3327. }
  3328. return result;
  3329. }
  3330. int sendDiagnosticsStatusNotificationRequest(char *status)
  3331. {
  3332. mtrace();
  3333. int result = FAIL;
  3334. char message[110]={0};
  3335. char guid[37]={0};
  3336. char tempdata[65]={0};
  3337. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3338. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3339. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3340. random_uuid(guid);
  3341. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3342. LWS_SendNow(message);
  3343. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3344. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3345. {
  3346. result = PASS;
  3347. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3348. }
  3349. //#ifdef SystemLogMessage
  3350. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3351. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3352. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3353. //#endif
  3354. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3355. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3356. //record status
  3357. if(strcmp(status,"Idle")==0)
  3358. {
  3359. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3360. }
  3361. else if(strcmp(status,"Uploaded")==0)
  3362. {
  3363. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3364. }
  3365. else if(strcmp(status,"UploadFailed")==0)
  3366. {
  3367. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3368. }
  3369. else if(strcmp(status,"Uploading")==0)
  3370. {
  3371. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3372. }
  3373. return result;
  3374. }
  3375. int sendFirmwareStatusNotificationRequest(char *status)
  3376. {
  3377. mtrace();
  3378. int result = FAIL;
  3379. char message[110]={0};
  3380. char guid[37]={0};
  3381. char tempdata[65]={0};
  3382. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3383. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3384. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3385. random_uuid(guid);
  3386. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3387. LWS_SendNow(message);
  3388. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3389. 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*/)
  3390. {
  3391. result = PASS;
  3392. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3393. }
  3394. //#ifdef SystemLogMessage
  3395. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3396. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3397. //#endif
  3398. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3399. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3400. //record status
  3401. if(strcmp(status,"Downloaded")==0)
  3402. {
  3403. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3404. }
  3405. else if(strcmp(status,"DownloadFailed")==0)
  3406. {
  3407. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3408. }
  3409. else if(strcmp(status,"Downloading")==0)
  3410. {
  3411. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3412. }
  3413. else if(strcmp(status,"Idle")==0)
  3414. {
  3415. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3416. }
  3417. else if(strcmp(status,"InstallationFailed")==0)
  3418. {
  3419. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3420. }
  3421. else if(strcmp(status,"Installing")==0)
  3422. {
  3423. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3424. }
  3425. else if(strcmp(status,"Installed")==0)
  3426. {
  3427. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3428. }
  3429. return result;
  3430. }
  3431. int sendHeartbeatRequest(int gun_index)
  3432. {
  3433. mtrace();
  3434. int result = FAIL;
  3435. char message[80]={0};
  3436. char guid[37]={0};
  3437. char tempdata[65]={0};
  3438. random_uuid(guid);
  3439. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3440. , MESSAGE_TYPE_CALL
  3441. , guid );
  3442. LWS_Send(message);
  3443. sprintf(tempdata, "Heartbeat,%d", 0);
  3444. 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*/)
  3445. {
  3446. result = PASS;
  3447. }
  3448. return result;
  3449. }
  3450. int sendStartTransactionRequest(int gun_index)
  3451. {
  3452. mtrace();
  3453. int result = FAIL;
  3454. char message[250]={0};
  3455. char guid[37]={0};
  3456. struct timeval tmnow;
  3457. struct tm *tm;
  3458. char buf[28];//, usec_buf[6];
  3459. char tempdata[65]={0};
  3460. int tempIndex = 0;
  3461. DEBUG_INFO("sendStartTransactionRequest...\n");
  3462. gettimeofday(&tmnow, NULL);
  3463. time_t t;
  3464. t = time(NULL);
  3465. /*UTC time and date*/
  3466. tm = gmtime(&t);
  3467. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3468. #if 0 // remove temporally
  3469. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3470. strcat(buf,".");
  3471. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3472. strcat(buf,usec_buf);
  3473. #endif
  3474. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3475. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  3476. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3477. // clear StartTransaction Response
  3478. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3479. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3480. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3481. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  3482. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3483. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3484. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3485. {
  3486. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3487. {
  3488. tempIndex = ((gun_index==2) ? 1: 0);
  3489. }
  3490. else
  3491. {
  3492. tempIndex = gun_index;
  3493. }
  3494. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3495. {
  3496. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3497. {
  3498. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3499. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3500. }
  3501. }
  3502. }
  3503. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3504. {
  3505. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3506. {
  3507. tempIndex = ((gun_index==2) ? 1: 0);
  3508. }
  3509. else
  3510. {
  3511. tempIndex = gun_index;
  3512. }
  3513. for (int index = 0; index < CCS_QUANTITY; index++)
  3514. {
  3515. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3516. {
  3517. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3518. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3519. }
  3520. }
  3521. }
  3522. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3523. {
  3524. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3525. {
  3526. tempIndex = ((gun_index==2) ? 1: 0);
  3527. }
  3528. else
  3529. {
  3530. tempIndex = gun_index;
  3531. }
  3532. for (int index = 0; index < GB_QUANTITY; index++)
  3533. {
  3534. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3535. {
  3536. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3537. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3538. }
  3539. }
  3540. }
  3541. else if(gunType[gun_index] == GUN_TYPE_DO)
  3542. {
  3543. tempIndex = gun_index;
  3544. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3545. {
  3546. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3547. {
  3548. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3549. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3550. }
  3551. }
  3552. }
  3553. else
  3554. {
  3555. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3556. {
  3557. tempIndex = 2;
  3558. }
  3559. else
  3560. {
  3561. tempIndex = gun_index;
  3562. }
  3563. for (int index = 0; index < AC_QUANTITY; index++)
  3564. {
  3565. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3566. {
  3567. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3568. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3569. }
  3570. }
  3571. }
  3572. random_uuid(guid);
  3573. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3574. {
  3575. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3576. , gun_index +1
  3577. , MESSAGE_TYPE_CALL
  3578. , guid
  3579. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3580. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3581. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3582. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3583. }
  3584. else
  3585. {
  3586. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3587. , gun_index +1
  3588. , MESSAGE_TYPE_CALL
  3589. , guid
  3590. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3591. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3592. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3593. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3594. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3595. }
  3596. #if 1
  3597. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3598. 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*/)
  3599. {
  3600. result = PASS;
  3601. }
  3602. #endif
  3603. strcpy(queuedata, message);
  3604. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3605. OCPP_insert_transaction_msg(YES, queuedata);
  3606. return result;
  3607. }
  3608. int sendStatusNotificationRequest(int gun_index)
  3609. {
  3610. mtrace();
  3611. int result = FAIL;
  3612. char message[600]={0};
  3613. char guid[37];
  3614. int currentStatus = 0;
  3615. struct timeval tmnow;
  3616. struct tm *tm;
  3617. char buf[28];//, usec_buf[6];
  3618. char tempdata[65]={0};
  3619. int tempIndex = 0;
  3620. uint8_t isStateChanged = TRUE;
  3621. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3622. gettimeofday(&tmnow, NULL);
  3623. time_t t;
  3624. t = time(NULL);
  3625. /*UTC time and date*/
  3626. tm = gmtime(&t);
  3627. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3628. #if 0 // remove temporally
  3629. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3630. strcat(buf,".");
  3631. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3632. strcat(buf,usec_buf);
  3633. #endif
  3634. printf("%s",buf);
  3635. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3636. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3637. // it's option
  3638. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3639. /*
  3640. enum _SYSTEM_STATUS
  3641. {
  3642. S_BOOTING = 0,
  3643. S_IDLE, = 1
  3644. S_AUTHORIZING, =2
  3645. S_REASSIGN_CHECK, =3
  3646. S_REASSIGN, =4
  3647. S_PRECHARGE, =5
  3648. S_PREPARING_FOR_EV, =6
  3649. S_PREPARING_FOR_EVSE, =7
  3650. S_CHARGING, =8
  3651. S_TERMINATING, =9
  3652. S_COMPLETE, =10
  3653. S_ALARM, =11
  3654. S_FAULT =12
  3655. }
  3656. */
  3657. //check Transaction active
  3658. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3659. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3660. {
  3661. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3662. {
  3663. tempIndex = ((gun_index==2) ? 1: 0);
  3664. }
  3665. else
  3666. {
  3667. tempIndex = gun_index;
  3668. }
  3669. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3670. {
  3671. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3672. {
  3673. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3674. {
  3675. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3676. {
  3677. currentStatus = Preparing; //OCPP Status: Preparing
  3678. }
  3679. else
  3680. {
  3681. currentStatus = Available; //OCPP Status: Available
  3682. }
  3683. }
  3684. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3685. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3686. ) //S_PRECHARGE
  3687. {
  3688. currentStatus = Preparing; //OCPP Status: Preparing
  3689. }
  3690. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3691. {
  3692. currentStatus = Charging; //OCPP Status: Charging
  3693. }
  3694. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3695. {
  3696. currentStatus = Finishing; //OCPP Status: Finishing
  3697. }
  3698. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3699. {
  3700. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3701. }
  3702. 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
  3703. {
  3704. currentStatus = Unavailable; //OCPP Status: Unavailable
  3705. }
  3706. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3707. {
  3708. currentStatus = Faulted; //OCPP Status: Faulted
  3709. }
  3710. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3711. {
  3712. currentStatus = Reserved; //OCPP Status: Reserved
  3713. }
  3714. } //end of the same index
  3715. }//end of for CHAdeMO_QUANTITY
  3716. }
  3717. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3718. {
  3719. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3720. {
  3721. tempIndex = ((gun_index==2) ? 1: 0);
  3722. }
  3723. else
  3724. {
  3725. tempIndex = gun_index;
  3726. }
  3727. for (int index = 0; index < CCS_QUANTITY; index++)
  3728. {
  3729. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3730. {
  3731. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3732. {
  3733. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3734. {
  3735. currentStatus = Preparing; //OCPP Status: Preparing
  3736. }
  3737. else
  3738. {
  3739. currentStatus = Available; //OCPP Status: Available
  3740. }
  3741. }
  3742. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3743. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3744. ) //S_PRECHARGE
  3745. {
  3746. currentStatus = Preparing; //OCPP Status: Preparing
  3747. }
  3748. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3749. {
  3750. currentStatus = Charging; //OCPP Status: Charging
  3751. }
  3752. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3753. {
  3754. currentStatus = Finishing; //OCPP Status: Finishing
  3755. }
  3756. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3757. {
  3758. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3759. }
  3760. 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
  3761. {
  3762. currentStatus = Unavailable; //OCPP Status : Unavailable
  3763. }
  3764. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3765. {
  3766. currentStatus = Faulted; //OCPP Status: Faulted
  3767. }
  3768. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3769. {
  3770. currentStatus = Reserved; //OCPP Status: Reserved
  3771. }
  3772. } //end of the same index
  3773. } // end of for CCS_QUANTITY
  3774. }
  3775. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3776. {
  3777. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3778. {
  3779. tempIndex = ((gun_index==2) ? 1: 0);
  3780. }
  3781. else
  3782. {
  3783. tempIndex = gun_index;
  3784. }
  3785. for (int index = 0; index < GB_QUANTITY; index++)
  3786. {
  3787. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3788. {
  3789. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3790. {
  3791. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3792. {
  3793. currentStatus = Preparing; //OCPP Status: Preparing
  3794. }
  3795. else
  3796. {
  3797. currentStatus = Available; //OCPP Status: Available
  3798. }
  3799. }
  3800. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3801. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3802. ) //S_PRECHARGE
  3803. {
  3804. currentStatus = Preparing; //OCPP Status: Preparing
  3805. }
  3806. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3807. {
  3808. currentStatus = Charging; //OCPP Status: Charging
  3809. }
  3810. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3811. {
  3812. currentStatus = Finishing; //OCPP Status: Finishing
  3813. }
  3814. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3815. {
  3816. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3817. }
  3818. 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
  3819. {
  3820. currentStatus = Unavailable; //OCPP Status: Unavailable
  3821. }
  3822. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3823. {
  3824. currentStatus = Faulted; //OCPP Status: Faulted
  3825. }
  3826. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3827. {
  3828. currentStatus = Reserved; //OCPP Status: Reserved
  3829. }
  3830. } //end of the same index
  3831. } // end of for GB_QUANTITY
  3832. }
  3833. else if(gunType[gun_index] == GUN_TYPE_DO)
  3834. {
  3835. tempIndex = gun_index;
  3836. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3837. {
  3838. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3839. {
  3840. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3841. {
  3842. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3843. {
  3844. currentStatus = Preparing; //OCPP Status: Preparing
  3845. }
  3846. else
  3847. {
  3848. currentStatus = Available; //OCPP Status: Available
  3849. }
  3850. }
  3851. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3852. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3853. ) //S_PRECHARGE
  3854. {
  3855. currentStatus = Preparing; //OCPP Status: Preparing
  3856. }
  3857. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3858. {
  3859. currentStatus = Charging; //OCPP Status: Charging
  3860. }
  3861. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3862. {
  3863. currentStatus = Finishing; //OCPP Status: Finishing
  3864. }
  3865. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3866. {
  3867. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3868. }
  3869. 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
  3870. {
  3871. currentStatus = Unavailable; //OCPP Status: Unavailable
  3872. }
  3873. 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
  3874. {
  3875. currentStatus = Faulted; //OCPP Status: Faulted
  3876. }
  3877. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3878. {
  3879. currentStatus = Reserved; //OCPP Status: Reserved
  3880. }
  3881. } //end of the same index
  3882. }
  3883. }
  3884. else
  3885. {
  3886. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3887. {
  3888. tempIndex = 2;
  3889. }
  3890. else
  3891. {
  3892. tempIndex = gun_index;
  3893. }
  3894. for (int index = 0; index < AC_QUANTITY; index++)
  3895. {
  3896. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3897. {
  3898. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3899. {
  3900. 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))
  3901. {
  3902. currentStatus = Preparing; //OCPP Status: Preparing
  3903. }
  3904. else
  3905. {
  3906. currentStatus = Available; //OCPP Status: Available
  3907. }
  3908. }
  3909. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3910. {
  3911. currentStatus = Preparing; //OCPP Status: Preparing
  3912. }
  3913. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3914. {
  3915. currentStatus = Charging; //OCPP Status: Charging
  3916. }
  3917. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3918. {
  3919. currentStatus = Finishing; //OCPP Status: Finishing
  3920. }
  3921. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3922. {
  3923. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  3924. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3925. else
  3926. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  3927. }
  3928. 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
  3929. {
  3930. currentStatus = Unavailable; //OCPP Status: Unavailable
  3931. }
  3932. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3933. {
  3934. currentStatus = Faulted; //OCPP Status: Faulted
  3935. }
  3936. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3937. {
  3938. currentStatus = Reserved; //OCPP Status: Reserved
  3939. }
  3940. }//end of the same index
  3941. }//end of for AC_QUANTITY
  3942. }
  3943. //it's option
  3944. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  3945. !ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq)
  3946. {
  3947. isStateChanged = FALSE;
  3948. }
  3949. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  3950. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3951. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3952. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3953. random_uuid(guid);
  3954. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3955. , MESSAGE_TYPE_CALL
  3956. , guid
  3957. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3958. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3959. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3960. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3961. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3962. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3963. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3964. if((server_sign == TRUE) && isStateChanged)
  3965. {
  3966. LWS_Send(message);
  3967. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3968. 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*/)
  3969. {
  3970. //DEBUG_ERROR("statusNotification mapitem pass");
  3971. result = PASS;
  3972. }
  3973. }
  3974. else
  3975. {
  3976. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  3977. result = PASS;
  3978. }
  3979. return result;
  3980. }
  3981. int sendStopTransactionRequest(int gun_index)
  3982. {
  3983. mtrace();
  3984. int result = FAIL;
  3985. //char message[1500]={0};
  3986. char guid[37]={0};
  3987. char tempdata[65]={0};
  3988. int tempIndex = 0;
  3989. char TempStopTransaction[256];
  3990. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3991. //int idx_sample=0;
  3992. DEBUG_INFO("sendStopTransactionRequest \n");
  3993. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3994. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3995. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3996. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3997. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3998. {
  3999. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4000. {
  4001. tempIndex = ((gun_index==2) ? 1: 0);
  4002. }
  4003. else
  4004. {
  4005. tempIndex = gun_index;
  4006. }
  4007. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4008. {
  4009. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4010. {
  4011. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4012. }
  4013. }// END OF CHAdeMO_QUANTITY
  4014. }
  4015. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4016. {
  4017. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4018. {
  4019. tempIndex = ((gun_index==2) ? 1: 0);
  4020. }
  4021. else
  4022. {
  4023. tempIndex = gun_index;
  4024. }
  4025. for (int index = 0; index < CCS_QUANTITY; index++)
  4026. {
  4027. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4028. {
  4029. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4030. }
  4031. }// END OF CCS_QUANTITY
  4032. }
  4033. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4034. {
  4035. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4036. {
  4037. tempIndex = ((gun_index==2) ? 1: 0);
  4038. }
  4039. else
  4040. {
  4041. tempIndex = gun_index;
  4042. }
  4043. for (int index = 0; index < GB_QUANTITY; index++)
  4044. {
  4045. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4046. {
  4047. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4048. }
  4049. }// END OF GB_QUANTITY
  4050. }
  4051. else if(gunType[gun_index] == GUN_TYPE_DO)
  4052. {
  4053. tempIndex = gun_index;
  4054. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4055. {
  4056. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4057. {
  4058. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4059. }
  4060. }// END OF GB_QUANTITY
  4061. }
  4062. else
  4063. {
  4064. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4065. {
  4066. tempIndex = 2;
  4067. }
  4068. else
  4069. {
  4070. tempIndex = gun_index;
  4071. }
  4072. for (int index = 0; index < AC_QUANTITY; index++)
  4073. {
  4074. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4075. {
  4076. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4077. }
  4078. }// END OF AC_QUANTITY
  4079. }
  4080. //====================================== Stop Transaction Time =====================================================
  4081. struct timeval tmnow;
  4082. struct tm *tm;
  4083. char buf[28];//, usec_buf[6];
  4084. gettimeofday(&tmnow, NULL);
  4085. time_t t;
  4086. t = time(NULL);
  4087. /*UTC time and date*/
  4088. tm = gmtime(&t);
  4089. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4090. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  4091. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4092. random_uuid(guid);
  4093. /***********************************transactionData******************************************************/
  4094. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4095. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4096. //=================================
  4097. // Transaction_Begin
  4098. //=================================
  4099. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4100. {
  4101. //============================================ Energy.Active.Import.Interval ================================
  4102. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4104. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4105. 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*/]);
  4106. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4107. 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))
  4108. {
  4109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4110. }
  4111. else
  4112. {
  4113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4114. }
  4115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4116. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4117. }
  4118. //=================================
  4119. // Transaction_End
  4120. //=================================
  4121. // ================================= Current.Import L1 ===============================================
  4122. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4123. {
  4124. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4125. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4126. {
  4127. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4128. {
  4129. tempIndex = ((gun_index==2) ? 1: 0);
  4130. }
  4131. else
  4132. {
  4133. tempIndex = gun_index;
  4134. }
  4135. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4136. {
  4137. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4138. {
  4139. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4140. }
  4141. }// End of for CHAdeMO_QUANTITY
  4142. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4143. }
  4144. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4145. {
  4146. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4147. {
  4148. tempIndex = ((gun_index==2) ? 1: 0);
  4149. }
  4150. else
  4151. {
  4152. tempIndex = gun_index;
  4153. }
  4154. for (int index = 0; index < CCS_QUANTITY; index++)
  4155. {
  4156. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4157. {
  4158. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4159. }
  4160. }// End of for CCS_QUANTITY
  4161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4162. }
  4163. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4164. {
  4165. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4166. {
  4167. tempIndex = ((gun_index==2) ? 1: 0);
  4168. }
  4169. else
  4170. {
  4171. tempIndex = gun_index;
  4172. }
  4173. for (int index = 0; index < GB_QUANTITY; index++)
  4174. {
  4175. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4176. {
  4177. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4178. }
  4179. }// End of for GB_QUANTITY
  4180. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4181. }
  4182. else if(gunType[gun_index] == GUN_TYPE_DO)
  4183. {
  4184. tempIndex = gun_index;
  4185. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4186. {
  4187. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4188. {
  4189. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4190. }
  4191. }
  4192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4193. }
  4194. else
  4195. {
  4196. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4197. {
  4198. tempIndex = 2;
  4199. }
  4200. else
  4201. {
  4202. tempIndex = gun_index;
  4203. }
  4204. for (int index = 0; index < AC_QUANTITY; index++)
  4205. {
  4206. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4207. {
  4208. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4209. }
  4210. }// End of for AC_QUANTITY
  4211. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4212. }
  4213. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4214. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4215. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4216. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4217. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4218. }
  4219. // ================================= Energy.Active.Import.Interval ==============================================
  4220. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4221. {
  4222. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4223. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4224. {
  4225. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4226. {
  4227. tempIndex = ((gun_index==2) ? 1: 0);
  4228. }
  4229. else
  4230. {
  4231. tempIndex = gun_index;
  4232. }
  4233. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4234. {
  4235. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4236. {
  4237. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4238. }
  4239. }// END OF CHAdeMO_QUANTITY
  4240. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4241. }
  4242. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4243. {
  4244. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4245. {
  4246. tempIndex = ((gun_index==2) ? 1: 0);
  4247. }
  4248. else
  4249. {
  4250. tempIndex = gun_index;
  4251. }
  4252. for (int index = 0; index < CCS_QUANTITY; index++)
  4253. {
  4254. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4255. {
  4256. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4257. }
  4258. }// END OF CCS_QUANTITY
  4259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4260. }
  4261. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4262. {
  4263. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4264. {
  4265. tempIndex = ((gun_index==2) ? 1: 0);
  4266. }
  4267. else
  4268. {
  4269. tempIndex = gun_index;
  4270. }
  4271. for (int index = 0; index < GB_QUANTITY; index++)
  4272. {
  4273. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4274. {
  4275. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4276. }
  4277. }// END OF GB_QUANTITY
  4278. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4279. }
  4280. else if(gunType[gun_index] == GUN_TYPE_DO)
  4281. {
  4282. tempIndex = gun_index;
  4283. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4284. {
  4285. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4286. {
  4287. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4288. }
  4289. }
  4290. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4291. }
  4292. else
  4293. {
  4294. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4295. {
  4296. tempIndex = 2;
  4297. }
  4298. else
  4299. {
  4300. tempIndex = gun_index;
  4301. }
  4302. for (int index = 0; index < AC_QUANTITY; index++)
  4303. {
  4304. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4305. {
  4306. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4307. }
  4308. }// END OF AC_QUANTITY
  4309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4310. }
  4311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4313. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4315. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4316. }
  4317. //=================================== Power.Active.Import ==================================================
  4318. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4319. {
  4320. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4321. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4322. {
  4323. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4324. {
  4325. tempIndex = ((gun_index==2) ? 1: 0);
  4326. }
  4327. else
  4328. {
  4329. tempIndex = gun_index;
  4330. }
  4331. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4332. {
  4333. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4334. {
  4335. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4336. }
  4337. } // End for CHAdeMO_QUANTITY
  4338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4339. }
  4340. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4341. {
  4342. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4343. {
  4344. tempIndex = ((gun_index==2) ? 1: 0);
  4345. }
  4346. else
  4347. {
  4348. tempIndex = gun_index;
  4349. }
  4350. for (int index = 0; index < CCS_QUANTITY; index++)
  4351. {
  4352. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4353. {
  4354. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4355. }
  4356. } // END for CCS_QUANTITY
  4357. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4358. }
  4359. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4360. {
  4361. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4362. {
  4363. tempIndex = ((gun_index==2) ? 1: 0);
  4364. }
  4365. else
  4366. {
  4367. tempIndex = gun_index;
  4368. }
  4369. for (int index = 0; index < GB_QUANTITY; index++)
  4370. {
  4371. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4372. {
  4373. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4374. }
  4375. }// END for GB_QUANTITY
  4376. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4377. }
  4378. else if(gunType[gun_index] == GUN_TYPE_DO)
  4379. {
  4380. tempIndex = gun_index;
  4381. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4382. {
  4383. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4384. {
  4385. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4386. }
  4387. }
  4388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4389. }
  4390. else
  4391. {
  4392. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4393. {
  4394. tempIndex = 2;
  4395. }
  4396. else
  4397. {
  4398. tempIndex = gun_index;
  4399. }
  4400. for (int index = 0; index < AC_QUANTITY; index++)
  4401. {
  4402. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4403. {
  4404. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4405. }
  4406. } // END for AC_QUANTITY
  4407. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4408. }
  4409. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4410. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4411. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4413. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4414. }
  4415. //============================ Voltage L1 ====================================
  4416. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4417. {
  4418. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4419. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4420. {
  4421. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4422. {
  4423. tempIndex = ((gun_index==2) ? 1: 0);
  4424. }
  4425. else
  4426. {
  4427. tempIndex = gun_index;
  4428. }
  4429. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4430. {
  4431. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4432. {
  4433. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4434. }
  4435. } // END OF FOR CHAdeMO_QUANTITY
  4436. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4437. }
  4438. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4439. {
  4440. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4441. {
  4442. tempIndex = ((gun_index==2) ? 1: 0);
  4443. }
  4444. else
  4445. {
  4446. tempIndex = gun_index;
  4447. }
  4448. for (int index = 0; index < CCS_QUANTITY; index++)
  4449. {
  4450. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4451. {
  4452. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4453. }
  4454. } // END OF FOR CCS_QUANTITY
  4455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4456. }
  4457. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4458. {
  4459. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4460. {
  4461. tempIndex = ((gun_index==2) ? 1: 0);
  4462. }
  4463. else
  4464. {
  4465. tempIndex = gun_index;
  4466. }
  4467. for (int index = 0; index < GB_QUANTITY; index++)
  4468. {
  4469. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4470. {
  4471. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4472. }
  4473. } // END OF FOR GB_QUANTITY
  4474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4475. }
  4476. else if(gunType[gun_index] == GUN_TYPE_DO)
  4477. {
  4478. tempIndex = gun_index;
  4479. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4480. {
  4481. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4482. {
  4483. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4484. }
  4485. }
  4486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4487. }
  4488. else
  4489. {
  4490. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4491. {
  4492. tempIndex = 2;
  4493. }
  4494. else
  4495. {
  4496. tempIndex = gun_index;
  4497. }
  4498. for (int index = 0; index < AC_QUANTITY; index++)
  4499. {
  4500. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4501. {
  4502. 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
  4503. }
  4504. } // END OF FOR AC_QUANTITY
  4505. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4506. }
  4507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4512. }
  4513. //====================== End SoC ================================
  4514. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4515. {
  4516. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4517. 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))
  4518. {
  4519. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4520. {
  4521. tempIndex = ((gun_index==2) ? 1: 0);
  4522. }
  4523. else
  4524. {
  4525. tempIndex = gun_index;
  4526. }
  4527. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4528. {
  4529. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4530. {
  4531. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4532. {
  4533. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4534. }
  4535. }
  4536. }
  4537. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4538. {
  4539. for (int index = 0; index < CCS_QUANTITY; index++)
  4540. {
  4541. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4542. {
  4543. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4544. }
  4545. }
  4546. }
  4547. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4548. {
  4549. for (int index = 0; index < GB_QUANTITY; index++)
  4550. {
  4551. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4552. {
  4553. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4554. }
  4555. }
  4556. }
  4557. else if(gunType[gun_index] == GUN_TYPE_DO)
  4558. {
  4559. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4560. {
  4561. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4562. {
  4563. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4564. }
  4565. }
  4566. }
  4567. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4568. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4571. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4573. } // END FOR DC CASE
  4574. }
  4575. // ================================= Current.Import L2 ===============================================
  4576. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4577. {
  4578. // AC 3 phse L2 current
  4579. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4580. {
  4581. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4582. {
  4583. tempIndex = 2;
  4584. }
  4585. else
  4586. {
  4587. tempIndex = gun_index;
  4588. }
  4589. for (int index = 0; index < AC_QUANTITY; index++)
  4590. {
  4591. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4592. {
  4593. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4594. }
  4595. }// End of for AC_QUANTITY
  4596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4597. }
  4598. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4599. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4600. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4601. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4602. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4603. }
  4604. // ================================= Current.Import L3 ===============================================
  4605. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4606. {
  4607. // AC 3 phse L3 current
  4608. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4609. {
  4610. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4611. {
  4612. tempIndex = 2;
  4613. }
  4614. else
  4615. {
  4616. tempIndex = gun_index;
  4617. }
  4618. for (int index = 0; index < AC_QUANTITY; index++)
  4619. {
  4620. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4621. {
  4622. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4623. }
  4624. }// End of for AC_QUANTITY
  4625. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4626. }
  4627. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4628. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4629. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4630. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4632. }
  4633. //============================ Voltage L2 ====================================
  4634. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4635. {
  4636. // AC 3 phse L2 voltage
  4637. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4638. {
  4639. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4640. {
  4641. tempIndex = 2;
  4642. }
  4643. else
  4644. {
  4645. tempIndex = gun_index;
  4646. }
  4647. for (int index = 0; index < AC_QUANTITY; index++)
  4648. {
  4649. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4650. {
  4651. 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
  4652. }
  4653. } // END OF FOR AC_QUANTITY
  4654. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4655. }
  4656. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4658. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4659. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4660. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4661. }
  4662. //============================ Voltage L3 ====================================
  4663. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4664. {
  4665. // AC 3 phse L3 voltage
  4666. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4667. {
  4668. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4669. {
  4670. tempIndex = 2;
  4671. }
  4672. else
  4673. {
  4674. tempIndex = gun_index;
  4675. }
  4676. for (int index = 0; index < AC_QUANTITY; index++)
  4677. {
  4678. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4679. {
  4680. 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
  4681. }
  4682. } // END OF FOR AC_QUANTITY
  4683. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4684. }
  4685. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4686. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4687. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4688. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4689. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4690. }
  4691. //====================== Start SoC ================================
  4692. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4693. {
  4694. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4695. 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))
  4696. {
  4697. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4698. {
  4699. tempIndex = ((gun_index==2) ? 1: 0);
  4700. }
  4701. else
  4702. {
  4703. tempIndex = gun_index;
  4704. }
  4705. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4706. {
  4707. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4708. {
  4709. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4710. {
  4711. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4712. }
  4713. }
  4714. }
  4715. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4716. {
  4717. for (int index = 0; index < CCS_QUANTITY; index++)
  4718. {
  4719. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4720. {
  4721. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4722. }
  4723. }
  4724. }
  4725. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4726. {
  4727. for (int index = 0; index < GB_QUANTITY; index++)
  4728. {
  4729. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4730. {
  4731. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4732. }
  4733. }
  4734. }
  4735. else if(gunType[gun_index] == GUN_TYPE_DO)
  4736. {
  4737. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4738. {
  4739. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4740. {
  4741. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4742. }
  4743. }
  4744. }
  4745. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4746. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4747. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4748. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4749. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4750. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4751. } // END FOR DC CASE
  4752. }
  4753. //================================================ Message create ====================================================
  4754. json_object *StopTransaction = json_object_new_object();
  4755. json_object *transactionDatas = json_object_new_array();
  4756. json_object *sampledValues = json_object_new_array();
  4757. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4758. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4759. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4760. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4761. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4762. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4763. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4764. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4765. {
  4766. json_object *transactionData = json_object_new_object();
  4767. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4768. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4769. {
  4770. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4771. {
  4772. json_object *sampledValue = json_object_new_object();
  4773. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4774. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4775. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4776. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4777. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4778. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4779. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4780. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4781. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4782. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4783. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4784. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4785. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4786. json_object_array_add(sampledValues, sampledValue);
  4787. }
  4788. }
  4789. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4790. json_object_array_add(transactionDatas, transactionData);
  4791. }
  4792. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4793. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4794. ,MESSAGE_TYPE_CALL
  4795. ,guid
  4796. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4797. json_object_put(StopTransaction);
  4798. #if 1 // for TempStopTransaction
  4799. //Delete TempStopTransaction
  4800. if((access(TempStopTransaction,F_OK))!=-1)
  4801. {
  4802. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4803. }
  4804. #endif
  4805. #if 1
  4806. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4807. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4808. {
  4809. result = PASS;
  4810. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4811. }
  4812. #endif
  4813. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4814. OCPP_insert_transaction_msg(NO, queuedata);
  4815. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4816. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4817. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4818. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4819. {
  4820. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4821. }
  4822. //for test
  4823. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4824. return result;
  4825. }
  4826. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4827. {
  4828. mtrace();
  4829. int result = FAIL;
  4830. char guid[37]={0};
  4831. char tempdata[65]={0};
  4832. int tempIndex = 0;
  4833. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4834. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4835. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4836. //set value
  4837. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4838. 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) )?
  4839. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  4840. -1);
  4841. random_uuid(guid);
  4842. //UTC Date time
  4843. struct timeval tmnow;
  4844. struct tm *tm;
  4845. char buf[28];//, usec_buf[6];
  4846. gettimeofday(&tmnow, NULL);
  4847. time_t t;
  4848. t = time(NULL);
  4849. /*UTC time and date*/
  4850. tm = gmtime(&t);
  4851. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4852. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4853. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4854. //********************************(1)Current.Import L1************************************************/
  4855. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4856. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4857. (dataType == ReadingContext_Trigger))
  4858. {
  4859. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4860. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4861. {
  4862. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4863. {
  4864. tempIndex = ((gun_index==2) ? 1: 0);
  4865. }
  4866. else
  4867. {
  4868. tempIndex = gun_index;
  4869. }
  4870. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4871. {
  4872. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4873. {
  4874. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4875. }
  4876. }
  4877. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4878. }
  4879. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4880. {
  4881. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4882. {
  4883. tempIndex = ((gun_index==2) ? 1: 0);
  4884. }
  4885. else
  4886. {
  4887. tempIndex = gun_index;
  4888. }
  4889. for (int index = 0; index < CCS_QUANTITY; index++)
  4890. {
  4891. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4892. {
  4893. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4894. }
  4895. }
  4896. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4897. }
  4898. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4899. {
  4900. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4901. {
  4902. tempIndex = ((gun_index==2) ? 1: 0);
  4903. }
  4904. else
  4905. {
  4906. tempIndex = gun_index;
  4907. }
  4908. for (int index = 0; index < GB_QUANTITY; index++)
  4909. {
  4910. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4911. {
  4912. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4913. }
  4914. }
  4915. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4916. }
  4917. else if(gunType[gun_index] == GUN_TYPE_DO)
  4918. {
  4919. tempIndex = gun_index;
  4920. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4921. {
  4922. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4923. {
  4924. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4925. }
  4926. }
  4927. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4928. }
  4929. else
  4930. {
  4931. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4932. {
  4933. tempIndex = 2;
  4934. }
  4935. else
  4936. {
  4937. tempIndex = gun_index;
  4938. }
  4939. for (int index = 0; index < AC_QUANTITY; index++)
  4940. {
  4941. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4942. {
  4943. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4944. }
  4945. }
  4946. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4947. }
  4948. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4949. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4950. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4951. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4952. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4953. }
  4954. //********************************(2)Energy.Active.Import.Register ************************************************/
  4955. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4956. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4957. (dataType == ReadingContext_Trigger))
  4958. {
  4959. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4960. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4961. {
  4962. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4963. {
  4964. tempIndex = ((gun_index==2) ? 1: 0);
  4965. }
  4966. else
  4967. {
  4968. tempIndex = gun_index;
  4969. }
  4970. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4971. {
  4972. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4973. {
  4974. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4975. }
  4976. }
  4977. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4978. }
  4979. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4980. {
  4981. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4982. {
  4983. tempIndex = ((gun_index==2) ? 1: 0);
  4984. }
  4985. else
  4986. {
  4987. tempIndex = gun_index;
  4988. }
  4989. for (int index = 0; index < CCS_QUANTITY; index++)
  4990. {
  4991. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4992. {
  4993. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4994. }
  4995. }
  4996. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4997. }
  4998. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4999. {
  5000. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5001. {
  5002. tempIndex = ((gun_index==2) ? 1: 0);
  5003. }
  5004. else
  5005. {
  5006. tempIndex = gun_index;
  5007. }
  5008. for (int index = 0; index < GB_QUANTITY; index++)
  5009. {
  5010. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5011. {
  5012. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5013. }
  5014. }
  5015. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5016. }
  5017. else if(gunType[gun_index] == GUN_TYPE_DO)
  5018. {
  5019. tempIndex = gun_index;
  5020. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5021. {
  5022. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5023. {
  5024. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5025. }
  5026. }
  5027. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5028. }
  5029. else
  5030. {
  5031. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5032. {
  5033. tempIndex = 2;
  5034. }
  5035. else
  5036. {
  5037. tempIndex = gun_index;
  5038. }
  5039. for (int index = 0; index < AC_QUANTITY; index++)
  5040. {
  5041. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5042. {
  5043. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5044. }
  5045. }
  5046. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5047. }
  5048. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5049. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5050. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5051. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5052. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5053. }
  5054. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5055. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5056. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5057. (dataType == ReadingContext_Trigger))
  5058. {
  5059. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5060. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5061. {
  5062. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5063. {
  5064. tempIndex = ((gun_index==2) ? 1: 0);
  5065. }
  5066. else
  5067. {
  5068. tempIndex = gun_index;
  5069. }
  5070. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5071. {
  5072. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5073. {
  5074. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5075. }
  5076. } // END OF FOR CHAdeMO_QUANTITY
  5077. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5078. }
  5079. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5080. {
  5081. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5082. {
  5083. tempIndex = ((gun_index==2) ? 1: 0);
  5084. }
  5085. else
  5086. {
  5087. tempIndex = gun_index;
  5088. }
  5089. for (int index = 0; index < CCS_QUANTITY; index++)
  5090. {
  5091. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5092. {
  5093. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5094. }
  5095. } // END OF CCS_QUANTITY
  5096. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5097. }
  5098. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5099. {
  5100. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5101. {
  5102. tempIndex = ((gun_index==2) ? 1: 0);
  5103. }
  5104. else
  5105. {
  5106. tempIndex = gun_index;
  5107. }
  5108. for (int index = 0; index < GB_QUANTITY; index++)
  5109. {
  5110. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5111. {
  5112. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5113. }
  5114. } // END OF GB_QUANTITY
  5115. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5116. }
  5117. else if(gunType[gun_index] == GUN_TYPE_DO)
  5118. {
  5119. tempIndex = gun_index;
  5120. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5121. {
  5122. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5123. {
  5124. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5125. }
  5126. }
  5127. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5128. }
  5129. else
  5130. {
  5131. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5132. {
  5133. tempIndex = 2;
  5134. }
  5135. else
  5136. {
  5137. tempIndex = gun_index;
  5138. }
  5139. for (int index = 0; index < AC_QUANTITY; index++)
  5140. {
  5141. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5142. {
  5143. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5144. }
  5145. }
  5146. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5147. }
  5148. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5149. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5150. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5151. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5152. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5153. }
  5154. //********************************(4)Power.Active.Import************************************************/
  5155. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5156. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5157. (dataType == ReadingContext_Trigger))
  5158. {
  5159. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5160. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5161. {
  5162. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5163. {
  5164. tempIndex = ((gun_index==2) ? 1: 0);
  5165. }
  5166. else
  5167. {
  5168. tempIndex = gun_index;
  5169. }
  5170. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5171. {
  5172. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5173. {
  5174. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5175. }
  5176. } // END OF FOR
  5177. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5178. }
  5179. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5180. {
  5181. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5182. {
  5183. tempIndex = ((gun_index==2) ? 1: 0);
  5184. }
  5185. else
  5186. {
  5187. tempIndex = gun_index;
  5188. }
  5189. for (int index = 0; index < CCS_QUANTITY; index++)
  5190. {
  5191. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5192. {
  5193. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5194. }
  5195. }
  5196. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5197. }
  5198. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5199. {
  5200. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5201. {
  5202. tempIndex = ((gun_index==2) ? 1: 0);
  5203. }
  5204. else
  5205. {
  5206. tempIndex = gun_index;
  5207. }
  5208. for (int index = 0; index < GB_QUANTITY; index++)
  5209. {
  5210. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5211. {
  5212. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5213. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5214. }
  5215. }
  5216. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5217. }
  5218. else if(gunType[gun_index] == GUN_TYPE_DO)
  5219. {
  5220. tempIndex = gun_index;
  5221. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5222. {
  5223. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5224. {
  5225. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5226. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5227. }
  5228. }
  5229. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5230. }
  5231. else
  5232. {
  5233. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5234. {
  5235. tempIndex = 2;
  5236. }
  5237. else
  5238. {
  5239. tempIndex = gun_index;
  5240. }
  5241. for (int index = 0; index < AC_QUANTITY; index++)
  5242. {
  5243. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5244. {
  5245. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5246. }
  5247. }
  5248. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5249. }
  5250. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5251. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5252. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5253. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5254. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5255. }
  5256. //***********************************************(5)VOLTAGE L1******************************************************/
  5257. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5258. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5259. (dataType == ReadingContext_Trigger))
  5260. {
  5261. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5262. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5263. {
  5264. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5265. {
  5266. tempIndex = ((gun_index==2) ? 1: 0);
  5267. }
  5268. else
  5269. {
  5270. tempIndex = gun_index;
  5271. }
  5272. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5273. {
  5274. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5275. {
  5276. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5277. }
  5278. }
  5279. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5280. }
  5281. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5282. {
  5283. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5284. {
  5285. tempIndex = ((gun_index==2) ? 1: 0);
  5286. }
  5287. else
  5288. {
  5289. tempIndex = gun_index;
  5290. }
  5291. for (int index = 0; index < CCS_QUANTITY; index++)
  5292. {
  5293. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5294. {
  5295. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5296. }
  5297. }
  5298. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5299. }
  5300. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5301. {
  5302. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5303. {
  5304. tempIndex = ((gun_index==2) ? 1: 0);
  5305. }
  5306. else
  5307. {
  5308. tempIndex = gun_index;
  5309. }
  5310. for (int index = 0; index < GB_QUANTITY; index++)
  5311. {
  5312. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5313. {
  5314. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5315. }
  5316. }
  5317. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5318. }
  5319. else if(gunType[gun_index] == GUN_TYPE_DO)
  5320. {
  5321. tempIndex = gun_index;
  5322. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5323. {
  5324. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5325. {
  5326. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5327. }
  5328. }
  5329. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5330. }
  5331. else
  5332. {
  5333. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5334. {
  5335. tempIndex = 2;
  5336. }
  5337. else
  5338. {
  5339. tempIndex = gun_index;
  5340. }
  5341. for (int index = 0; index < AC_QUANTITY; index++)
  5342. {
  5343. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5344. {
  5345. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5346. }
  5347. }
  5348. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5349. }
  5350. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5351. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5352. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5353. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5354. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5355. }
  5356. //***********************************************(6)SOC******************************************************/
  5357. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5358. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5359. (dataType == ReadingContext_Trigger))
  5360. {
  5361. 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))
  5362. {
  5363. //idx_sample=5;
  5364. //sampledValue = NULL;
  5365. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5366. {
  5367. tempIndex = ((gun_index==2) ? 1: 0);
  5368. }
  5369. else
  5370. {
  5371. tempIndex = gun_index;
  5372. }
  5373. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5374. {
  5375. //tempIndex = ((gun_index==2) ? 1: 0);
  5376. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5377. {
  5378. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5379. {
  5380. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5381. }
  5382. }
  5383. }
  5384. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5385. {
  5386. //tempIndex = ((gun_index==2) ? 1: 0);
  5387. for (int index = 0; index < CCS_QUANTITY; index++)
  5388. {
  5389. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5390. {
  5391. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5392. }
  5393. }
  5394. }
  5395. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5396. {
  5397. //tempIndex = ((gun_index==2) ? 1: 0);
  5398. for (int index = 0; index < GB_QUANTITY; index++)
  5399. {
  5400. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5401. {
  5402. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5403. }
  5404. }
  5405. }
  5406. else if(gunType[gun_index] == GUN_TYPE_DO)
  5407. {
  5408. //tempIndex = ((gun_index==2) ? 1: 0);
  5409. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5410. {
  5411. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5412. {
  5413. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5414. }
  5415. }
  5416. }
  5417. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5418. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5419. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5420. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5421. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5422. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5423. }
  5424. }
  5425. //********************************(7)Current.Import L2************************************************/
  5426. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5427. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5428. (dataType == ReadingContext_Trigger))
  5429. {
  5430. // Only for AC 3 phase
  5431. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5432. {
  5433. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5434. {
  5435. tempIndex = 2;
  5436. }
  5437. else
  5438. {
  5439. tempIndex = gun_index;
  5440. }
  5441. for (int index = 0; index < AC_QUANTITY; index++)
  5442. {
  5443. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5444. {
  5445. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5446. }
  5447. }
  5448. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5449. }
  5450. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5451. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5452. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5453. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5454. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5455. }
  5456. //********************************(8)Current.Import L3************************************************/
  5457. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5458. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5459. (dataType == ReadingContext_Trigger))
  5460. {
  5461. // Only for AC 3 phase
  5462. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5463. {
  5464. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5465. {
  5466. tempIndex = 2;
  5467. }
  5468. else
  5469. {
  5470. tempIndex = gun_index;
  5471. }
  5472. for (int index = 0; index < AC_QUANTITY; index++)
  5473. {
  5474. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5475. {
  5476. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5477. }
  5478. }
  5479. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5480. }
  5481. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5482. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5483. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5484. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5485. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5486. }
  5487. //***********************************************(9)VOLTAGE L2******************************************************/
  5488. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5489. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5490. (dataType == ReadingContext_Trigger))
  5491. {
  5492. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5493. {
  5494. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5495. {
  5496. tempIndex = 2;
  5497. }
  5498. else
  5499. {
  5500. tempIndex = gun_index;
  5501. }
  5502. for (int index = 0; index < AC_QUANTITY; index++)
  5503. {
  5504. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5505. {
  5506. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5507. }
  5508. }
  5509. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5510. }
  5511. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5512. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5513. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5514. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5515. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5516. }
  5517. //***********************************************(10)VOLTAGE L3******************************************************/
  5518. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5519. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5520. (dataType == ReadingContext_Trigger))
  5521. {
  5522. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5523. {
  5524. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5525. {
  5526. tempIndex = 2;
  5527. }
  5528. else
  5529. {
  5530. tempIndex = gun_index;
  5531. }
  5532. for (int index = 0; index < AC_QUANTITY; index++)
  5533. {
  5534. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5535. {
  5536. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5537. }
  5538. }
  5539. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5540. }
  5541. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5542. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5543. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5544. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5545. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5546. }
  5547. // Message create ====================================================================================================
  5548. if(TRUE)
  5549. {
  5550. json_object *MeterValueReq = json_object_new_object();
  5551. json_object *MeterValues = json_object_new_array();
  5552. json_object *sampledValues = json_object_new_array();
  5553. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  5554. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  5555. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  5556. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  5557. {
  5558. json_object *MeterValue = json_object_new_object();
  5559. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5560. {
  5561. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5562. {
  5563. json_object *sampledValue = json_object_new_object();
  5564. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5565. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5566. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5567. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5568. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5569. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5570. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5571. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5572. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5573. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5574. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5575. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5576. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5577. json_object_array_add(sampledValues, sampledValue);
  5578. }
  5579. }
  5580. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5581. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5582. json_object_array_add(MeterValues, MeterValue);
  5583. }
  5584. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5585. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5586. ,gun_index + 1
  5587. ,MESSAGE_TYPE_CALL
  5588. ,guid
  5589. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5590. json_object_put(MeterValueReq);
  5591. }
  5592. // Put request guid to hash map
  5593. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5594. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  5595. {
  5596. result = PASS;
  5597. //DEBUG_INFO("MeterValues mapitem pass\n");
  5598. }
  5599. if((dataType != ReadingContext_Trigger) &&
  5600. (dataType != ReadingContext_Sample_Clock) &&
  5601. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  5602. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5603. else
  5604. {
  5605. if(FirstHeartBeat)
  5606. LWS_Send(queuedata +2);
  5607. }
  5608. return result;
  5609. }
  5610. int sendLogStatusNotificationRequest(char *status)
  5611. {
  5612. mtrace();
  5613. int result = PASS;
  5614. char message[4096]={0};
  5615. char guid[37]={0};
  5616. char tempdata[128]={0};
  5617. json_object *LogStatusNotification = json_object_new_object();
  5618. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  5619. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  5620. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  5621. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  5622. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  5623. random_uuid(guid);
  5624. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  5625. json_object_put(LogStatusNotification);
  5626. LWS_Send(message);
  5627. sprintf(tempdata, "LogStatusNotification,%d", 0);
  5628. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5629. {
  5630. result = PASS;
  5631. }
  5632. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  5633. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  5634. return result;
  5635. }
  5636. int sendSecurityEventNotificationRequest()
  5637. {
  5638. mtrace();
  5639. int result = PASS;
  5640. char message[4096]={0};
  5641. char guid[37]={0};
  5642. char tempdata[128]={0};
  5643. json_object *SecurityEventNotification = json_object_new_object();
  5644. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  5645. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  5646. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  5647. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  5648. random_uuid(guid);
  5649. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  5650. json_object_put(SecurityEventNotification);
  5651. LWS_Send(message);
  5652. sprintf(tempdata, "SecurityEventNotification,0");
  5653. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5654. {
  5655. result = PASS;
  5656. }
  5657. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5658. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  5659. return result;
  5660. }
  5661. int sendSignCertificateRequest()
  5662. {
  5663. mtrace();
  5664. int result = PASS;
  5665. char message[4096]={0};
  5666. char guid[37]={0};
  5667. char tempdata[128]={0};
  5668. json_object *SignCertificate = json_object_new_object();
  5669. DEBUG_INFO("sendSignCertificateRequest...\n");
  5670. // Read csr file content
  5671. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  5672. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  5673. char *line = NULL;
  5674. size_t len = 0;
  5675. while(getline(&line, &len, fp) != -1)
  5676. {
  5677. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5678. {
  5679. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  5680. }
  5681. }
  5682. fclose(fp);
  5683. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  5684. random_uuid(guid);
  5685. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  5686. json_object_put(SignCertificate);
  5687. LWS_Send(message);
  5688. sprintf(tempdata, "SignCertificate,0");
  5689. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5690. {
  5691. result = PASS;
  5692. }
  5693. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  5694. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  5695. return result;
  5696. }
  5697. int sendSignedFirmwareStatusNotificationRequest(char *status)
  5698. {
  5699. mtrace();
  5700. int result = PASS;
  5701. char message[110]={0};
  5702. char guid[37]={0};
  5703. char tempdata[65]={0};
  5704. json_object *FirmwareStatusNotification = json_object_new_object();
  5705. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  5706. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  5707. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  5708. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  5709. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  5710. random_uuid(guid);
  5711. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  5712. json_object_put(FirmwareStatusNotification);
  5713. LWS_Send(message);
  5714. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5715. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5716. {
  5717. result = PASS;
  5718. }
  5719. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  5720. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  5721. return result;
  5722. }
  5723. //==========================================
  5724. // send confirm routine
  5725. //==========================================
  5726. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5727. {
  5728. mtrace();
  5729. int result = FAIL;
  5730. char message[100]={0};
  5731. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5732. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5733. LWS_Send(message);
  5734. result = TRUE;
  5735. return result;
  5736. }
  5737. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5738. {
  5739. mtrace();
  5740. int result = FAIL;
  5741. char message[100]={0};
  5742. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5743. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5744. LWS_Send(message);
  5745. result = TRUE;
  5746. return result;
  5747. }
  5748. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5749. {
  5750. mtrace();
  5751. int result = FAIL;
  5752. char message[100]={0};
  5753. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5754. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5755. LWS_Send(message);
  5756. result = TRUE;
  5757. return result;
  5758. }
  5759. int sendClearCacheConfirmation(char *uuid,char *payload)
  5760. {
  5761. mtrace();
  5762. int result = FAIL;
  5763. char message[500]={0};
  5764. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5765. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5766. LWS_Send(message);
  5767. return result;
  5768. }
  5769. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5770. {
  5771. mtrace();
  5772. int result = FAIL;
  5773. char message[500]={0};
  5774. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5775. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5776. LWS_Send(message);
  5777. return result;
  5778. }
  5779. int sendDataTransferConfirmation(char *uuid,char *payload)
  5780. {
  5781. mtrace();
  5782. char statusStr[20]={0};
  5783. char dataStr[10]={0};
  5784. char sstr[20]={0};
  5785. int c = 0;
  5786. char *loc;
  5787. int result = FAIL;
  5788. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5789. /**********************status**************************/
  5790. loc = strstr(payload, "status");
  5791. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5792. c = 0;
  5793. while (loc[3+strlen("status")+c] != '\"')
  5794. {
  5795. sstr[c] = loc[3+strlen("status")+c];
  5796. c++;
  5797. }
  5798. sstr[c] = '\0';
  5799. strcpy(statusStr, sstr);
  5800. /**********************data**************************/
  5801. loc = strstr(payload, "data");
  5802. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5803. c = 0;
  5804. while (loc[3+strlen("data")+c] != '\"')
  5805. {
  5806. sstr[c] = loc[3+strlen("data")+c];
  5807. c++;
  5808. }
  5809. sstr[c] = '\0';
  5810. strcpy(dataStr, sstr);
  5811. return result;
  5812. }
  5813. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5814. {
  5815. mtrace();
  5816. int result = FAIL;
  5817. char message[1000]={0};
  5818. int CompositeScheduleIndex = 0;
  5819. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5820. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5821. if(nPeriod == 0)
  5822. {
  5823. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5824. {
  5825. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5826. ,MESSAGE_TYPE_CALLRESULT
  5827. ,uuid
  5828. ,payload
  5829. ,connectorIdInt);
  5830. }
  5831. else
  5832. {
  5833. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5834. ,MESSAGE_TYPE_CALLRESULT
  5835. ,uuid
  5836. ,payload
  5837. ,connectorIdInt
  5838. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5839. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5840. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5841. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5842. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5843. }
  5844. }
  5845. else
  5846. {
  5847. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5848. ,MESSAGE_TYPE_CALLRESULT
  5849. ,uuid
  5850. ,payload
  5851. ,connectorIdInt
  5852. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5853. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5854. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5855. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5856. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5857. {
  5858. if (idx_sample == 0)
  5859. {
  5860. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5861. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5862. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5863. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5864. }
  5865. else
  5866. {
  5867. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5868. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5869. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5870. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5871. }
  5872. }
  5873. sprintf(message + strlen(message), "]}}]");
  5874. }
  5875. LWS_Send(message);
  5876. result = TRUE;
  5877. return result;
  5878. }
  5879. int sendGetConfigurationConfirmation(char *uuid)
  5880. {
  5881. mtrace();
  5882. int result = FAIL;
  5883. int MaxKeySupported = 0;
  5884. int sentConfigurationNumber= 0;
  5885. int sentunConfigurationNumber= 0;
  5886. char message[4000]={0};
  5887. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5888. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5889. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5890. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5891. ,MESSAGE_TYPE_CALLRESULT
  5892. ,uuid );
  5893. //configuration key
  5894. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5895. {
  5896. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5897. {
  5898. if (sentConfigurationNumber == 0)
  5899. {
  5900. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5901. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5902. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5903. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5904. }
  5905. else
  5906. {
  5907. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5908. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5909. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5910. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5911. }
  5912. sentConfigurationNumber = sentConfigurationNumber + 1;
  5913. }
  5914. }
  5915. sprintf(message + strlen(message), "]");
  5916. if(UnknownKeynum != 0)
  5917. {
  5918. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5919. //unkown key
  5920. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5921. {
  5922. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5923. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5924. if(sentunConfigurationNumber == 0)
  5925. {
  5926. sprintf(message + strlen(message), "\"%s\""
  5927. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5928. }
  5929. else
  5930. {
  5931. sprintf(message + strlen(message), ",\"%s\""
  5932. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5933. }
  5934. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5935. }
  5936. sprintf(message + strlen(message), "]");
  5937. }
  5938. sprintf(message + strlen(message), "}]");
  5939. LWS_Send(message);
  5940. return result;
  5941. }
  5942. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5943. {
  5944. mtrace();
  5945. int result = FAIL;
  5946. char message[400]={0};
  5947. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5948. if(strcmp(payload,"")==0)
  5949. {
  5950. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5951. }
  5952. else
  5953. {
  5954. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5955. }
  5956. LWS_Send(message);
  5957. result = TRUE;
  5958. return result;
  5959. }
  5960. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5961. {
  5962. mtrace();
  5963. int result = FAIL;
  5964. char message[80]={0};
  5965. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5966. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5967. LWS_Send(message);
  5968. result = TRUE;
  5969. return result;
  5970. }
  5971. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5972. {
  5973. mtrace();
  5974. int result = FAIL;
  5975. char message[80]={0};
  5976. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5977. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5978. LWS_Send(message);
  5979. result = TRUE;
  5980. return result;
  5981. }
  5982. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5983. {
  5984. mtrace();
  5985. int result = FAIL;
  5986. char message[80]={0};
  5987. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5988. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5989. LWS_Send(message);
  5990. result = TRUE;
  5991. return result;
  5992. }
  5993. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5994. {
  5995. mtrace();
  5996. int result = FAIL;
  5997. char message[80]={0};
  5998. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5999. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  6000. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6001. LWS_Send(message);
  6002. result = TRUE;
  6003. return result;
  6004. }
  6005. int sendResetConfirmation(char *uuid,char *payload)
  6006. {
  6007. mtrace();
  6008. int result = FAIL;
  6009. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6010. char message[80]={0};
  6011. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  6012. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6013. LWS_Send(message);
  6014. result = TRUE;
  6015. return result;
  6016. }
  6017. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6018. {
  6019. mtrace();
  6020. int result = FAIL;
  6021. char message[500]={0};
  6022. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6023. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6024. LWS_Send(message);
  6025. result = TRUE;
  6026. return result;
  6027. }
  6028. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6029. {
  6030. mtrace();
  6031. int result = FAIL;
  6032. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6033. char message[80]={0};
  6034. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6035. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6036. LWS_Send(message);
  6037. result = TRUE;
  6038. return result;
  6039. }
  6040. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6041. {
  6042. mtrace();
  6043. int result = FAIL;
  6044. char message[80]={0};
  6045. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6046. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6047. LWS_Send(message);
  6048. result = TRUE;
  6049. return result;
  6050. }
  6051. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6052. {
  6053. mtrace();
  6054. int result = FAIL;
  6055. char message[80]={0};
  6056. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6057. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6058. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6059. LWS_Send(message);
  6060. result = TRUE;
  6061. return result;
  6062. }
  6063. int sendUpdateFirmwareConfirmation(char *uuid)
  6064. {
  6065. mtrace();
  6066. int result = FAIL;
  6067. char message[60]={0};
  6068. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6069. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6070. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6071. LWS_Send(message);
  6072. result = TRUE;
  6073. return result;
  6074. }
  6075. int sendCertificateSignedConfirmation(char *uuid)
  6076. {
  6077. mtrace();
  6078. int result = PASS;
  6079. char message[4096]={0};
  6080. json_object *CertificateSigned = json_object_new_object();
  6081. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6082. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  6083. sprintf(message,"[%d,\"%s\",%s]"
  6084. ,MESSAGE_TYPE_CALLRESULT
  6085. ,uuid
  6086. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6087. json_object_put(CertificateSigned);
  6088. LWS_Send(message);
  6089. return result;
  6090. }
  6091. int sendDeleteCertificateConfirmation(char *uuid)
  6092. {
  6093. mtrace();
  6094. int result = PASS;
  6095. char message[4096]={0};
  6096. json_object *DeleteCertificate = json_object_new_object();
  6097. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6098. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  6099. sprintf(message,"[%d,\"%s\",%s]"
  6100. ,MESSAGE_TYPE_CALLRESULT
  6101. ,uuid
  6102. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6103. json_object_put(DeleteCertificate);
  6104. LWS_Send(message);
  6105. return result;
  6106. }
  6107. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6108. {
  6109. mtrace();
  6110. int result = PASS;
  6111. char message[4096]={0};
  6112. json_object *ExtendedTriggerMessage = json_object_new_object();
  6113. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6114. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  6115. sprintf(message,"[%d,\"%s\",%s]"
  6116. ,MESSAGE_TYPE_CALLRESULT
  6117. ,uuid
  6118. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6119. json_object_put(ExtendedTriggerMessage);
  6120. LWS_Send(message);
  6121. return result;
  6122. }
  6123. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6124. {
  6125. mtrace();
  6126. int result = PASS;
  6127. char message[4096]={0};
  6128. json_object *GetInstalledCertificateIds = json_object_new_object();
  6129. json_object *certificateHashDataDatas = json_object_new_array();
  6130. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6131. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  6132. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6133. {
  6134. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6135. {
  6136. json_object *certificateHashData = json_object_new_object();
  6137. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6138. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6139. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6140. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6141. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6142. }
  6143. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6144. }
  6145. else
  6146. {
  6147. json_object_put(certificateHashDataDatas);
  6148. }
  6149. sprintf(message,"[%d,\"%s\",%s]"
  6150. ,MESSAGE_TYPE_CALLRESULT
  6151. ,uuid
  6152. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6153. json_object_put(GetInstalledCertificateIds);
  6154. LWS_Send(message);
  6155. return result;
  6156. }
  6157. int sendGetLogConfirmation(char *uuid)
  6158. {
  6159. mtrace();
  6160. int result = PASS;
  6161. char message[4096]={0};
  6162. json_object *GetLog = json_object_new_object();
  6163. DEBUG_INFO("sendGetLogConfirmation...\n");
  6164. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  6165. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  6166. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  6167. sprintf(message,"[%d,\"%s\",%s]"
  6168. ,MESSAGE_TYPE_CALLRESULT
  6169. ,uuid
  6170. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6171. json_object_put(GetLog);
  6172. LWS_Send(message);
  6173. return result;
  6174. }
  6175. int sendInstallCertificateConfirmation(char *uuid)
  6176. {
  6177. mtrace();
  6178. int result = PASS;
  6179. char message[4096]={0};
  6180. json_object *InstallCertificate = json_object_new_object();
  6181. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6182. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  6183. sprintf(message,"[%d,\"%s\",%s]"
  6184. ,MESSAGE_TYPE_CALLRESULT
  6185. ,uuid
  6186. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6187. json_object_put(InstallCertificate);
  6188. LWS_Send(message);
  6189. return result;
  6190. }
  6191. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6192. {
  6193. mtrace();
  6194. int result = PASS;
  6195. char message[4096]={0};
  6196. json_object *SignedUpdateFirmware = json_object_new_object();
  6197. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6198. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  6199. sprintf(message,"[%d,\"%s\",%s]"
  6200. ,MESSAGE_TYPE_CALLRESULT
  6201. ,uuid
  6202. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6203. json_object_put(SignedUpdateFirmware);
  6204. LWS_Send(message);
  6205. return result;
  6206. }
  6207. int sendUnknownConfirmation(char *uuid)
  6208. {
  6209. mtrace();
  6210. int result = PASS;
  6211. char message[256]={0};
  6212. DEBUG_INFO("sendUnknownConfirmation...\n");
  6213. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6214. LWS_Send(message);
  6215. return result;
  6216. }
  6217. //==========================================
  6218. // Handle server request routine Start
  6219. //==========================================
  6220. int handleCancelReservationRequest(char *uuid, char *payload)
  6221. {
  6222. mtrace();
  6223. int result = FAIL;
  6224. int gunNO = 0;
  6225. int reservationIdInt = -1;
  6226. char comfirmstr[20];
  6227. DEBUG_INFO("handleCancelReservationRequest...\n");
  6228. json_object *CancelReservation;
  6229. CancelReservation = json_tokener_parse(payload);
  6230. if(!is_error(CancelReservation))
  6231. {
  6232. // Required data
  6233. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6234. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6235. }
  6236. json_object_put(CancelReservation);
  6237. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6238. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6239. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6240. if(reservationIdInt != -1)
  6241. {
  6242. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6243. //check Transaction active
  6244. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6245. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6246. {
  6247. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6248. {
  6249. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6250. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6251. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6252. {
  6253. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6254. }
  6255. else
  6256. {
  6257. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6258. }
  6259. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6260. goto end;
  6261. }
  6262. }
  6263. for (int index = 0; index < CCS_QUANTITY; index++)
  6264. {
  6265. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6266. {
  6267. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6268. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6269. if(gunType[2] == GUN_TYPE_CCS)
  6270. {
  6271. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6272. }
  6273. else
  6274. {
  6275. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6276. }
  6277. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6278. goto end;
  6279. }
  6280. }
  6281. for (int index = 0; index < GB_QUANTITY; index++)
  6282. {
  6283. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6284. {
  6285. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6286. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6287. if(gunType[2] == GUN_TYPE_GBT)
  6288. {
  6289. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6290. }
  6291. else
  6292. {
  6293. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6294. }
  6295. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6296. goto end;
  6297. }
  6298. }
  6299. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6300. {
  6301. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6302. {
  6303. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6304. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6305. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6306. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6307. goto end;
  6308. }
  6309. }
  6310. for (int index = 0; index < AC_QUANTITY; index++)
  6311. {
  6312. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  6313. {
  6314. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6315. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6316. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6317. {
  6318. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  6319. }
  6320. else
  6321. {
  6322. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  6323. }
  6324. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6325. goto end;
  6326. }
  6327. }
  6328. }
  6329. //The reservationId does NOT match the reservationId
  6330. sendCancelReservationConfirmation(uuid, comfirmstr);
  6331. end:
  6332. // Fill in ocpp packet uuid
  6333. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  6334. return result;
  6335. }
  6336. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  6337. {
  6338. mtrace();
  6339. int result = FAIL;
  6340. int gunIndex = 0;
  6341. char typeStr[16]={0};
  6342. char comfirmstr[20];
  6343. int specificId = FALSE;
  6344. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  6345. json_object *ChangeAvailability;
  6346. ChangeAvailability = json_tokener_parse(payload);
  6347. if(!is_error(ChangeAvailability))
  6348. {
  6349. // Required data
  6350. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  6351. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  6352. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  6353. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  6354. }
  6355. json_object_put(ChangeAvailability);
  6356. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6357. {
  6358. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  6359. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  6360. }
  6361. else if(gunIndex == 0)
  6362. {
  6363. for(int i=0; i < gunTotalNumber; i++)
  6364. {
  6365. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  6366. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  6367. }
  6368. }
  6369. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6370. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6371. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6372. {
  6373. specificId = TRUE;
  6374. }
  6375. if(specificId == FALSE)
  6376. goto end;
  6377. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6378. {
  6379. //----------------------gunIndex is 0 ------------------------------------------------//
  6380. if(gunIndex == 0)
  6381. {
  6382. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6383. {
  6384. for(int i=0; i < gunTotalNumber; i++)
  6385. {
  6386. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6387. {
  6388. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6389. {
  6390. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6391. {
  6392. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6393. goto end;
  6394. }
  6395. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6396. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6397. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6398. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6399. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6400. {
  6401. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6402. goto end;
  6403. }
  6404. }
  6405. }//END FOR CHAdeMO_QUANTITY
  6406. for (int index = 0; index < CCS_QUANTITY; index++)
  6407. {
  6408. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6409. {
  6410. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6411. {
  6412. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6413. goto end;
  6414. }
  6415. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6416. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6417. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6418. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6419. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6420. {
  6421. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6422. goto end;
  6423. }
  6424. }
  6425. }//END FOR CCS_QUANTITY
  6426. for (int index = 0; index < GB_QUANTITY; index++)
  6427. {
  6428. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6429. {
  6430. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6431. {
  6432. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6433. goto end;
  6434. }
  6435. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6436. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6437. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6438. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6439. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6440. {
  6441. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6442. goto end;
  6443. }
  6444. }
  6445. }// END FOR GB_QUANTITY
  6446. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6447. {
  6448. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6449. {
  6450. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6451. {
  6452. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6453. goto end;
  6454. }
  6455. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6456. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6457. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6458. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6459. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6460. {
  6461. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6462. goto end;
  6463. }
  6464. }
  6465. }// END FOR GENERAL_GUN_QUANTITY
  6466. for (int index = 0; index < AC_QUANTITY; index++)
  6467. {
  6468. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6469. {
  6470. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6471. {
  6472. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6473. goto end;
  6474. }
  6475. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6476. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6477. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6478. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6479. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6480. {
  6481. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6482. goto end;
  6483. }
  6484. }
  6485. }//END FOR AC_QUANTITY
  6486. }// END FOR gunTotalNumber
  6487. }
  6488. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6489. {
  6490. for(int i=0; i < gunTotalNumber; i++)
  6491. {
  6492. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6493. {
  6494. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6495. goto end;
  6496. }
  6497. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6498. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6499. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6500. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6501. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6502. {
  6503. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6504. goto end;
  6505. }
  6506. }
  6507. }
  6508. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6509. goto end;
  6510. }
  6511. //----------------------gunIndex is not 0 ------------------------------------------------//
  6512. //check Transaction active
  6513. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6514. {
  6515. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6516. {
  6517. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6518. {
  6519. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6520. goto end;
  6521. }
  6522. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6523. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6524. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6525. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6526. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6527. {
  6528. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6529. goto end;
  6530. }
  6531. else
  6532. {
  6533. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6534. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6535. goto end;
  6536. }
  6537. }
  6538. }//END FOR CHAdeMO_QUANTITY
  6539. for (int index = 0; index < CCS_QUANTITY; index++)
  6540. {
  6541. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6542. {
  6543. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6544. {
  6545. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6546. goto end;
  6547. }
  6548. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6549. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6550. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6551. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6552. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6553. {
  6554. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6555. goto end;
  6556. }
  6557. else
  6558. {
  6559. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  6560. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6561. goto end;
  6562. }
  6563. }
  6564. }//END FOR CCS_QUANTITY
  6565. for (int index = 0; index < GB_QUANTITY; index++)
  6566. {
  6567. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  6568. {
  6569. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6570. {
  6571. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6572. goto end;
  6573. }
  6574. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6575. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6576. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6577. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6578. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6579. {
  6580. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6581. goto end;
  6582. }
  6583. else
  6584. {
  6585. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  6586. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6587. goto end;
  6588. }
  6589. }
  6590. }// END FOR GB_QUANTITY
  6591. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6592. {
  6593. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  6594. {
  6595. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6596. {
  6597. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6598. goto end;
  6599. }
  6600. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6601. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6602. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6603. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6604. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6605. {
  6606. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6607. goto end;
  6608. }
  6609. else
  6610. {
  6611. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  6612. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6613. goto end;
  6614. }
  6615. }
  6616. }// END FOR GENERAL_GUN_QUANTITY
  6617. for (int index = 0; index < AC_QUANTITY; index++)
  6618. {
  6619. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  6620. {
  6621. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6622. {
  6623. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6624. goto end;
  6625. }
  6626. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6627. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6628. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6629. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6630. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6631. {
  6632. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6633. goto end;
  6634. }
  6635. else
  6636. {
  6637. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  6638. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6639. goto end;
  6640. }
  6641. }
  6642. }//END FOR AC_QUANTITY
  6643. }//END FOR AvailabilityTypeStr[Inoperative]
  6644. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  6645. {
  6646. //----------------------gunIndex is 0 ------------------------------------------------//
  6647. if(gunIndex == 0)
  6648. {
  6649. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6650. {
  6651. for(int i=0; i < gunTotalNumber; i++)
  6652. {
  6653. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6654. {
  6655. 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
  6656. {
  6657. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6658. goto end;
  6659. }
  6660. }//END FOR CHAdeMO_QUANTITY
  6661. for (int index = 0; index < CCS_QUANTITY; index++)
  6662. {
  6663. 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
  6664. {
  6665. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6666. goto end;
  6667. }
  6668. }//END FOR CCS_QUANTITY
  6669. for (int index = 0; index < GB_QUANTITY; index++)
  6670. {
  6671. 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
  6672. {
  6673. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6674. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6675. goto end;
  6676. }
  6677. }// END FOR GB_QUANTITY
  6678. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6679. {
  6680. 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
  6681. {
  6682. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6683. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6684. goto end;
  6685. }
  6686. }// END FOR GENERAL_GUN_QUANTITY
  6687. for (int index = 0; index < AC_QUANTITY; index++)
  6688. {
  6689. 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
  6690. {
  6691. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6692. goto end;
  6693. }
  6694. }//END FOR CHAdeMO_QUANTITY
  6695. }// END FOR gunTotalNumber
  6696. }
  6697. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6698. {
  6699. for(int i=0; i < gunTotalNumber; i++)
  6700. {
  6701. for (int index = 0; index < AC_QUANTITY; index++)
  6702. {
  6703. 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
  6704. {
  6705. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6706. goto end;
  6707. }
  6708. }//END FOR CHAdeMO_QUANTITY
  6709. } // END FOR gunTotalNumber
  6710. }
  6711. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6712. goto end;
  6713. }
  6714. //----------------------gunIndex is not 0 ------------------------------------------------//
  6715. //check Transaction active
  6716. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6717. {
  6718. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6719. {
  6720. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6721. goto end;
  6722. }
  6723. }//END FOR CHAdeMO_QUANTITY
  6724. for (int index = 0; index < CCS_QUANTITY; index++)
  6725. {
  6726. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6727. {
  6728. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6729. goto end;
  6730. }
  6731. }//END FOR CCS_QUANTITY
  6732. for (int index = 0; index < GB_QUANTITY; index++)
  6733. {
  6734. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6735. {
  6736. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6737. goto end;
  6738. }
  6739. }// END FOR GB_QUANTITY
  6740. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6741. {
  6742. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6743. {
  6744. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6745. goto end;
  6746. }
  6747. }// END FOR GENERAL_GUN_QUANTITY
  6748. for (int index = 0; index < AC_QUANTITY; index++)
  6749. {
  6750. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6751. {
  6752. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6753. goto end;
  6754. }
  6755. }//END FOR AC_QUANTITY
  6756. }//END FOR AvailabilityTypeStr[Operative]
  6757. end:
  6758. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6759. {
  6760. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6761. }
  6762. else
  6763. {
  6764. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6765. }
  6766. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6767. {
  6768. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6769. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6770. }
  6771. else if(gunIndex == 0)
  6772. {
  6773. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6774. {
  6775. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6776. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6777. }
  6778. }
  6779. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6780. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6781. return result;
  6782. }
  6783. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6784. {
  6785. mtrace();
  6786. int result = FAIL;
  6787. char keystr[40]={0};
  6788. char valuestr[256]={0};
  6789. char comfirmstr[20]={0};
  6790. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6791. json_object *ChangeConfiguration;
  6792. ChangeConfiguration = json_tokener_parse(payload);
  6793. if(!is_error(ChangeConfiguration))
  6794. {
  6795. // Required data
  6796. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6797. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6798. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6799. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6800. }
  6801. json_object_put(ChangeConfiguration);
  6802. if((uuid==NULL) || (payload ==NULL) )
  6803. {
  6804. DEBUG_ERROR("Payload is null\n");
  6805. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6806. }
  6807. else
  6808. {
  6809. int status = setKeyValue(keystr, valuestr);
  6810. switch(status)
  6811. {
  6812. case ConfigurationStatus_Accepted:
  6813. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6814. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  6815. StoreConfigurationTable();
  6816. break;
  6817. case RebootRequired:
  6818. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6819. StoreConfigurationTable();
  6820. break;
  6821. case NotSupported:
  6822. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6823. break;
  6824. case ConfigurationStatus_Rejected:
  6825. default:
  6826. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6827. break;
  6828. }
  6829. }
  6830. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6831. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  6832. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6833. {
  6834. ChageWebSocketPingInterval(atoi(valuestr));
  6835. }
  6836. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  6837. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6838. {
  6839. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  6840. SetOcppConnStatus(FALSE);
  6841. }
  6842. return result;
  6843. }
  6844. int handleClearCacheRequest(char *uuid, char *payload)
  6845. {
  6846. mtrace();
  6847. int result = FAIL;
  6848. char comfirmstr[20];
  6849. char rmFileCmd[100]={0};
  6850. struct stat stats;
  6851. DEBUG_INFO("handleClearCacheRequest...\n");
  6852. stat("/Storage/OCPP", &stats);
  6853. // Check for directory existence
  6854. if (S_ISDIR(stats.st_mode) == 1)
  6855. {}
  6856. else
  6857. {
  6858. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6859. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6860. system(rmFileCmd);
  6861. }
  6862. if(OCPP_cleanLocalCache())
  6863. {
  6864. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6865. }
  6866. else
  6867. {
  6868. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6869. }
  6870. sendClearCacheConfirmation(uuid, comfirmstr);
  6871. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6872. return result;
  6873. }
  6874. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6875. {
  6876. mtrace();
  6877. int result = FAIL;
  6878. int resultRename;
  6879. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6880. char chargingProfilePurposeStr[26]={0};
  6881. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6882. char tempchargingProfilePurposeStr[26]={0};
  6883. char str[100]={0};
  6884. char fname[200]={0};
  6885. char comfirmstr[20]={0};
  6886. char word[1600]={0};
  6887. int clearflag = FALSE;
  6888. int chargingProfileIdIsNULL = FALSE;
  6889. int connectorIsNULL = FALSE;
  6890. int chargingProfilePurposeIsNULL = FALSE;
  6891. int stackLevelIsNULL = FALSE;
  6892. //int GotoEnd = FALSE;
  6893. FILE *fptr1, *fptr2;
  6894. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6895. int n_chargingProfile=0;
  6896. int isEmptyFile = FALSE;
  6897. char sLineWord[1600]={0};
  6898. char chargingProfiles[10][100]={0};
  6899. int ChargeProfileCount = 0;
  6900. int ch;
  6901. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6902. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6903. json_object *ClearChargingProfile;
  6904. ClearChargingProfile = json_tokener_parse(payload);
  6905. if(!is_error(ClearChargingProfile))
  6906. {
  6907. // Optional data
  6908. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6909. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6910. else
  6911. chargingProfileIdIsNULL = TRUE;
  6912. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6913. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6914. else
  6915. connectorIsNULL = TRUE;
  6916. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6917. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6918. else
  6919. chargingProfilePurposeIsNULL = TRUE;
  6920. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6921. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6922. else
  6923. stackLevelIsNULL = TRUE;
  6924. }
  6925. json_object_put(ClearChargingProfile);
  6926. if(connectorIsNULL == FALSE)
  6927. {
  6928. switch(connectorIdInt)
  6929. {
  6930. case 0:
  6931. if(chargingProfilePurposeIsNULL == TRUE)
  6932. {
  6933. int l = 0;
  6934. strcpy(fname, ChargePointMaxProfile_JSON);
  6935. if((access(fname,F_OK))!=-1)
  6936. {
  6937. strcpy(chargingProfiles[l], fname);
  6938. l = l + 1;
  6939. }
  6940. strcpy(fname, TxDefaultProfile_0_JSON);
  6941. if((access(fname,F_OK))!=-1)
  6942. {
  6943. strcpy(chargingProfiles[l], fname);
  6944. l = l + 1;
  6945. }
  6946. ChargeProfileCount = l;
  6947. }
  6948. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6949. {
  6950. strcpy(fname, ChargePointMaxProfile_JSON);
  6951. if((access(fname,F_OK))!=-1)
  6952. {
  6953. strcpy(chargingProfiles[0], fname);
  6954. ChargeProfileCount = 1;
  6955. }
  6956. }
  6957. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6958. {
  6959. strcpy(fname, TxDefaultProfile_0_JSON);
  6960. if((access(fname,F_OK))!=-1)
  6961. {
  6962. strcpy(chargingProfiles[0], fname);
  6963. ChargeProfileCount = 1;
  6964. }
  6965. }
  6966. break;
  6967. default:
  6968. if(chargingProfilePurposeIsNULL == TRUE)
  6969. {
  6970. int m = 0;
  6971. memset(fname, 0, ARRAY_SIZE(fname));
  6972. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6973. if((access(fname,F_OK))!=-1)
  6974. {
  6975. strcpy(chargingProfiles[m], fname);
  6976. m = m + 1;
  6977. }
  6978. memset(fname, 0, ARRAY_SIZE(fname));
  6979. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6980. if((access(fname,F_OK))!=-1)
  6981. {
  6982. strcpy(chargingProfiles[m], fname);
  6983. m = m + 1;
  6984. }
  6985. ChargeProfileCount = m;
  6986. }
  6987. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6988. {
  6989. //strcpy(fname, TxDefaultProfile_1_JSON);
  6990. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6991. if((access(fname,F_OK))!=-1)
  6992. {
  6993. strcpy(chargingProfiles[0], fname);
  6994. ChargeProfileCount = 1;
  6995. }
  6996. }
  6997. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6998. {
  6999. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7000. if((access(fname,F_OK))!=-1)
  7001. {
  7002. strcpy(chargingProfiles[0], fname);
  7003. ChargeProfileCount = 1;
  7004. }
  7005. //strcpy(fname, TxProfile_1_JSON);
  7006. }
  7007. //strcpy(fname, ChargePointMaxProfile_JSON );
  7008. break;
  7009. }
  7010. }
  7011. else // Check all Charging Profiles
  7012. {
  7013. int i = 0;
  7014. char fnametemp[200]={0};
  7015. ChargeProfileCount = 0;
  7016. //Check ChargePointMaxProfile.json exit
  7017. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  7018. {
  7019. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  7020. i = i + 1;
  7021. }
  7022. //Check TxDefaultProfile_0.json exit
  7023. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  7024. {
  7025. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  7026. i = i + 1;
  7027. }
  7028. //Check TxDefaultProfile_%d.json
  7029. for(int j=1; j <= gunTotalNumber; j++)
  7030. {
  7031. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7032. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  7033. if((access(fnametemp,F_OK))!=-1)
  7034. {
  7035. strcpy(chargingProfiles[i], fnametemp);
  7036. i = i + 1;
  7037. }
  7038. }
  7039. //Check TxProfile_%d.json
  7040. for(int j=1; j <= gunTotalNumber; j++)
  7041. {
  7042. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7043. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  7044. if((access(fnametemp,F_OK))!=-1)
  7045. {
  7046. strcpy(chargingProfiles[i], fnametemp);
  7047. i = i + 1;
  7048. }
  7049. }
  7050. ChargeProfileCount = i;
  7051. }// End connectorIsNULL is TRUE
  7052. if(ChargeProfileCount == 0)
  7053. {
  7054. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7055. goto end;
  7056. }
  7057. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7058. {
  7059. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7060. goto end;
  7061. }
  7062. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7063. {
  7064. memset(str, 0, ARRAY_SIZE(str));
  7065. // clear temp file
  7066. sprintf(str,"rm -f %s",temp);
  7067. system(str);
  7068. for(int k=0; k < ChargeProfileCount; k++)
  7069. {
  7070. memset(str, 0, ARRAY_SIZE(str));
  7071. //clear file in C
  7072. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7073. system(str);
  7074. }
  7075. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7076. goto end;
  7077. }
  7078. else if(connectorIsNULL == TRUE)
  7079. {
  7080. for(int k=0; k < ChargeProfileCount; k++)
  7081. {
  7082. fptr1 = fopen(chargingProfiles[k], "r");
  7083. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  7084. //Check Charging Profile Count
  7085. while(fscanf(fptr1, "%s", word) != EOF)
  7086. {
  7087. //DEBUG_INFO("word=%s\n",word);
  7088. if(strstr(word, "chargingProfileId")!= NULL)
  7089. {
  7090. //DEBUG_INFO("test chargingProfileId \n");
  7091. n_chargingProfile = n_chargingProfile + 1;
  7092. //DEBUG_INFO("chargingProfileId Found\n");
  7093. }
  7094. }
  7095. rewind(fptr1);
  7096. //search Charging Profile Element
  7097. //int i= 0;
  7098. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7099. {
  7100. json_object *tmpProfilee;
  7101. tmpProfilee = json_tokener_parse(sLineWord);
  7102. if(!is_error(tmpProfilee))
  7103. {
  7104. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7105. {
  7106. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7107. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7108. }
  7109. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7110. {
  7111. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7112. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7113. }
  7114. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7115. {
  7116. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7117. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7118. }
  7119. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7120. {
  7121. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7122. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7123. }
  7124. }
  7125. json_object_put(tmpProfilee);
  7126. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7127. {
  7128. //------- not write to fptr2-------//
  7129. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7130. //clearflag = TRUE;
  7131. }
  7132. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7133. {
  7134. //------- not write to fptr2-------//
  7135. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7136. }
  7137. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7138. {
  7139. //------- not write to fptr2-------//
  7140. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7141. }
  7142. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7143. {
  7144. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7145. }
  7146. else
  7147. {
  7148. fprintf(fptr2, sLineWord);//writing data into file
  7149. }
  7150. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7151. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7152. if(clearflag == TRUE)
  7153. {
  7154. fclose(fptr1);
  7155. fclose(fptr2);
  7156. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7157. system(str);
  7158. // clear temp file
  7159. sprintf(str,"rm -f %s",temp);
  7160. system(str);
  7161. }
  7162. else
  7163. {
  7164. fclose(fptr1);
  7165. fclose(fptr2);
  7166. memset(str, 0, ARRAY_SIZE(str));
  7167. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7168. system(str);
  7169. resultRename = rename(temp, chargingProfiles[k]);
  7170. if(resultRename == 0)
  7171. {
  7172. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7173. }
  7174. else
  7175. {
  7176. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7177. }
  7178. if(comfirmstr[0]== 0)
  7179. {
  7180. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7181. }
  7182. //Check chargingProfile is empty file
  7183. /*------ Read the file ----------------*/
  7184. fptr1=fopen(chargingProfiles[k],"r");
  7185. ch=fgetc(fptr1);
  7186. rewind(fptr1);
  7187. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7188. if(ch!=EOF)
  7189. {
  7190. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7191. {
  7192. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7193. if(sLineWord[0]=='\0')
  7194. {
  7195. isEmptyFile = TRUE;
  7196. break;
  7197. }
  7198. else
  7199. {
  7200. isEmptyFile = FALSE;
  7201. break;
  7202. }
  7203. }
  7204. }
  7205. else
  7206. isEmptyFile = TRUE;
  7207. fclose(fptr1);
  7208. if(isEmptyFile == TRUE)
  7209. {
  7210. memset(str, 0, ARRAY_SIZE(str));
  7211. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7212. system(str);
  7213. }
  7214. }
  7215. }// End of while(int k=0; k < ChargePointCount; k++)
  7216. }
  7217. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7218. {
  7219. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7220. for(int k=0; k < ChargeProfileCount; k++)
  7221. {
  7222. fptr1 = fopen(chargingProfiles[k], "r");
  7223. fptr2 = fopen(temp, "w+");
  7224. //Check Charging Profile Count
  7225. while(fscanf(fptr1, "%s", word) != EOF)
  7226. {
  7227. //DEBUG_INFO("word=%s\n",word);
  7228. if(strstr(word, "chargingProfileId")!= NULL)
  7229. {
  7230. n_chargingProfile = n_chargingProfile + 1;
  7231. }
  7232. }
  7233. rewind(fptr1);
  7234. //search Charging Profile Element
  7235. //int i= 0;
  7236. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7237. {
  7238. json_object *tmpProfilee;
  7239. tmpProfilee = json_tokener_parse(sLineWord);
  7240. if(!is_error(tmpProfilee))
  7241. {
  7242. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7243. {
  7244. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7245. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7246. }
  7247. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7248. {
  7249. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7250. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7251. }
  7252. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7253. {
  7254. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7255. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7256. }
  7257. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7258. {
  7259. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7260. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7261. }
  7262. }
  7263. json_object_put(tmpProfilee);
  7264. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7265. {
  7266. //------- not write to fptr2-------//
  7267. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7268. //clearflag = TRUE;
  7269. }
  7270. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7271. {
  7272. //------- not write to fptr2-------//
  7273. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7274. }
  7275. else if(stackLevelIsNULL == TRUE)
  7276. {
  7277. //Clear Whole File
  7278. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7279. clearflag = TRUE;
  7280. break;
  7281. }
  7282. else
  7283. {
  7284. fprintf(fptr2, sLineWord);//writing data into file
  7285. }
  7286. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7287. }
  7288. if(clearflag == TRUE)
  7289. {
  7290. fclose(fptr1);
  7291. fclose(fptr2);
  7292. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7293. system(str);
  7294. // clear temp file
  7295. sprintf(str,"rm -f %s",temp);
  7296. system(str);
  7297. }
  7298. else
  7299. {
  7300. fclose(fptr1);
  7301. fclose(fptr2);
  7302. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7303. system(str);
  7304. resultRename = rename(temp, chargingProfiles[k]);
  7305. if(resultRename == 0)
  7306. {
  7307. DEBUG_INFO("File ChargingProfile renamed successfully");
  7308. }
  7309. else
  7310. {
  7311. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7312. }
  7313. if(comfirmstr[0]== 0)
  7314. {
  7315. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7316. }
  7317. //Check chargingProfile is empty file
  7318. /*------ Read the file ----------------*/
  7319. fptr1=fopen(chargingProfiles[k],"r");
  7320. ch=fgetc(fptr1);
  7321. rewind(fptr1);
  7322. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7323. if(ch!=EOF)
  7324. {
  7325. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7326. {
  7327. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7328. if(sLineWord[0]=='\0')
  7329. {
  7330. isEmptyFile = TRUE;
  7331. break;
  7332. }
  7333. else
  7334. {
  7335. isEmptyFile = FALSE;
  7336. break;
  7337. }
  7338. }
  7339. }
  7340. else
  7341. isEmptyFile = TRUE;
  7342. fclose(fptr1);
  7343. if(isEmptyFile == TRUE)
  7344. {
  7345. memset(str, 0, ARRAY_SIZE(str));
  7346. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7347. system(str);
  7348. }
  7349. /*------- End of reading ---------------*/
  7350. }
  7351. } // while(int k=0; k < ChargeProfileCount; k++)
  7352. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  7353. end:
  7354. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  7355. {
  7356. if(connectorIdInt == 0)
  7357. {
  7358. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  7359. {
  7360. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  7361. }
  7362. }
  7363. else
  7364. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  7365. }
  7366. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  7367. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7368. return result;
  7369. }
  7370. void createFirmwareVersionByDataTransfer(void)
  7371. {
  7372. json_object *FirmwareDataTransfer = json_object_new_object();
  7373. // AC & DC model
  7374. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7375. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7376. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7377. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7378. // DC model
  7379. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  7380. {
  7381. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7382. {
  7383. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7384. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7385. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7386. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7387. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7388. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7389. }
  7390. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  7391. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  7392. {
  7393. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7394. }
  7395. }
  7396. else
  7397. {
  7398. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7399. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7400. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7401. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7402. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7403. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7404. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7405. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7406. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7407. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7408. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7409. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7410. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7411. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7412. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7413. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7414. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7415. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7416. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7417. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7418. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7419. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7420. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7421. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7422. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7423. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7424. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7425. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7426. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7427. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7428. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7429. }
  7430. // 4G model
  7431. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7432. {
  7433. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7434. }
  7435. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7436. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7437. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7438. json_object_put(FirmwareDataTransfer);
  7439. }
  7440. int handleDataTransferRequest(char *uuid, char *payload)
  7441. {
  7442. mtrace();
  7443. json_object *response = json_object_new_object();
  7444. int result = FAIL;
  7445. char tempvendorId[255]={0};
  7446. char tempmessageId[50]={0};
  7447. char tempdata[512]={0};
  7448. char message[2048]={0};
  7449. DEBUG_INFO("handleDataTransferRequest...\n");
  7450. if((uuid != NULL) && (payload != NULL))
  7451. {
  7452. json_object *DataTransfer;
  7453. DataTransfer = json_tokener_parse(payload);
  7454. if(!is_error(DataTransfer))
  7455. {
  7456. // Required data
  7457. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7458. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7459. // Optional data
  7460. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7461. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7462. if(json_object_object_get(DataTransfer, "data") != NULL)
  7463. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7464. result = PASS;
  7465. }
  7466. json_object_put(DataTransfer);
  7467. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7468. {
  7469. // Send all moudle firmware version on EVSE
  7470. createFirmwareVersionByDataTransfer();
  7471. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7472. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  7473. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7474. json_object_put(response);
  7475. }
  7476. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7477. {
  7478. system("/usr/bin/run_tmate_restart.sh &");
  7479. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7480. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7481. json_object_put(response);
  7482. }
  7483. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7484. {
  7485. json_object *data;
  7486. data = json_tokener_parse(tempdata);
  7487. if(!is_error(data))
  7488. {
  7489. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7490. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7491. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7492. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7493. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7494. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7495. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7496. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7497. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7498. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7499. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7500. }
  7501. else
  7502. {
  7503. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7504. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7505. }
  7506. json_object_put(data);
  7507. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7508. json_object_put(response);
  7509. }
  7510. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7511. {
  7512. json_object *data;
  7513. data = json_tokener_parse(tempdata);
  7514. if(!is_error(data))
  7515. {
  7516. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7517. if(json_object_object_get(data, "idToken") != NULL)
  7518. {
  7519. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7520. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7521. }
  7522. if(json_object_object_get(data, "price") != NULL)
  7523. {
  7524. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7525. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7526. }
  7527. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7528. }
  7529. else
  7530. {
  7531. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7532. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7533. }
  7534. json_object_put(data);
  7535. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7536. json_object_put(response);
  7537. }
  7538. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7539. {
  7540. json_object *data;
  7541. data = json_tokener_parse(tempdata);
  7542. if(!is_error(data))
  7543. {
  7544. if(json_object_object_get(data, "txId") != NULL)
  7545. {
  7546. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7547. for(int idx = 0;idx<gunTotalNumber;idx++)
  7548. {
  7549. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7550. {
  7551. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7552. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7553. if(json_object_object_get(data, "description") != NULL)
  7554. {
  7555. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7556. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7557. }
  7558. }
  7559. }
  7560. }
  7561. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7562. }
  7563. else
  7564. {
  7565. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7566. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7567. }
  7568. json_object_put(data);
  7569. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7570. json_object_put(response);
  7571. }
  7572. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7573. {
  7574. json_object *data;
  7575. data = json_tokener_parse(tempdata);
  7576. if(!is_error(data))
  7577. {
  7578. if(json_object_object_get(data, "txId") != NULL)
  7579. {
  7580. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7581. for(int idx = 0;idx<gunTotalNumber;idx++)
  7582. {
  7583. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7584. {
  7585. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7586. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7587. if(json_object_object_get(data, "description") != NULL)
  7588. {
  7589. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7590. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7591. }
  7592. }
  7593. }
  7594. }
  7595. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7596. }
  7597. else
  7598. {
  7599. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7600. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7601. }
  7602. json_object_put(data);
  7603. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7604. json_object_put(response);
  7605. }
  7606. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  7607. {
  7608. json_object *data;
  7609. data = json_tokener_parse(tempdata);
  7610. if(!is_error(data))
  7611. {
  7612. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7613. if(json_object_object_get(data, "Content_Type") != NULL)
  7614. {
  7615. 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))
  7616. {
  7617. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  7618. if(json_object_object_get(data, "Customization_Conent") != NULL)
  7619. {
  7620. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  7621. }
  7622. }
  7623. else
  7624. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7625. }
  7626. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7627. }
  7628. else
  7629. {
  7630. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7631. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7632. }
  7633. json_object_put(data);
  7634. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7635. json_object_put(response);
  7636. }
  7637. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  7638. {
  7639. json_object *data;
  7640. data = json_tokener_parse(tempdata);
  7641. if(!is_error(data))
  7642. {
  7643. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7644. if(json_object_object_get(data, "Page_Index") != NULL)
  7645. {
  7646. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  7647. }
  7648. if(json_object_object_get(data, "Duration") != NULL)
  7649. {
  7650. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  7651. }
  7652. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  7653. }
  7654. else
  7655. {
  7656. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7657. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7658. }
  7659. json_object_put(data);
  7660. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7661. json_object_put(response);
  7662. }
  7663. else
  7664. {
  7665. // Can not find valid message id
  7666. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7667. }
  7668. }
  7669. else
  7670. {
  7671. // Payload is null
  7672. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7673. }
  7674. LWS_Send(message);
  7675. return result;
  7676. }
  7677. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7678. {
  7679. mtrace();
  7680. int result = FAIL;
  7681. int connectorIdInt, durationInt;
  7682. char chargingRateUnitStr[4]={0};
  7683. char comfirmstr[20];
  7684. int confirmPeriods = 0;
  7685. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7686. json_object *GetCompositeSchedule;
  7687. GetCompositeSchedule = json_tokener_parse(payload);
  7688. if(!is_error(GetCompositeSchedule))
  7689. {
  7690. // Required data
  7691. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7692. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7693. else
  7694. connectorIdInt = -1;
  7695. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7696. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7697. else
  7698. durationInt = 86400;
  7699. // Optional data
  7700. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7701. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7702. }
  7703. json_object_put(GetCompositeSchedule);
  7704. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7705. if((connectorIdInt == 0) ||
  7706. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7707. {
  7708. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7709. struct StructChargingProfile tmpProfile[1];
  7710. if(strstr(chargingRateUnitStr, "W") != NULL)
  7711. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7712. else
  7713. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7714. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7715. {
  7716. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7717. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7718. }
  7719. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7720. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7721. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7722. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7723. {
  7724. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7725. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7726. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7727. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  7728. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  7729. {
  7730. confirmPeriods = idx;
  7731. break;
  7732. }
  7733. }
  7734. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  7735. {
  7736. confirmPeriods += 1;
  7737. }
  7738. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7739. }
  7740. else
  7741. {
  7742. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7743. }
  7744. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7745. return result;
  7746. }
  7747. int handleGetConfigurationRequest(char *uuid, char *payload)
  7748. {
  7749. mtrace();
  7750. int result = FAIL;
  7751. int MaxKeySupported = 0;
  7752. int n_keys = 0;
  7753. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7754. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7755. json_object *GetConfiguration;
  7756. GetConfiguration = json_tokener_parse(payload);
  7757. if(!is_error(GetConfiguration))
  7758. {
  7759. // Optional data
  7760. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7761. {
  7762. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7763. {
  7764. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7765. n_keys = idx + 1;
  7766. }
  7767. }
  7768. }
  7769. json_object_put(GetConfiguration);
  7770. UnknownKeynum = 0;
  7771. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7772. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7773. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7774. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7775. if(n_keys != 0)
  7776. {
  7777. for(int i=0;i<n_keys;i++)
  7778. {
  7779. getKeyValue(requestKey[i]);
  7780. }
  7781. }
  7782. else
  7783. {
  7784. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7785. getKeyValue("");
  7786. }
  7787. processUnkownKey();
  7788. sendGetConfigurationConfirmation(uuid);
  7789. return result;
  7790. }
  7791. static char fnamePlusPath[100]={0};
  7792. static char fnamePWithNoPath[60]={0};
  7793. void checkUploadLog(void)
  7794. {
  7795. FILE *fp;
  7796. /* Open the command for reading. */
  7797. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7798. if (fp == NULL) {
  7799. printf("Failed to run command\n" );
  7800. exit(1);
  7801. }
  7802. int ftppathlen = 0;
  7803. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7804. int i = 0;
  7805. /* Read the output a line at a time - output it. */
  7806. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7807. if(i==0)
  7808. {
  7809. ftppathlen = strlen(fnamePlusPath);
  7810. printf("%s\n", fnamePlusPath);
  7811. fnamePlusPath[ftppathlen]='\0';
  7812. break;
  7813. }
  7814. i= i+1;
  7815. }
  7816. /* close */
  7817. pclose(fp);
  7818. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7819. {
  7820. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7821. {
  7822. fnamePlusPath[k]='\0';
  7823. }
  7824. }
  7825. i=1;
  7826. //char fname[60]={0};
  7827. while(i < ftppathlen)
  7828. {
  7829. int len=ftppathlen-i;
  7830. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7831. {
  7832. printf("compare '/' all right\n");
  7833. break;
  7834. }
  7835. i=i+1;
  7836. }
  7837. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7838. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7839. fnamePWithNoPath[i+1] = '\0';
  7840. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7841. {
  7842. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7843. {
  7844. fnamePWithNoPath[j]='\0';
  7845. }
  7846. }
  7847. FILE* fp1 = fopen(fnamePlusPath, "r");
  7848. if (fp1)
  7849. {
  7850. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7851. // file exists
  7852. fclose(fp1);
  7853. }
  7854. else
  7855. {
  7856. // file doesn't exist
  7857. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7858. }
  7859. }
  7860. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7861. {
  7862. mtrace();
  7863. int result = FAIL;
  7864. time_t CurrentTime;
  7865. struct tm *tm;
  7866. pthread_t th_Status;
  7867. CurrentTime = time(NULL);
  7868. tm = localtime(&CurrentTime);
  7869. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  7870. 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);
  7871. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7872. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7873. return result;
  7874. }
  7875. void* GetDiagnosticsProcess(void* data)
  7876. {
  7877. pthread_detach(pthread_self());
  7878. mtrace();
  7879. int retriesInt=0, retryIntervalInt=0;
  7880. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7881. 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};
  7882. int port=0;
  7883. int isSuccess = FALSE;
  7884. char cmdBuf[2048];
  7885. struct tm *tmNow;
  7886. time_t CurrentTime;
  7887. struct tm tmStart;
  7888. struct tm tmStop;
  7889. CurrentTime = time(NULL);
  7890. tmNow=localtime(&CurrentTime);
  7891. uint16_t targetYear, targetMonth;
  7892. json_object *GetDiagnostics;
  7893. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7894. GetDiagnostics = json_tokener_parse(data);
  7895. if(!is_error(GetDiagnostics))
  7896. {
  7897. // Required data
  7898. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7899. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7900. // Optional data
  7901. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7902. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7903. else
  7904. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7905. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7906. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7907. else
  7908. retryIntervalInt = 30;
  7909. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7910. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7911. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7912. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7913. }
  7914. json_object_put(GetDiagnostics);
  7915. // Pack log to compress file
  7916. 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) &&
  7917. (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))
  7918. {
  7919. // Pack system log
  7920. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7921. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  7922. targetYear = tmStart.tm_year;
  7923. targetMonth = tmStart.tm_mon;
  7924. do
  7925. {
  7926. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7927. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7928. if(targetMonth+1>=13)
  7929. {
  7930. targetYear += 1;
  7931. targetMonth = 1;
  7932. }
  7933. else
  7934. {
  7935. targetMonth += 1;
  7936. }
  7937. }while((targetYear < (tmNow->tm_year+1900)) ||
  7938. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7939. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  7940. system(cmdBuf);
  7941. // Pack charging & event log
  7942. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  7943. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  7944. targetYear = tmStart.tm_year;
  7945. targetMonth = tmStart.tm_mon;
  7946. do
  7947. {
  7948. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  7949. if(targetMonth+1>=13)
  7950. {
  7951. targetYear += 1;
  7952. targetMonth = 1;
  7953. }
  7954. else
  7955. {
  7956. targetMonth += 1;
  7957. }
  7958. }while((targetYear < (tmNow->tm_year+1900)) ||
  7959. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  7960. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  7961. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  7962. system(cmdBuf);
  7963. // Combine log file
  7964. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  7965. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  7966. }
  7967. else
  7968. {
  7969. system("exec /root/logPackTools 'log' 6");
  7970. }
  7971. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  7972. system(cmdBuf);
  7973. checkUploadLog();
  7974. //****************location*******************/
  7975. if(strcmp(locationstr,"")==0)
  7976. {
  7977. DEBUG_INFO("location is <Empty>!\n");
  7978. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7979. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  7980. goto end;
  7981. }
  7982. memset(protocol, 0, ARRAY_SIZE(protocol));
  7983. memset(user, 0, ARRAY_SIZE(user) );
  7984. memset(password, 0, ARRAY_SIZE(password));
  7985. memset(host, 0, ARRAY_SIZE(host));
  7986. memset(path, 0, ARRAY_SIZE(path));
  7987. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  7988. memset(host1, 0, ARRAY_SIZE(host1));
  7989. memset(path1, 0, ARRAY_SIZE(path1));
  7990. /*location: ftp://user:password@host:port/path*/
  7991. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  7992. if((access(fnamePlusPath,F_OK))!=-1)
  7993. {
  7994. DEBUG_INFO("fnamePlusPath exist.\n");
  7995. }
  7996. else
  7997. {
  7998. DEBUG_INFO("fnamePlusPath not exist!\n");
  7999. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8000. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8001. goto end;
  8002. }
  8003. if(strchr(locationstr,'@')==NULL)
  8004. {
  8005. sscanf(locationstr,
  8006. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8007. protocol, host, &port, path);
  8008. strcpy(user,"anonymous");
  8009. strcpy(password,"");
  8010. }
  8011. else
  8012. {
  8013. //DEBUG_INFO("pch=%s\n", pch);
  8014. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8015. protocol, user, password, host, &port, path);
  8016. }
  8017. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  8018. {
  8019. DEBUG_INFO("protocol is not ftp/http ! \n");
  8020. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8021. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8022. goto end;
  8023. }
  8024. if(strncmp(locationstr,"http", 4) == 0)
  8025. {
  8026. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  8027. sprintf(ftppath,"/%s", path);
  8028. do
  8029. {
  8030. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8031. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8032. sleep(3);
  8033. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  8034. if(!isSuccess)
  8035. {
  8036. DEBUG_INFO("Diagnostics fail.\n");
  8037. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8038. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8039. sleep(retryIntervalInt);
  8040. }
  8041. else
  8042. {
  8043. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8044. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8045. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8046. }
  8047. retriesInt--;
  8048. }while((isSuccess == 0)&&(retriesInt >= 0));
  8049. }
  8050. else
  8051. {
  8052. sscanf(host,"%[^/]%s",host1, path1);
  8053. if(strlen(path) > 0)
  8054. sprintf(ftppath,"/%s", path);
  8055. else
  8056. sprintf(ftppath,"/%s", path1);
  8057. int ftppathlen=strlen(ftppath);
  8058. int i=1;
  8059. char filenametemp[50];
  8060. while(i < ftppathlen)
  8061. {
  8062. int len=ftppathlen-i;
  8063. if(ftppath[len]== 47) // '/' ascll code: 47
  8064. {
  8065. DEBUG_INFO("find '/' all right\n");
  8066. break;
  8067. }
  8068. i=i+1;
  8069. }
  8070. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  8071. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8072. filenametemp[i+1] = 0;
  8073. if(port == 0)
  8074. port = 21;
  8075. do
  8076. {
  8077. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8078. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8079. sleep(3);
  8080. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  8081. if(!isSuccess)
  8082. {
  8083. DEBUG_INFO("Diagnostics fail.\n");
  8084. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8085. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8086. sleep(retryIntervalInt);
  8087. }
  8088. else
  8089. {
  8090. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8091. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8092. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8093. }
  8094. retriesInt--;
  8095. }while((!isSuccess)&&(retriesInt >= 0));
  8096. }
  8097. end:
  8098. system("rm -f /mnt/*");
  8099. sleep(5);
  8100. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8101. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8102. pthread_exit(NULL);
  8103. }
  8104. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  8105. {
  8106. mtrace();
  8107. int result = FAIL;
  8108. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  8109. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  8110. {
  8111. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  8112. localversion = -1;
  8113. }
  8114. else
  8115. {
  8116. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  8117. OCPP_getListVerion();
  8118. }
  8119. //from db.OCPP_getListVerion
  8120. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  8121. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  8122. sendGetLocalListVersionConfirmation(uuid,"");
  8123. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  8124. return result;
  8125. }
  8126. int handleRemoteStartRequest(char *uuid, char *payload)
  8127. {
  8128. mtrace();
  8129. int result = FAIL;
  8130. int connectorIdInt=0;
  8131. int tempIndex = 0;
  8132. int connectorIdIsNULL, chargingProfileIsNULL;
  8133. char comfirmstr[20]={0};
  8134. char cmdBuf[512];
  8135. json_object *RemoteStartTransaction;
  8136. FILE *fp;
  8137. DEBUG_INFO("handleRemoteStartRequest ...\n");
  8138. if(server_pending == TRUE)
  8139. {
  8140. return 0;
  8141. }
  8142. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  8143. RemoteStartTransaction = json_tokener_parse(payload);
  8144. if(!is_error(RemoteStartTransaction))
  8145. {
  8146. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  8147. {
  8148. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  8149. if(connectorIdInt <= gunTotalNumber)
  8150. {
  8151. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  8152. // Required data
  8153. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  8154. // Optional data
  8155. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  8156. {
  8157. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  8158. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  8159. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  8160. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  8161. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  8162. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  8163. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  8164. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  8165. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  8166. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  8167. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  8168. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  8169. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  8170. {
  8171. 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")));
  8172. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  8173. 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"));
  8174. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  8175. 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"));
  8176. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  8177. 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")));
  8178. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8179. {
  8180. 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++)
  8181. {
  8182. 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"));
  8183. 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"));
  8184. 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)
  8185. 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"));
  8186. }
  8187. }
  8188. }
  8189. }
  8190. else
  8191. chargingProfileIsNULL = TRUE;
  8192. }
  8193. }
  8194. else
  8195. connectorIdIsNULL = TRUE;
  8196. }
  8197. else
  8198. connectorIdIsNULL = TRUE;
  8199. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8200. {
  8201. DEBUG_WARN("Connector id is NULL\n.");
  8202. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8203. goto end;
  8204. }
  8205. /*
  8206. enum _SYSTEM_STATUS
  8207. {
  8208. S_BOOTING = 0,
  8209. S_IDLE, = 1
  8210. S_AUTHORIZING, = 2
  8211. S_REASSIGN_CHECK, = 3
  8212. S_REASSIGN, = 4
  8213. S_PRECHARGE, = 5
  8214. S_PREPARING_FOR_EV, = 6
  8215. S_PREPARING_FOR_EVSE, = 7
  8216. S_CHARGING, = 8
  8217. S_TERMINATING, = 9
  8218. S_COMPLETE, = 10
  8219. S_ALARM, = 11
  8220. S_FAULT = 12
  8221. }
  8222. */
  8223. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8224. {
  8225. //check Transaction active
  8226. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8227. {
  8228. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8229. {
  8230. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8231. }
  8232. else
  8233. {
  8234. tempIndex = connectorIdInt -1;
  8235. }
  8236. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8237. {
  8238. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8239. {
  8240. 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))
  8241. {
  8242. //Reserved
  8243. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8244. }
  8245. 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))
  8246. {
  8247. //Reserved
  8248. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8249. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8250. goto end;
  8251. }
  8252. else
  8253. {
  8254. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8255. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8256. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8257. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8258. {
  8259. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8260. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8261. goto end;
  8262. }
  8263. }//END FOR ELSE
  8264. }
  8265. }// END FOR CHAdeMO_QUANTITY
  8266. }
  8267. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8268. {
  8269. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8270. {
  8271. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8272. }
  8273. else
  8274. {
  8275. tempIndex = connectorIdInt -1;
  8276. }
  8277. for (int index = 0; index < CCS_QUANTITY; index++)
  8278. {
  8279. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8280. {
  8281. 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))
  8282. {
  8283. //Reserved
  8284. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8285. }
  8286. 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))
  8287. {
  8288. //Reserved
  8289. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8290. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8291. goto end;
  8292. }
  8293. else
  8294. {
  8295. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8296. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8297. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8298. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8299. {
  8300. DEBUG_WARN("CCS connector not allow start\n.");
  8301. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8302. goto end;
  8303. }
  8304. }// END FOR ELSE
  8305. }
  8306. }// END FOR CCS_QUANTITY
  8307. }
  8308. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8309. {
  8310. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8311. {
  8312. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8313. }
  8314. else
  8315. {
  8316. tempIndex = connectorIdInt -1;
  8317. }
  8318. for (int index = 0; index < GB_QUANTITY; index++)
  8319. {
  8320. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8321. {
  8322. 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))
  8323. {
  8324. //Reserved
  8325. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8326. }
  8327. 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))
  8328. {
  8329. //Reserved
  8330. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8331. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8332. goto end;
  8333. }
  8334. else
  8335. {
  8336. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8337. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8338. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8339. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8340. {
  8341. DEBUG_WARN("GB connector not allow start\n.");
  8342. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8343. goto end;
  8344. }
  8345. }// END FOR ELSE
  8346. }
  8347. } // END FOR GB_QUANTITY
  8348. }
  8349. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8350. {
  8351. tempIndex = connectorIdInt -1;
  8352. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8353. {
  8354. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  8355. {
  8356. 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))
  8357. {
  8358. //Reserved
  8359. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8360. }
  8361. 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))
  8362. {
  8363. //Reserved
  8364. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8365. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8366. goto end;
  8367. }
  8368. else
  8369. {
  8370. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8371. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8372. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8373. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8374. {
  8375. DEBUG_WARN("GB connector not allow start\n.");
  8376. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8377. goto end;
  8378. }
  8379. }// END FOR ELSE
  8380. }
  8381. } // END FOR GB_QUANTITY
  8382. }
  8383. else
  8384. {
  8385. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8386. {
  8387. tempIndex = 2;
  8388. }
  8389. else
  8390. {
  8391. tempIndex = connectorIdInt -1;
  8392. }
  8393. for (int index = 0; index < AC_QUANTITY; index++)
  8394. {
  8395. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  8396. {
  8397. 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))
  8398. {
  8399. //Reserved
  8400. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8401. }
  8402. 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))
  8403. {
  8404. //Reserved
  8405. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8406. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8407. goto end;
  8408. }
  8409. else
  8410. {
  8411. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8412. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8413. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8414. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8415. {
  8416. DEBUG_WARN("AC connector not allow start\n.");
  8417. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8418. goto end;
  8419. }
  8420. }//END FOR ELSE
  8421. }
  8422. }// END FOR AC_QUANTITY
  8423. }
  8424. if(chargingProfileIsNULL == FALSE)
  8425. {
  8426. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8427. {
  8428. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8429. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8430. //memset idTag
  8431. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8432. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8433. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8434. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8435. // Save profile to file
  8436. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8437. system(cmdBuf);
  8438. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8439. fp = fopen(cmdBuf, "w");
  8440. 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));
  8441. fclose(fp);
  8442. }
  8443. else
  8444. {
  8445. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  8446. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8447. }
  8448. }
  8449. else
  8450. {
  8451. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8452. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8453. //memset idTag
  8454. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8455. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8456. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8457. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8458. }
  8459. }
  8460. else
  8461. {
  8462. DEBUG_WARN("Connector id over\n.");
  8463. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8464. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8465. }
  8466. end:
  8467. json_object_put(RemoteStartTransaction);
  8468. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  8469. {
  8470. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  8471. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8472. }
  8473. //OCPP send RemoteStartConfirmation by first.
  8474. sendRemoteStartConfirmation(uuid, comfirmstr);
  8475. return result;
  8476. }
  8477. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  8478. {
  8479. mtrace();
  8480. int result = FAIL;
  8481. int match = FALSE;
  8482. int GunNO = 0;
  8483. int tempIndex = 0;
  8484. int transactionIdInt=0;
  8485. int transactionIdIsNULL= TRUE;
  8486. char comfirmstr[20];
  8487. json_object *RemoteStopTransaction;
  8488. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  8489. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  8490. if(server_pending == TRUE)
  8491. {
  8492. return 0;
  8493. }
  8494. RemoteStopTransaction = json_tokener_parse(payload);
  8495. if(!is_error(RemoteStopTransaction))
  8496. {
  8497. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  8498. {
  8499. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  8500. transactionIdIsNULL = FALSE;
  8501. }
  8502. }
  8503. json_object_put(RemoteStopTransaction);
  8504. if(transactionIdIsNULL == FALSE)
  8505. {
  8506. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  8507. {
  8508. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  8509. {
  8510. //check Transaction active
  8511. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8512. {
  8513. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8514. {
  8515. tempIndex = ((gun_index==2) ? 1: 0);
  8516. }
  8517. else
  8518. {
  8519. tempIndex = gun_index;
  8520. }
  8521. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8522. {
  8523. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8524. {
  8525. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8526. {
  8527. match = TRUE;
  8528. GunNO = gun_index;
  8529. }
  8530. }
  8531. }// END FOR CHAdeMO_QUANTITY
  8532. }
  8533. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8534. {
  8535. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8536. {
  8537. tempIndex = ((gun_index==2) ? 1: 0);
  8538. }
  8539. else
  8540. {
  8541. tempIndex = gun_index;
  8542. }
  8543. for (int index = 0; index < CCS_QUANTITY; index++)
  8544. {
  8545. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8546. {
  8547. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8548. {
  8549. match = TRUE;
  8550. GunNO = gun_index;
  8551. }
  8552. }
  8553. }// END FOR CCS_QUANTITY
  8554. }
  8555. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8556. {
  8557. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8558. {
  8559. tempIndex = ((gun_index==2) ? 1: 0);
  8560. }
  8561. else
  8562. {
  8563. tempIndex = gun_index;
  8564. }
  8565. for (int index = 0; index < GB_QUANTITY; index++)
  8566. {
  8567. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8568. {
  8569. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8570. {
  8571. match = TRUE;
  8572. GunNO = gun_index;
  8573. }
  8574. }
  8575. }// END FOR GB_QUANTITY
  8576. }
  8577. else if(gunType[gun_index] == GUN_TYPE_DO)
  8578. {
  8579. tempIndex = gun_index;
  8580. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8581. {
  8582. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8583. {
  8584. 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
  8585. {
  8586. match = TRUE;
  8587. GunNO = gun_index;
  8588. }
  8589. }
  8590. }// END FOR GB_QUANTITY
  8591. }
  8592. else
  8593. {
  8594. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8595. {
  8596. tempIndex = 2;
  8597. }
  8598. else
  8599. {
  8600. tempIndex = gun_index;
  8601. }
  8602. for (int index = 0; index < AC_QUANTITY; index++)
  8603. {
  8604. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8605. {
  8606. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8607. {
  8608. match = TRUE;
  8609. GunNO = gun_index;
  8610. }
  8611. }
  8612. }// END FOR CHAdeMO_QUANTITY
  8613. } // END FOR AC ELSE
  8614. }// CHECK IF ResponseTransactionId == transactionIdInt
  8615. }//END FOR
  8616. if( match == TRUE)
  8617. {
  8618. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8619. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8620. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8621. }
  8622. else
  8623. {
  8624. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8625. }
  8626. }
  8627. else
  8628. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8629. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8630. return result;
  8631. }
  8632. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8633. {
  8634. mtrace();
  8635. int result = FAIL;
  8636. int connectorIdInt=0, reservationIdInt=0;
  8637. int tempIndex = 0;
  8638. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8639. char comfirmstr[20]={0};
  8640. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8641. int c = 0;
  8642. char *loc;
  8643. //char *ptr;
  8644. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8645. strcpy(sstrtemp, stringtrimspace(payload));
  8646. //***(1)connectorId ****/
  8647. c=0;
  8648. loc = strstr(sstrtemp, "connectorId");
  8649. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8650. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8651. {
  8652. sstr[c] = loc[strlen("connectorId")+2+c];
  8653. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8654. c++;
  8655. }
  8656. sstr[c] = '\0';
  8657. connectorIdInt = atoi(sstr);
  8658. //***(2)expiryDate ****/
  8659. loc = strstr(sstrtemp, "expiryDate");
  8660. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8661. c = 0;
  8662. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8663. {
  8664. sstr[c] = loc[3+strlen("expiryDate")+c];
  8665. c++;
  8666. }
  8667. sstr[c] = '\0';
  8668. strcpy(expiryDatestr, sstr);
  8669. //***(3)idTag ****/
  8670. loc = strstr(sstrtemp, "idTag");
  8671. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8672. c = 0;
  8673. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8674. {
  8675. sstr[c] = loc[3+strlen("idTag")+c];
  8676. c++;
  8677. }
  8678. sstr[c] = '\0';
  8679. strcpy(idTagstr, sstr);
  8680. //***(4)parentIdTag ****/
  8681. loc = strstr(sstrtemp, "parentIdTag");
  8682. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8683. c = 0;
  8684. if(loc == NULL)
  8685. {
  8686. strcpy(parentIdTagstr, "");
  8687. }
  8688. else
  8689. {
  8690. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8691. {
  8692. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8693. c++;
  8694. }
  8695. sstr[c] = '\0';
  8696. strcpy(parentIdTagstr, sstr);
  8697. }
  8698. //***(5)reservationId ****/
  8699. c=0;
  8700. loc = strstr(sstrtemp, "reservationId");
  8701. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8702. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8703. {
  8704. sstr[c] = loc[strlen("reservationId")+2+c];
  8705. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8706. c++;
  8707. }
  8708. sstr[c] = '\0';
  8709. reservationIdInt = atoi(sstr);
  8710. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8711. /*
  8712. enum SYSTEM_STATUS
  8713. {
  8714. SYS_MODE_BOOTING = 0,
  8715. SYS_MODE_IDLE = 1,
  8716. SYS_MODE_AUTHORIZING = 2,
  8717. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8718. SYS_MODE_REASSIGN = 4,
  8719. SYS_MODE_PREPARING = 5,
  8720. SYS_MODE_PREPARE_FOR_EV = 6,
  8721. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8722. SYS_MODE_CHARGING = 8,
  8723. SYS_MODE_TERMINATING = 9,
  8724. SYS_MODE_COMPLETE = 10,
  8725. SYS_MODE_ALARM = 11,
  8726. SYS_MODE_FAULT = 12,
  8727. SYS_MODE_RESERVATION = 13,
  8728. SYS_MODE_BOOKING = 14,
  8729. SYS_MODE_MAINTAIN = 15,
  8730. SYS_MODE_DEBUG = 16,
  8731. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8732. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8733. SYS_MODE_UPDATE = 19
  8734. };
  8735. */
  8736. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8737. {
  8738. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8739. goto end;
  8740. }
  8741. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8742. {
  8743. //check Transaction active
  8744. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8745. {
  8746. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8747. {
  8748. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8749. }
  8750. else
  8751. {
  8752. tempIndex = connectorIdInt -1;
  8753. }
  8754. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8755. {
  8756. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8757. {
  8758. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8759. {
  8760. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8761. {
  8762. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8763. {
  8764. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8765. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8766. }
  8767. 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'))
  8768. {
  8769. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8770. }
  8771. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8772. {
  8773. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8774. }
  8775. else
  8776. {
  8777. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8778. }
  8779. }
  8780. 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
  8781. {
  8782. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8783. }
  8784. }
  8785. else
  8786. {
  8787. //replace reservation
  8788. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8789. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8790. }
  8791. }
  8792. } // END FOR CHAdeMO_QUANTITY
  8793. }
  8794. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8795. {
  8796. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8797. {
  8798. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8799. }
  8800. else
  8801. {
  8802. tempIndex = connectorIdInt -1;
  8803. }
  8804. for (int index = 0; index < CCS_QUANTITY; index++)
  8805. {
  8806. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8807. {
  8808. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8809. {
  8810. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8811. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8812. {
  8813. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8814. {
  8815. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8816. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8817. }
  8818. 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'))
  8819. {
  8820. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8821. }
  8822. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8823. {
  8824. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8825. }
  8826. else
  8827. {
  8828. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8829. }
  8830. }
  8831. 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
  8832. {
  8833. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8834. }
  8835. }
  8836. else
  8837. {
  8838. //replace reservation
  8839. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8840. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8841. }
  8842. }
  8843. } // END FOR CCS_QUANTITY
  8844. }
  8845. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8846. {
  8847. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8848. {
  8849. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8850. }
  8851. else
  8852. {
  8853. tempIndex = connectorIdInt -1;
  8854. }
  8855. for (int index = 0; index < GB_QUANTITY; index++)
  8856. {
  8857. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8858. {
  8859. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8860. {
  8861. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8862. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8863. {
  8864. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8865. {
  8866. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8867. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8868. }
  8869. 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'))
  8870. {
  8871. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8872. }
  8873. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8874. {
  8875. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8876. }
  8877. else
  8878. {
  8879. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8880. }
  8881. }
  8882. 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
  8883. {
  8884. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8885. }
  8886. }
  8887. else
  8888. {
  8889. //replace reservation
  8890. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8891. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8892. }
  8893. }
  8894. }// END FOR GB_QUANTITY
  8895. }
  8896. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8897. {
  8898. tempIndex = connectorIdInt -1;
  8899. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8900. {
  8901. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8902. {
  8903. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8904. {
  8905. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8906. 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
  8907. {
  8908. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8909. {
  8910. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8911. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8912. }
  8913. 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'))
  8914. {
  8915. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8916. }
  8917. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8918. {
  8919. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8920. }
  8921. else
  8922. {
  8923. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8924. }
  8925. }
  8926. 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
  8927. {
  8928. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8929. }
  8930. }
  8931. else
  8932. {
  8933. //replace reservation
  8934. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8935. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8936. }
  8937. }
  8938. }// END FOR GB_QUANTITY
  8939. }
  8940. else
  8941. {
  8942. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8943. {
  8944. tempIndex = 2;
  8945. }
  8946. else
  8947. {
  8948. tempIndex = (connectorIdInt -1);
  8949. }
  8950. for (int index = 0; index < AC_QUANTITY; index++)
  8951. {
  8952. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8953. {
  8954. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8955. {
  8956. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8957. {
  8958. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8959. {
  8960. 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))
  8961. {
  8962. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8963. }
  8964. else
  8965. {
  8966. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8967. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8968. }
  8969. }
  8970. 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'))
  8971. {
  8972. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8973. }
  8974. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8975. {
  8976. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8977. }
  8978. else
  8979. {
  8980. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8981. }
  8982. }
  8983. 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
  8984. {
  8985. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8986. }
  8987. }
  8988. else
  8989. {
  8990. //replace reservation
  8991. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8992. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8993. }
  8994. }
  8995. } // END FOR AC_QUANTITY
  8996. }
  8997. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8998. }
  8999. else if(connectorIdInt == 0)
  9000. {
  9001. //check Transaction active
  9002. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9003. {
  9004. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9005. {
  9006. 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'))
  9007. {
  9008. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9009. goto end;
  9010. }
  9011. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9012. {
  9013. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9014. goto end;
  9015. }
  9016. 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
  9017. {
  9018. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9019. goto end;
  9020. }
  9021. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9022. {
  9023. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9024. goto end;
  9025. }
  9026. }
  9027. }// END FOR CHAdeMO_QUANTITY
  9028. for (int index = 0; index < CCS_QUANTITY; index++)
  9029. {
  9030. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9031. {
  9032. 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'))
  9033. {
  9034. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9035. goto end;
  9036. }
  9037. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  9038. {
  9039. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9040. goto end;
  9041. }
  9042. 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
  9043. {
  9044. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9045. goto end;
  9046. }
  9047. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9048. {
  9049. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9050. goto end;
  9051. }
  9052. }
  9053. } // END FOR CCS_QUANTITY
  9054. for (int index = 0; index < GB_QUANTITY; index++)
  9055. {
  9056. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9057. {
  9058. 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'))
  9059. {
  9060. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9061. goto end;
  9062. }
  9063. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9064. {
  9065. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9066. goto end;
  9067. }
  9068. 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
  9069. {
  9070. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9071. goto end;
  9072. }
  9073. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9074. {
  9075. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9076. goto end;
  9077. }
  9078. }
  9079. } // END FOR GB_QUANTITY
  9080. for (int index = 0; index < AC_QUANTITY; index++)
  9081. {
  9082. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9083. {
  9084. 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'))
  9085. {
  9086. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9087. goto end;
  9088. }
  9089. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9090. {
  9091. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9092. goto end;
  9093. }
  9094. 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
  9095. {
  9096. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9097. goto end;
  9098. }
  9099. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9100. {
  9101. 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))
  9102. {
  9103. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9104. goto end;
  9105. }
  9106. }
  9107. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9108. {
  9109. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9110. goto end;
  9111. }
  9112. }
  9113. }// END FOR AC_QUANTITY
  9114. //The connectorId is 0
  9115. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  9116. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9117. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  9118. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  9119. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  9120. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  9121. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  9122. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  9123. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  9124. result = TRUE;
  9125. return result;
  9126. }
  9127. else
  9128. {
  9129. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9130. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9131. }
  9132. if(strcmp(comfirmstr,"Accepted") == 0)
  9133. {
  9134. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  9135. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  9136. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  9137. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  9138. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  9139. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  9140. result = TRUE;
  9141. return result;
  9142. }
  9143. end:
  9144. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  9145. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  9146. return result;
  9147. }
  9148. int handleResetRequest(char *uuid, char *payload)
  9149. {
  9150. mtrace();
  9151. int result = FAIL;
  9152. char sstr[10]={0},sstrtemp[30]={ 0 };
  9153. char typestr[10]={0};
  9154. char comfirmstr[20]={0};
  9155. int c = 0;
  9156. char *loc;
  9157. DEBUG_INFO("handleResetRequest...\n");
  9158. strcpy(sstrtemp, stringtrimspace(payload));
  9159. loc = strstr(sstrtemp, "type");
  9160. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9161. c = 0;
  9162. while (loc[3+strlen("type")+c] != '\"')
  9163. {
  9164. sstr[c] = loc[3+strlen("type")+c];
  9165. c++;
  9166. }
  9167. sstr[c] = '\0';
  9168. strcpy(typestr,sstr);
  9169. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  9170. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  9171. {
  9172. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  9173. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  9174. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  9175. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9176. }
  9177. else
  9178. {
  9179. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  9180. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  9181. result = PASS;
  9182. }
  9183. sendResetConfirmation(uuid, comfirmstr);
  9184. return result;
  9185. }
  9186. int handleSendLocalListRequest(char *uuid, char *payload)
  9187. {
  9188. mtrace();
  9189. int result = FAIL;
  9190. int listVersionInt;
  9191. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  9192. char listsearch[]="listVersion";
  9193. char updateTypesearch[]="updateType";
  9194. char localAuthorizationListsearch[]="localAuthorizationList";
  9195. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  9196. char CardList[500][160]={0};
  9197. char updateTypestr[15]={0};
  9198. char idTagstr[20]={0};
  9199. char parentIdTag[20]={0};
  9200. char expiryDate[30]={0};
  9201. char idTagstatus[16]={0};
  9202. int c = 0;
  9203. int i = 0;
  9204. char *delim1 = "}";
  9205. char * pch;
  9206. char *loc;
  9207. //char *ptr;
  9208. char comfirmstr[20];
  9209. //int n_localAuthorizations = 0;
  9210. int checkState_Faulted = FALSE;
  9211. DEBUG_INFO("handleSendLocalListRequest...\n");
  9212. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9213. {
  9214. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9215. goto end;
  9216. }
  9217. //check Charge Point state
  9218. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9219. {
  9220. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9221. {
  9222. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9223. }
  9224. }
  9225. for (int index = 0; index < CCS_QUANTITY; index++)
  9226. {
  9227. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9228. {
  9229. checkState_Faulted = TRUE; //OCPP Status
  9230. }
  9231. }
  9232. for (int index = 0; index < GB_QUANTITY; index++)
  9233. {
  9234. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9235. {
  9236. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9237. }
  9238. }
  9239. //check Charge Point state
  9240. for (int index = 0; index < AC_QUANTITY; index++)
  9241. {
  9242. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9243. {
  9244. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9245. }
  9246. }
  9247. if(checkState_Faulted == TRUE)
  9248. {
  9249. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9250. goto end;
  9251. }
  9252. //Filter payload space
  9253. strcpy(sstrtemp, stringtrimspace(payload));
  9254. //listVersion
  9255. c = 0;
  9256. loc = strstr(sstrtemp, listsearch);
  9257. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  9258. {
  9259. sstr[c] = loc[strlen("listVersion")+2+c];
  9260. c++;
  9261. }
  9262. sstr[c] = '\0';
  9263. listVersionInt = atoi(sstr);
  9264. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9265. //updateType
  9266. loc = strstr(sstrtemp, updateTypesearch);
  9267. c = 0;
  9268. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  9269. {
  9270. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  9271. c++;
  9272. }
  9273. sstr[c] = '\0';
  9274. strcpy(updateTypestr, sstr);
  9275. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  9276. //localAuthorizationList
  9277. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9278. loc = strstr(sstrtemp, localAuthorizationListsearch);
  9279. if(loc != NULL) // localAuthorizationList is not NULL
  9280. {
  9281. //Check UpdateType
  9282. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9283. {
  9284. //Local list full update
  9285. printf("Local list full update.\n");
  9286. OCPP_getListVerion();
  9287. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9288. {
  9289. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9290. goto end;
  9291. }
  9292. OCPP_cleanLocalList();
  9293. }
  9294. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9295. {
  9296. //Local list different update
  9297. printf("Local list different update.\n");
  9298. OCPP_getListVerion();
  9299. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9300. {
  9301. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9302. goto end;
  9303. }
  9304. }
  9305. else
  9306. {
  9307. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9308. goto end;
  9309. }
  9310. c = 0;
  9311. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  9312. {
  9313. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  9314. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9315. c++;
  9316. }
  9317. sstr[c] = '\0';
  9318. //DEBUG_INFO("sstr=%s\n", sstr);
  9319. //parsing strings to words
  9320. i = 0;
  9321. pch = strtok(sstr,delim1);
  9322. while (pch != NULL)
  9323. {
  9324. strcpy(CardList[i], pch);
  9325. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  9326. pch = strtok (NULL, delim1);
  9327. i = i + 1;
  9328. }
  9329. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  9330. //local Authorizations List Numbers
  9331. //n_localAuthorizations = i;
  9332. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  9333. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9334. c= 0;
  9335. while(c < i) // i is CardList Number
  9336. {
  9337. //Search "IdToken"
  9338. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9339. loc = strstr(CardList[c], "idTag");
  9340. int j = 0;
  9341. while (loc[3+strlen("idTag")+j] != '\"')
  9342. {
  9343. sstr[j] = loc[3+strlen("idTag")+j];
  9344. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9345. j++;
  9346. }
  9347. sstr[j] = '\0';
  9348. strcpy(idTagstr, sstr);
  9349. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  9350. //Search "expiryDate"
  9351. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9352. loc = strstr(CardList[c], "expiryDate");
  9353. j = 0;
  9354. if(loc != NULL)
  9355. {
  9356. while (loc[3+strlen("expiryDate")+j] != '\"')
  9357. {
  9358. sstr[j] = loc[3+strlen("expiryDate")+j];
  9359. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9360. j++;
  9361. }
  9362. sstr[j] = '\0';
  9363. strcpy(expiryDate, sstr);
  9364. }
  9365. else
  9366. {
  9367. strcpy(expiryDate, "");
  9368. }
  9369. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  9370. //Search "parentIdTag"
  9371. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9372. loc = strstr(CardList[c], "parentIdTag");
  9373. j = 0;
  9374. if(loc != NULL)
  9375. {
  9376. while (loc[3+strlen("parentIdTag")+j] != '\"')
  9377. {
  9378. sstr[j] = loc[3+strlen("parentIdTag")+j];
  9379. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9380. j++;
  9381. }
  9382. sstr[j] = '\0';
  9383. strcpy(parentIdTag, sstr);
  9384. }
  9385. else
  9386. {
  9387. strcpy(parentIdTag, "");
  9388. }
  9389. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  9390. //Search "status"
  9391. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9392. loc = strstr(CardList[c], "status");
  9393. j = 0;
  9394. while (loc[3+strlen("status")+j] != '\"')
  9395. {
  9396. sstr[j] = loc[3+strlen("status")+j];
  9397. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9398. j++;
  9399. }
  9400. sstr[j] = '\0';
  9401. strcpy(idTagstatus, sstr);
  9402. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  9403. OCPP_getIdTagFromLocalList(idTagstr);
  9404. //OCPP_getIdTagFromLocalList("test"); For Test
  9405. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  9406. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  9407. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9408. {
  9409. //Local list full update
  9410. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9411. // update list
  9412. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9413. //DEBUG_INFO("Local list full update. 1\n");
  9414. //OCPP_get_TableAuthlocalAllData();
  9415. //DEBUG_INFO("Local list full update. 2\n");
  9416. }
  9417. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9418. {
  9419. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9420. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  9421. }
  9422. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  9423. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  9424. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  9425. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  9426. c++;
  9427. }
  9428. }
  9429. else
  9430. {
  9431. //Check UpdateType
  9432. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9433. {
  9434. //Local list full update
  9435. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  9436. OCPP_cleanLocalList();
  9437. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9438. goto end;
  9439. }
  9440. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9441. {
  9442. //Local list different update
  9443. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  9444. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9445. goto end;
  9446. }
  9447. }
  9448. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9449. end:
  9450. sendSendLocalListConfirmation(uuid, comfirmstr);
  9451. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  9452. return result;
  9453. }
  9454. #define MAX 200
  9455. int handleSetChargingProfileRequest(char *uuid, char *payload)
  9456. {
  9457. mtrace();
  9458. int result = FAIL;
  9459. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  9460. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  9461. char chargingProfilePurposeStr[30]={0};
  9462. char chargingProfileKindStr[16]={0};
  9463. char recurrencyKindStr[10]={0};
  9464. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  9465. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  9466. int chargingSchedulePeriodCount = 0;
  9467. char comfirmstr[20]={0};
  9468. int meet= FALSE;
  9469. FILE *fptr1;
  9470. char filename[MAX]={0};
  9471. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  9472. char rmFileCmd[50]={0};
  9473. char tempchargingProfilePurposeStr[30]={0};
  9474. char word[1600]={0};
  9475. int n_chargingProfile = 0;
  9476. json_object *SetChargingProfile;
  9477. DEBUG_INFO("handleSetChargingProfileRequest\n");
  9478. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  9479. SetChargingProfile = json_tokener_parse(payload);
  9480. if(!is_error(SetChargingProfile))
  9481. {
  9482. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  9483. {
  9484. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  9485. if(connectorIdInt == 0)
  9486. {
  9487. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  9488. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  9489. }
  9490. else
  9491. {
  9492. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  9493. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  9494. }
  9495. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  9496. }
  9497. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  9498. {
  9499. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9500. {
  9501. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9502. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9503. {
  9504. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9505. }
  9506. else
  9507. {
  9508. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9509. }
  9510. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  9511. }
  9512. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9513. {
  9514. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  9515. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9516. {
  9517. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  9518. }
  9519. else
  9520. {
  9521. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  9522. }
  9523. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  9524. }
  9525. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9526. {
  9527. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9528. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9529. {
  9530. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9531. }
  9532. else
  9533. {
  9534. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9535. }
  9536. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  9537. }
  9538. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  9539. {
  9540. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  9541. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9542. {
  9543. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9544. }
  9545. else
  9546. {
  9547. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9548. }
  9549. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9550. }
  9551. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9552. {
  9553. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9554. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9555. {
  9556. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9557. }
  9558. else
  9559. {
  9560. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9561. }
  9562. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9563. }
  9564. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9565. {
  9566. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9567. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9568. {
  9569. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9570. }
  9571. else
  9572. {
  9573. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9574. }
  9575. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9576. }
  9577. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9578. {
  9579. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9580. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9581. {
  9582. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9583. }
  9584. else
  9585. {
  9586. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9587. }
  9588. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9589. }
  9590. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9591. {
  9592. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9593. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9594. {
  9595. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9596. }
  9597. else
  9598. {
  9599. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9600. }
  9601. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9602. }
  9603. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9604. {
  9605. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9606. {
  9607. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9608. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9609. {
  9610. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9611. }
  9612. else
  9613. {
  9614. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9615. }
  9616. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9617. }
  9618. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9619. {
  9620. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9621. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9622. {
  9623. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9624. }
  9625. else
  9626. {
  9627. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9628. }
  9629. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9630. }
  9631. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9632. {
  9633. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9634. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9635. {
  9636. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9637. }
  9638. else
  9639. {
  9640. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9641. }
  9642. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9643. }
  9644. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9645. {
  9646. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9647. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9648. {
  9649. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9650. }
  9651. else
  9652. {
  9653. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9654. }
  9655. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9656. }
  9657. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9658. {
  9659. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9660. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9661. if(chargingSchedulePeriodCount <= 10)
  9662. {
  9663. 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++)
  9664. {
  9665. 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)
  9666. {
  9667. 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"));
  9668. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9669. {
  9670. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9671. }
  9672. else
  9673. {
  9674. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9675. }
  9676. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9677. }
  9678. 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)
  9679. {
  9680. 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"));
  9681. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9682. {
  9683. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9684. }
  9685. else
  9686. {
  9687. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9688. }
  9689. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9690. }
  9691. 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)
  9692. {
  9693. 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"));
  9694. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9695. {
  9696. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9697. }
  9698. else
  9699. {
  9700. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9701. }
  9702. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9703. }
  9704. }
  9705. }
  9706. }
  9707. }
  9708. }
  9709. }
  9710. json_object_put(SetChargingProfile);
  9711. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9712. {
  9713. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9714. goto end;
  9715. }
  9716. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9717. {
  9718. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9719. if(connectorIdInt != 0)
  9720. {
  9721. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9722. goto end;
  9723. }
  9724. strcpy(filename, ChargePointMaxProfile_JSON );
  9725. fptr1 = fopen(filename, "r");
  9726. if (!fptr1)
  9727. {
  9728. //file not exist
  9729. DEBUG_INFO("Unable to open the input file!!\n");
  9730. fptr1 = fopen(filename, "w+");
  9731. }
  9732. else
  9733. {
  9734. //Check Charging Profile Count
  9735. while(fscanf(fptr1, "%s", word) != EOF)
  9736. {
  9737. //DEBUG_INFO("word=%s\n",word);
  9738. if(strstr(word, "chargingProfileId")!= NULL)
  9739. {
  9740. //DEBUG_INFO("test chargingProfileId \n");
  9741. n_chargingProfile = n_chargingProfile + 1;
  9742. //DEBUG_INFO("chargingProfileId Found\n");
  9743. }
  9744. }
  9745. }
  9746. fclose(fptr1);
  9747. }
  9748. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9749. {
  9750. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9751. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9752. {
  9753. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9754. goto end;
  9755. }
  9756. memset(filename, 0, ARRAY_SIZE(filename));
  9757. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9758. fptr1 = fopen(filename, "r");
  9759. if (!fptr1)
  9760. {
  9761. //file not exist
  9762. //DEBUG_INFO("Unable to open the input file!!\n");
  9763. fptr1 = fopen(filename, "w+");
  9764. }
  9765. else
  9766. {
  9767. //Check Charging Profile Count
  9768. while(fscanf(fptr1, "%s", word) != EOF)
  9769. {
  9770. //DEBUG_INFO("word=%s\n",word);
  9771. if(strstr(word, "chargingProfileId")!= NULL)
  9772. {
  9773. //DEBUG_INFO("test chargingProfileId \n");
  9774. n_chargingProfile = n_chargingProfile + 1;
  9775. //DEBUG_INFO("chargingProfileId Found\n");
  9776. }
  9777. }
  9778. }
  9779. fclose(fptr1);
  9780. }
  9781. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9782. {
  9783. //printf("set chargingProfile 1-4\n");
  9784. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9785. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9786. if(connectorIdInt == 0)
  9787. {
  9788. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9789. goto end;
  9790. }
  9791. int tempIndex = 0;
  9792. //check Transaction active
  9793. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9794. {
  9795. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9796. {
  9797. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9798. }
  9799. else
  9800. {
  9801. tempIndex = connectorIdInt -1;
  9802. }
  9803. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9804. {
  9805. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9806. {
  9807. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  9808. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9809. {
  9810. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9811. {
  9812. meet = TRUE;
  9813. break;
  9814. }
  9815. }
  9816. }
  9817. }
  9818. }
  9819. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9820. {
  9821. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9822. {
  9823. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9824. }
  9825. else
  9826. {
  9827. tempIndex = connectorIdInt -1;
  9828. }
  9829. for (int index = 0; index < CCS_QUANTITY; index++)
  9830. {
  9831. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9832. {
  9833. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  9834. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9835. {
  9836. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9837. {
  9838. meet = TRUE;
  9839. break;
  9840. }
  9841. }
  9842. }
  9843. }
  9844. }
  9845. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9846. {
  9847. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9848. {
  9849. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9850. }
  9851. else
  9852. {
  9853. tempIndex = connectorIdInt -1;
  9854. }
  9855. for (int index = 0; index < GB_QUANTITY; index++)
  9856. {
  9857. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9858. {
  9859. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  9860. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9861. {
  9862. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9863. {
  9864. meet = TRUE;
  9865. break;
  9866. }
  9867. }
  9868. }
  9869. }
  9870. }
  9871. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9872. {
  9873. tempIndex = connectorIdInt -1;
  9874. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9875. {
  9876. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9877. {
  9878. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  9879. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9880. {
  9881. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9882. {
  9883. meet = TRUE;
  9884. break;
  9885. }
  9886. }
  9887. }
  9888. }
  9889. }
  9890. else
  9891. {
  9892. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9893. {
  9894. tempIndex = 2;
  9895. }
  9896. else
  9897. {
  9898. tempIndex = (connectorIdInt -1);
  9899. }
  9900. for (int index = 0; index < AC_QUANTITY; index++)
  9901. {
  9902. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9903. {
  9904. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9905. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9906. {
  9907. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9908. {
  9909. meet = TRUE;
  9910. break;
  9911. }
  9912. }
  9913. }
  9914. }
  9915. }
  9916. //check Transaction active
  9917. if(meet == FALSE)
  9918. {
  9919. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9920. goto end;
  9921. }
  9922. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9923. {
  9924. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9925. goto end;
  9926. }
  9927. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9928. fptr1 = fopen(filename, "r");
  9929. if (!fptr1)
  9930. {
  9931. //file not exist
  9932. DEBUG_INFO("Unable to open the input file!!\n");
  9933. fptr1 = fopen(filename, "w+");
  9934. }
  9935. else
  9936. {
  9937. //Check Charging Profile Count
  9938. while(fscanf(fptr1, "%s", word) != EOF)
  9939. {
  9940. //DEBUG_INFO("word=%s\n",word);
  9941. if(strstr(word, "chargingProfileId")!= NULL)
  9942. {
  9943. //DEBUG_INFO("test chargingProfileId \n");
  9944. n_chargingProfile = n_chargingProfile + 1;
  9945. //DEBUG_INFO("chargingProfileId Found\n");
  9946. }
  9947. }
  9948. }
  9949. fclose(fptr1);
  9950. }
  9951. // Check ChargeProfileMaxStackLevel
  9952. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9953. {
  9954. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9955. goto end;
  9956. }
  9957. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9958. {
  9959. int i = 0;
  9960. char fnametemp[200]={0};
  9961. n_chargingProfile = 0;
  9962. //Check ChargePointMaxProfile.json exit
  9963. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9964. {
  9965. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  9966. //Check Charging Profile Count
  9967. while(fscanf(fptr1, "%s", word) != EOF)
  9968. {
  9969. //DEBUG_INFO("word=%s\n",word);
  9970. if(strstr(word, "chargingProfileId")!= NULL)
  9971. {
  9972. //DEBUG_INFO("test chargingProfileId \n");
  9973. n_chargingProfile = n_chargingProfile + 1;
  9974. i = i + 1;
  9975. //DEBUG_INFO("chargingProfileId Found\n");
  9976. }
  9977. memset(word, 0, ARRAY_SIZE(word));
  9978. }
  9979. fclose(fptr1);
  9980. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9981. }
  9982. //Check TxDefaultProfile_0.json exit
  9983. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9984. {
  9985. i = 0;
  9986. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9987. //Check Charging Profile Count
  9988. while(fscanf(fptr1, "%s", word) != EOF)
  9989. {
  9990. //DEBUG_INFO("word=%s\n",word);
  9991. if(strstr(word, "chargingProfileId")!= NULL)
  9992. {
  9993. //DEBUG_INFO("test chargingProfileId \n");
  9994. n_chargingProfile = n_chargingProfile + 1;
  9995. i = i + 1;
  9996. //DEBUG_INFO("chargingProfileId Found\n");
  9997. }
  9998. memset(word, 0, ARRAY_SIZE(word));
  9999. }
  10000. fclose(fptr1);
  10001. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  10002. }
  10003. //Check TxDefaultProfile_%d.json
  10004. for(int j=1; j <= gunTotalNumber; j++)
  10005. {
  10006. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10007. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  10008. if((access(fnametemp,F_OK))!=-1)
  10009. {
  10010. i = 0;
  10011. fptr1 = fopen(fnametemp, "r");
  10012. //Check Charging Profile Count
  10013. while(fscanf(fptr1, "%s", word) != EOF)
  10014. {
  10015. //DEBUG_INFO("word=%s\n",word);
  10016. if(strstr(word, "chargingProfileId")!= NULL)
  10017. {
  10018. //DEBUG_INFO("test chargingProfileId \n");
  10019. n_chargingProfile = n_chargingProfile + 1;
  10020. i = i + 1;
  10021. //DEBUG_INFO("chargingProfileId Found\n");
  10022. }
  10023. memset(word, 0, ARRAY_SIZE(word));
  10024. }
  10025. fclose(fptr1);
  10026. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10027. }
  10028. }
  10029. //Check TxProfile_%d.json
  10030. for(int j=1; j <= gunTotalNumber; j++)
  10031. {
  10032. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10033. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  10034. if((access(fnametemp,F_OK))!=-1)
  10035. {
  10036. i = 0;
  10037. fptr1 = fopen(fnametemp, "r");
  10038. //Check Charging Profile Count
  10039. while(fscanf(fptr1, "%s", word) != EOF)
  10040. {
  10041. //DEBUG_INFO("word=%s\n",word);
  10042. if(strstr(word, "chargingProfileId")!= NULL)
  10043. {
  10044. //DEBUG_INFO("test chargingProfileId \n");
  10045. n_chargingProfile = n_chargingProfile + 1;
  10046. i = i + 1;
  10047. //DEBUG_INFO("chargingProfileId Found\n");
  10048. }
  10049. memset(word, 0, ARRAY_SIZE(word));
  10050. }
  10051. fclose(fptr1);
  10052. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10053. }
  10054. }
  10055. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10056. {
  10057. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10058. goto end;
  10059. }
  10060. }
  10061. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10062. //**********************************Write to File********************************************************/
  10063. FILE *infile;
  10064. FILE *outfile;
  10065. infile = fopen (filename, "r");
  10066. outfile = fopen (tempfile, "w");
  10067. int d =0;
  10068. d = fgetc(infile);
  10069. rewind(infile);
  10070. if(d == EOF)
  10071. {
  10072. // Profile is empty
  10073. fprintf(outfile,"%s\n",payload);
  10074. fclose(infile);
  10075. fclose(outfile);
  10076. sprintf(rmFileCmd,"rm -f %s",filename);
  10077. system(rmFileCmd);
  10078. rename(tempfile, filename);
  10079. }
  10080. else
  10081. {
  10082. // Profile is not empty
  10083. char buf[2048]={0};
  10084. int ChargingProfileAdded = FALSE;
  10085. while (fgets(buf, sizeof(buf), infile) != NULL)
  10086. {
  10087. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10088. json_object *tmpChargingProfile;
  10089. tmpChargingProfile = json_tokener_parse(buf);
  10090. if(!is_error(SetChargingProfile))
  10091. {
  10092. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10093. {
  10094. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10095. }
  10096. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10097. {
  10098. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10099. {
  10100. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10101. }
  10102. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10103. {
  10104. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10105. }
  10106. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10107. {
  10108. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10109. }
  10110. }
  10111. }
  10112. json_object_put(tmpChargingProfile);
  10113. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10114. {
  10115. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10116. {
  10117. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10118. if(ChargingProfileAdded == FALSE)
  10119. {
  10120. fprintf(outfile,"%s\n",payload);
  10121. ChargingProfileAdded = TRUE;
  10122. }
  10123. }
  10124. else
  10125. {
  10126. if(tempstackLevelInt < stackLevelInt)
  10127. {
  10128. if(ChargingProfileAdded == FALSE)
  10129. {
  10130. fprintf(outfile,"%s\n",buf);
  10131. fprintf(outfile,"%s\n",payload);
  10132. ChargingProfileAdded = TRUE;
  10133. }
  10134. else
  10135. {
  10136. fprintf(outfile,"%s\n",buf);
  10137. }
  10138. }
  10139. else
  10140. {
  10141. if(ChargingProfileAdded == FALSE)
  10142. {
  10143. fprintf(outfile,"%s\n",buf);
  10144. fprintf(outfile,"%s\n",payload);
  10145. ChargingProfileAdded = TRUE;
  10146. }
  10147. else
  10148. {
  10149. fprintf(outfile,"%s\n",buf);
  10150. }
  10151. }
  10152. }
  10153. }
  10154. else
  10155. {
  10156. if(tempchargingProfileIdInt < chargingProfileIdInt)
  10157. {
  10158. if(ChargingProfileAdded == FALSE)
  10159. {
  10160. fprintf(outfile,"%s\n",buf);
  10161. fprintf(outfile,"%s\n",payload);
  10162. ChargingProfileAdded = TRUE;
  10163. }
  10164. else
  10165. {
  10166. fprintf(outfile,"%s\n",buf);
  10167. }
  10168. }
  10169. else if(tempstackLevelInt < stackLevelInt)
  10170. {
  10171. if(ChargingProfileAdded == FALSE)
  10172. {
  10173. fprintf(outfile,"%s\n",buf);
  10174. fprintf(outfile,"%s\n",payload);
  10175. ChargingProfileAdded = TRUE;
  10176. }
  10177. else
  10178. {
  10179. fprintf(outfile,"%s\n",buf);
  10180. }
  10181. }
  10182. else
  10183. {
  10184. if(ChargingProfileAdded == FALSE)
  10185. {
  10186. fprintf(outfile,"%s\n",buf);
  10187. fprintf(outfile,"%s\n",payload);
  10188. ChargingProfileAdded = TRUE;
  10189. }
  10190. else
  10191. {
  10192. fprintf(outfile,"%s\n",buf);
  10193. }
  10194. }
  10195. }
  10196. } // end of while loop
  10197. fclose(infile);
  10198. fclose(outfile);
  10199. sprintf(rmFileCmd,"rm -f %s",filename);
  10200. system(rmFileCmd);
  10201. rename(tempfile, filename);
  10202. }
  10203. sleep(1);
  10204. result = TRUE;
  10205. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10206. end:
  10207. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10208. {
  10209. if(connectorIdInt == 0)
  10210. {
  10211. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10212. {
  10213. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  10214. }
  10215. }
  10216. else
  10217. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  10218. }
  10219. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10220. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10221. return result;
  10222. }
  10223. int handleTriggerMessageRequest(char *uuid, char *payload)
  10224. {
  10225. mtrace();
  10226. int result = FAIL;
  10227. int connectorIdIsNULL = FALSE;
  10228. int connectorIdInt =0;
  10229. char sstr[40]={0},sstrtemp[100]={ 0 };
  10230. char requestedMessagestr[40]={0};
  10231. char comfirmstr[20]={0};
  10232. int c = 0;
  10233. char *loc;
  10234. DEBUG_INFO("handleTriggerMessageRequest\n");
  10235. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10236. strcpy(sstrtemp, stringtrimspace(payload));
  10237. c = 0;
  10238. loc = strstr(sstrtemp, "requestedMessage");
  10239. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10240. {
  10241. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10242. c++;
  10243. }
  10244. sstr[c] = '\0';
  10245. strcpy(requestedMessagestr, sstr);
  10246. c = 0;
  10247. loc = strstr(sstrtemp, "connectorId");
  10248. if(loc == NULL)
  10249. {
  10250. connectorIdIsNULL = TRUE;
  10251. }
  10252. else
  10253. {
  10254. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10255. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10256. {
  10257. sstr[c] = loc[strlen("connectorId")+2+c];
  10258. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10259. c++;
  10260. }
  10261. sstr[c] = '\0';
  10262. connectorIdInt = atoi(sstr);
  10263. }
  10264. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10265. {
  10266. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10267. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10268. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10269. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10270. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10271. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10272. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10273. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10274. {
  10275. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10276. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10277. return TRUE;
  10278. }
  10279. else
  10280. {
  10281. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10282. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10283. }
  10284. }
  10285. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10286. {
  10287. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10288. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10289. return TRUE;
  10290. }
  10291. //==========================
  10292. // Trigger message
  10293. //==========================
  10294. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10295. {
  10296. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10297. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10298. {
  10299. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10300. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10301. }
  10302. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10303. }
  10304. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10305. {
  10306. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  10307. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10308. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10309. }
  10310. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10311. {
  10312. //sendBootNotificationRequest();
  10313. server_sign = FALSE;
  10314. }
  10315. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10316. {
  10317. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10318. }
  10319. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10320. {
  10321. if(connectorIdIsNULL == FALSE)
  10322. {
  10323. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10324. {
  10325. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10326. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10327. }
  10328. }
  10329. else
  10330. {
  10331. for(int idx=0;idx< gunTotalNumber;idx++)
  10332. {
  10333. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10334. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10335. }
  10336. }
  10337. }
  10338. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10339. {
  10340. if(connectorIdIsNULL == FALSE)
  10341. {
  10342. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10343. {
  10344. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  10345. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  10346. }
  10347. }
  10348. else
  10349. {
  10350. for(int idx=0;idx< gunTotalNumber;idx++)
  10351. {
  10352. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  10353. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10354. }
  10355. }
  10356. }
  10357. return result;
  10358. }
  10359. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10360. {
  10361. mtrace();
  10362. int result = FAIL;
  10363. int connectorIdInt =0;
  10364. char comfirmstr[20]={0};
  10365. int tempIndex = 0;
  10366. json_object *UnlockConnector;
  10367. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10368. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10369. UnlockConnector = json_tokener_parse(payload);
  10370. if(!is_error(UnlockConnector))
  10371. {
  10372. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10373. {
  10374. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10375. }
  10376. }
  10377. json_object_put(UnlockConnector);
  10378. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10379. if(gunTotalNumber == 0)
  10380. {
  10381. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10382. goto end;
  10383. }
  10384. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10385. {
  10386. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10387. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10388. goto end;
  10389. }
  10390. else
  10391. {
  10392. //check Transaction active
  10393. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10394. {
  10395. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10396. {
  10397. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10398. }
  10399. else
  10400. {
  10401. tempIndex = connectorIdInt -1;
  10402. }
  10403. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10404. {
  10405. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10406. {
  10407. //stop Transaction
  10408. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10409. }
  10410. }
  10411. }
  10412. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10413. {
  10414. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10415. {
  10416. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10417. }
  10418. else
  10419. {
  10420. tempIndex = connectorIdInt -1;
  10421. }
  10422. for (int index = 0; index < CCS_QUANTITY; index++)
  10423. {
  10424. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10425. {
  10426. //stop Transaction
  10427. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10428. }
  10429. }
  10430. }
  10431. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  10432. {
  10433. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10434. {
  10435. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10436. }
  10437. else
  10438. {
  10439. tempIndex = connectorIdInt -1;
  10440. }
  10441. for (int index = 0; index < GB_QUANTITY; index++)
  10442. {
  10443. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  10444. {
  10445. //stop Transaction
  10446. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10447. }
  10448. }
  10449. }
  10450. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  10451. {
  10452. tempIndex = connectorIdInt -1;
  10453. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10454. {
  10455. 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)))
  10456. {
  10457. //stop Transaction
  10458. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10459. }
  10460. }
  10461. }
  10462. else
  10463. {
  10464. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10465. {
  10466. tempIndex = 2;
  10467. }
  10468. else
  10469. {
  10470. tempIndex = connectorIdInt-1;
  10471. }
  10472. for (int index = 0; index < AC_QUANTITY; index++)
  10473. {
  10474. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10475. {
  10476. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10477. }
  10478. }
  10479. }
  10480. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  10481. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  10482. result = TRUE;
  10483. return result;
  10484. }
  10485. end:
  10486. //json_object_put(obj); --- remove temporally
  10487. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  10488. return result;
  10489. }
  10490. static char UpdateFirmwarepayloadData[300]={0};
  10491. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  10492. {
  10493. mtrace();
  10494. int result = FAIL;
  10495. pthread_t t;
  10496. sendUpdateFirmwareConfirmation(uuid);
  10497. memset(UpdateFirmwarepayloadData, 0, 300);
  10498. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  10499. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  10500. ////pthread_join(t, NULL); //
  10501. //pthread_detach(t);
  10502. //sendUpdateFirmwareConfirmation(uuid);
  10503. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  10504. return result;
  10505. }
  10506. void *UpdateFirmwareProcess(void *data)
  10507. {
  10508. pthread_detach(pthread_self());
  10509. mtrace();
  10510. int retriesInt =0, retryIntervalInt=0;
  10511. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  10512. int port=0;
  10513. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  10514. int isSuccess = 0;
  10515. char ftpbuf[1024];
  10516. char temp[1024];
  10517. char * pch;
  10518. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  10519. json_object *UpdateFirmware;
  10520. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  10521. if(!is_error(UpdateFirmware))
  10522. {
  10523. // Required data
  10524. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  10525. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  10526. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  10527. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  10528. // Optional data
  10529. if(json_object_object_get(UpdateFirmware, "retries"))
  10530. {
  10531. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  10532. }
  10533. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  10534. {
  10535. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  10536. }
  10537. }
  10538. json_object_put(UpdateFirmware);
  10539. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10540. memset(path, 0, ARRAY_SIZE(path));
  10541. // Wait retrieveData
  10542. if(strlen(retrieveDatestr) > 10)
  10543. {
  10544. do
  10545. {
  10546. sleep(1);
  10547. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  10548. }
  10549. // Ready to download
  10550. system("rm -f /mnt/*");
  10551. if(strncmp(locationstr,"http", 4) == 0)
  10552. {
  10553. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10554. sprintf(ftppath,"/%s", path);
  10555. DEBUG_INFO("locationstr: %s\n", locationstr);
  10556. DEBUG_INFO("protocol: %s\n",protocol);
  10557. DEBUG_INFO("host: %s\n",host);
  10558. DEBUG_INFO("path: %s\n",path);
  10559. DEBUG_INFO("ftppath: %s\n",ftppath);
  10560. int ftppathlen=strlen(ftppath);
  10561. int i=1;
  10562. char filenametemp[50];
  10563. while(i < ftppathlen)
  10564. {
  10565. int len=ftppathlen-i;
  10566. if(ftppath[len]== 47) // '/' ascll code: 47
  10567. {
  10568. DEBUG_INFO("compare '/' all right\n");
  10569. break;
  10570. }
  10571. i=i+1;
  10572. }
  10573. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10574. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10575. filenametemp[i+1] = 0;
  10576. do
  10577. {
  10578. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10579. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10580. sleep(1);
  10581. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10582. if(!isSuccess)
  10583. {
  10584. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10585. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10586. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10587. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10588. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10589. }
  10590. else
  10591. {
  10592. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10593. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10594. }
  10595. retriesInt--;
  10596. }while((isSuccess == 0)&&(retriesInt >= 0));
  10597. }
  10598. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10599. {
  10600. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10601. memset(temp, 0, ARRAY_SIZE(temp));
  10602. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10603. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10604. int ftppathlen=strlen(ftpbuf);
  10605. int i=1;
  10606. char filenametemp[50];
  10607. while(i < ftppathlen)
  10608. {
  10609. int len=ftppathlen-i;
  10610. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10611. {
  10612. DEBUG_INFO(" compare '/' all right\n");
  10613. break;
  10614. }
  10615. i=i+1;
  10616. }
  10617. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10618. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10619. filenametemp[i+1] = 0;
  10620. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10621. pch=strchr(temp,'@');
  10622. if(pch==NULL)
  10623. {
  10624. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10625. protocol, host, &port, path);
  10626. strcpy(user,"anonymous");
  10627. strcpy(password,"");
  10628. }
  10629. else
  10630. {
  10631. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10632. protocol, user, password, host, &port, path);
  10633. }
  10634. sscanf(host,"%[^/]%s",host1, path1);
  10635. sprintf(ftppath,"%s", path1);
  10636. //DEBUG_INFO("protocol =%s\n",protocol);
  10637. //DEBUG_INFO("user =%s\n",user);
  10638. //DEBUG_INFO("password =%s\n",password);
  10639. //DEBUG_INFO("host1 =%s\n",host1);
  10640. //DEBUG_INFO("port =%d\n",port);
  10641. //DEBUG_INFO("path1 =%s\n",path1);
  10642. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10643. //ftpFile(host, user, password, port, ftppath, fname);
  10644. //download firmware pthred
  10645. if(port == 0)
  10646. {
  10647. port = 21;
  10648. }
  10649. do
  10650. {
  10651. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10652. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10653. sleep(1);
  10654. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10655. if(!isSuccess)
  10656. {
  10657. //BulldogUtil.sleepMs(interval*1000);
  10658. DEBUG_INFO("Update firmware request and download file fail.\n");
  10659. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10660. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10661. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10662. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10663. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10664. }
  10665. else
  10666. {
  10667. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10668. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10669. }
  10670. retriesInt--;
  10671. }while((!isSuccess)&&(retriesInt >= 0));
  10672. }
  10673. else
  10674. {
  10675. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10676. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10677. sleep(1);
  10678. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10679. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10680. }
  10681. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  10682. pthread_exit(NULL);
  10683. }
  10684. int handleCertificateSignedRequest(char *uuid, char *payload)
  10685. {
  10686. mtrace();
  10687. int result = PASS;
  10688. json_object *CertificateSigned;
  10689. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10690. CertificateSigned = json_tokener_parse(payload);
  10691. if(!is_error(CertificateSigned))
  10692. {
  10693. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  10694. }
  10695. json_object_put(CertificateSigned);
  10696. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  10697. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  10698. fclose(fp);
  10699. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10700. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  10701. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  10702. sendCertificateSignedConfirmation(uuid);
  10703. return result;
  10704. }
  10705. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10706. {
  10707. mtrace();
  10708. int result = PASS;
  10709. json_object *DeleteCertificate;
  10710. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10711. DeleteCertificate = json_tokener_parse(payload);
  10712. if(!is_error(DeleteCertificate))
  10713. {
  10714. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10715. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10716. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10717. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10718. }
  10719. json_object_put(DeleteCertificate);
  10720. /*
  10721. * TODO: Delete certificateSigned process
  10722. */
  10723. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  10724. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  10725. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  10726. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  10727. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  10728. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  10729. sendDeleteCertificateConfirmation(uuid);
  10730. return result;
  10731. }
  10732. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  10733. {
  10734. mtrace();
  10735. int result = PASS;
  10736. json_object *ExtendedTriggerMessage;
  10737. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  10738. ExtendedTriggerMessage = json_tokener_parse(payload);
  10739. if(!is_error(ExtendedTriggerMessage))
  10740. {
  10741. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  10742. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  10743. {
  10744. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  10745. }
  10746. else
  10747. {
  10748. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  10749. }
  10750. }
  10751. json_object_put(ExtendedTriggerMessage);
  10752. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  10753. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  10754. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  10755. {
  10756. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  10757. }
  10758. else
  10759. {
  10760. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  10761. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  10762. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10763. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  10764. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  10765. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  10766. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  10767. {
  10768. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10769. }
  10770. else
  10771. {
  10772. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10773. }
  10774. }
  10775. sendExtendedTriggerMessageConfirmation(uuid);
  10776. //==========================
  10777. // Trigger message
  10778. //==========================
  10779. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  10780. {
  10781. //sendBootNotificationRequest();
  10782. server_sign = FALSE;
  10783. }
  10784. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  10785. {
  10786. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  10787. }
  10788. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10789. {
  10790. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  10791. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10792. {
  10793. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10794. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10795. }
  10796. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10797. }
  10798. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  10799. {
  10800. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  10801. }
  10802. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  10803. {
  10804. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10805. {
  10806. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  10807. }
  10808. else
  10809. {
  10810. for(int idx=0;idx< gunTotalNumber;idx++)
  10811. {
  10812. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10813. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10814. }
  10815. }
  10816. }
  10817. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  10818. {
  10819. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  10820. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  10821. {
  10822. 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\" &");
  10823. }
  10824. }
  10825. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  10826. {
  10827. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10828. {
  10829. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  10830. }
  10831. else
  10832. {
  10833. for(int idx=0;idx< gunTotalNumber;idx++)
  10834. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10835. }
  10836. }
  10837. return result;
  10838. }
  10839. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10840. {
  10841. mtrace();
  10842. int result = PASS;
  10843. json_object *GetInstalledCertificateIds;
  10844. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10845. GetInstalledCertificateIds = json_tokener_parse(payload);
  10846. if(!is_error(GetInstalledCertificateIds))
  10847. {
  10848. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  10849. }
  10850. json_object_put(GetInstalledCertificateIds);
  10851. /*
  10852. * TODO: Return installed certificate process
  10853. */
  10854. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  10855. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  10856. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  10857. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  10858. sendGetInstalledCertificateIdsConfirmation(uuid);
  10859. return result;
  10860. }
  10861. int handleGetLogRequest(char *uuid, char *payload)
  10862. {
  10863. mtrace();
  10864. int result = PASS;
  10865. json_object *GetLog;
  10866. DEBUG_INFO("handleGetLogRequest...\n");
  10867. GetLog = json_tokener_parse(payload);
  10868. if(!is_error(GetLog))
  10869. {
  10870. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10871. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10872. if(json_object_object_get(GetLog, "retries") != NULL)
  10873. {
  10874. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  10875. }
  10876. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  10877. {
  10878. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  10879. }
  10880. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10881. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10882. {
  10883. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10884. }
  10885. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10886. {
  10887. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10888. }
  10889. }
  10890. json_object_put(GetLog);
  10891. /*
  10892. * TODO: Upload log process
  10893. */
  10894. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  10895. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  10896. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  10897. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  10898. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  10899. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  10900. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  10901. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  10902. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  10903. sendGetLogConfirmation(uuid);
  10904. return result;
  10905. }
  10906. int handleInstallCertificateRequest(char *uuid, char *payload)
  10907. {
  10908. mtrace();
  10909. int result = PASS;
  10910. json_object *InstallCertificate;
  10911. DEBUG_INFO("handleInstallCertificateRequest...\n");
  10912. InstallCertificate = json_tokener_parse(payload);
  10913. if(!is_error(InstallCertificate))
  10914. {
  10915. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  10916. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  10917. /*
  10918. * TODO: Install certificate process
  10919. */
  10920. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  10921. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  10922. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  10923. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  10924. sendInstallCertificateConfirmation(uuid);
  10925. }
  10926. json_object_put(InstallCertificate);
  10927. return result;
  10928. }
  10929. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  10930. {
  10931. mtrace();
  10932. int result = PASS;
  10933. json_object *SignedUpdateFirmware;
  10934. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  10935. SignedUpdateFirmware = json_tokener_parse(payload);
  10936. if(!is_error(SignedUpdateFirmware))
  10937. {
  10938. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  10939. {
  10940. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  10941. }
  10942. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  10943. {
  10944. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  10945. }
  10946. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  10947. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  10948. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  10949. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  10950. {
  10951. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  10952. }
  10953. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  10954. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  10955. }
  10956. json_object_put(SignedUpdateFirmware);
  10957. /*
  10958. * TODO: Upgrade firmware process
  10959. */
  10960. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  10961. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  10962. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  10963. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  10964. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  10965. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  10966. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  10967. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  10968. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  10969. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  10970. sendInstallCertificateConfirmation(uuid);
  10971. return result;
  10972. }
  10973. int handleUnknownRequest(char *uuid, char *payload)
  10974. {
  10975. mtrace();
  10976. int result = PASS;
  10977. DEBUG_INFO("handleUnknownRequest...\n");
  10978. sendUnknownConfirmation(uuid);
  10979. result = PASS;
  10980. return result;
  10981. }
  10982. //==========================================
  10983. // Handle server response routine
  10984. //==========================================
  10985. void handleAuthorizeResponse(char *payload, int gun_index)
  10986. {
  10987. mtrace();
  10988. char expiryDatestr[30]={0};
  10989. char parentIdTagstr[20]={0};
  10990. char statusstr[20]={0};
  10991. int expiryDateISNULL=FALSE;
  10992. int parentIdTagISNULL=FALSE;
  10993. DEBUG_INFO("handleAuthorizeResponse...\n");
  10994. json_object *Authorize;
  10995. Authorize = json_tokener_parse(payload);
  10996. if(!is_error(Authorize))
  10997. {
  10998. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  10999. {
  11000. // Required data
  11001. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11002. // Optional data
  11003. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11004. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11005. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11006. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11007. }
  11008. }
  11009. json_object_put(Authorize);
  11010. if(expiryDateISNULL == FALSE)
  11011. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11012. if(parentIdTagISNULL == FALSE)
  11013. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11014. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  11015. //Update idTag information to authorization cache if supproted
  11016. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11017. {
  11018. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11019. }
  11020. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  11021. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11022. authorizeRetryTimes = 0;
  11023. }
  11024. void handleBootNotificationResponse(char *payload, int gun_index)
  11025. {
  11026. mtrace();
  11027. char statusStr[12]={0};
  11028. char currentTimeStr[30]={0};
  11029. int intervalInt = 0;
  11030. DEBUG_INFO("handleBootNotificationResponse...\n");
  11031. json_object *BootNotification;
  11032. BootNotification = json_tokener_parse(payload);
  11033. if(!is_error(BootNotification))
  11034. {
  11035. // Required data
  11036. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11037. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11038. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11039. }
  11040. json_object_put(BootNotification);
  11041. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11042. BootNotificationInterval = intervalInt;
  11043. HeartBeatWaitTime = intervalInt;
  11044. //write back to ShmOCPP16Data->BootNotification
  11045. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  11046. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11047. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  11048. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11049. {
  11050. server_sign = TRUE;
  11051. server_pending =FALSE;
  11052. }
  11053. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11054. {
  11055. server_pending = TRUE;
  11056. }
  11057. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  11058. srand(time(NULL));
  11059. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11060. SetOcppConnStatus(TRUE);
  11061. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  11062. }
  11063. void handleDataTransferResponse(char *payload, int gun_index)
  11064. {
  11065. char sstr[160]={0};//sstr[200]={ 0 };
  11066. int c = 0;
  11067. char *loc;
  11068. DEBUG_INFO("handleDataTransferResponse ...\n");
  11069. loc = strstr(payload, "status");
  11070. printf("loc=%s\n",loc);
  11071. c = 0;
  11072. while (loc[3+strlen("status")+c] != '\"')
  11073. {
  11074. sstr[c] = loc[3+strlen("status")+c];
  11075. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11076. c++;
  11077. }
  11078. sstr[c] = '\0';
  11079. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11080. }
  11081. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11082. {
  11083. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11084. //struct json_object *obj;
  11085. // obj = json_tokener_parse(payload);
  11086. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11087. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11088. //No fields are defined.
  11089. }
  11090. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11091. {
  11092. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11093. //struct json_object *obj;
  11094. // obj = json_tokener_parse(payload);
  11095. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11096. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11097. //No fields are defined.
  11098. }
  11099. void handleHeartbeatResponse(char *payload, int gun_index)
  11100. {
  11101. mtrace();
  11102. DEBUG_INFO("handleHeartbeatResponse...\n");
  11103. json_object *Heartbeat;
  11104. Heartbeat = json_tokener_parse(payload);
  11105. if(!is_error(Heartbeat))
  11106. {
  11107. // Required data
  11108. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11109. }
  11110. json_object_put(Heartbeat);
  11111. if(FirstHeartBeat == 0)
  11112. {
  11113. FirstHeartBeat = 1;
  11114. DEBUG_INFO("FirstHeartBeat \n");
  11115. }
  11116. HeartBeatWithNOResponse = 0;
  11117. clientTime.Heartbeat=time((time_t*)NULL);
  11118. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  11119. }
  11120. void handleMeterValuesResponse(char *payload, int gun_index)
  11121. {
  11122. mtrace();
  11123. DEBUG_INFO("handleMeterValuesResponse...\n");
  11124. }
  11125. void handleStartTransactionResponse(char *payload, int gun_index)
  11126. {
  11127. mtrace();
  11128. //int transactionIdInt = 0;
  11129. FILE *outfile;
  11130. char data[100]={0};
  11131. DEBUG_INFO("handleStartTransactionResponse...\n");
  11132. json_object *StartTransaction;
  11133. StartTransaction = json_tokener_parse(payload);
  11134. if(!is_error(StartTransaction))
  11135. {
  11136. // Required data
  11137. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11138. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11139. // Optional data
  11140. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11141. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11142. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11143. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11144. }
  11145. json_object_put(StartTransaction);
  11146. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11147. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11148. //-----------Start : write to the Queue TransactionId file -----------------//
  11149. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  11150. {}
  11151. else
  11152. {
  11153. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  11154. if(log == NULL)
  11155. {
  11156. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11157. return ;
  11158. }
  11159. else
  11160. {
  11161. fclose(log);
  11162. }
  11163. }
  11164. // open file for writing
  11165. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11166. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  11167. {
  11168. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  11169. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11170. fputs(data, outfile);
  11171. fclose (outfile);
  11172. }
  11173. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11174. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11175. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11176. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  11177. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11178. }
  11179. void handleStatusNotificationResponse(char *payload, int gun_index)
  11180. {
  11181. mtrace();
  11182. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11183. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11184. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11185. }
  11186. void handleStopTransactionnResponse(char *payload, int gun_index)
  11187. {
  11188. mtrace();
  11189. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11190. json_object *StopTransaction;
  11191. StopTransaction = json_tokener_parse(payload);
  11192. if(!is_error(StopTransaction))
  11193. {
  11194. // Optional data
  11195. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11196. {
  11197. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11198. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11199. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11200. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11201. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11202. }
  11203. }
  11204. json_object_put(StopTransaction);
  11205. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11206. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11207. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11208. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11209. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11210. }
  11211. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11212. {
  11213. mtrace();
  11214. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11215. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  11216. }
  11217. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11218. {
  11219. mtrace();
  11220. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11221. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  11222. }
  11223. void handleSignCertificateResponse(char *payload, int gun_index)
  11224. {
  11225. mtrace();
  11226. DEBUG_INFO("handleSignCertificateResponse...\n");
  11227. json_object *SignCertificate;
  11228. SignCertificate = json_tokener_parse(payload);
  11229. if(!is_error(SignCertificate))
  11230. {
  11231. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11232. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  11233. }
  11234. json_object_put(SignCertificate);
  11235. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  11236. }
  11237. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11238. {
  11239. mtrace();
  11240. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11241. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11242. }
  11243. //==========================================
  11244. // Handle Error routine
  11245. //==========================================
  11246. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11247. {
  11248. mtrace();
  11249. #ifdef SystemLogMessage
  11250. DEBUG_INFO("errorCode: %s\n", errorCode);
  11251. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11252. DEBUG_INFO("errorDetails: %s\n", payload);
  11253. #endif
  11254. }
  11255. //===============================================
  11256. // Common routine
  11257. //===============================================
  11258. int initialConfigurationTable(void)
  11259. {
  11260. //clock_t start_t, end_t, total_t;
  11261. FILE *fp;
  11262. FILE *outfile;
  11263. char str[512]={0};
  11264. char sstr[256]={0};
  11265. int c = 0;
  11266. char *loc;
  11267. int confVersion = 2;
  11268. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11269. //start_t = clock();
  11270. //printf("Starting of the program, start_t = %ld\n", start_t);
  11271. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11272. // Check configuration file size is correct
  11273. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  11274. {
  11275. struct stat st;
  11276. stat("/Storage/OCPP/OCPPConfiguration", &st);
  11277. if(st.st_size < 3100)
  11278. {
  11279. system("rm -f /Storage/OCPP/OCPPConfiguration");
  11280. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11281. }
  11282. }
  11283. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  11284. {
  11285. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11286. if(outfile == NULL)
  11287. {
  11288. DEBUG_INFO("Error opening file\n");
  11289. return FALSE;
  11290. }
  11291. /*Core Profile*/
  11292. //AllowOfflineTxForUnknownId
  11293. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11297. //AuthorizationCacheEnabled
  11298. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11302. //AuthorizeRemoteTxRequests
  11303. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11307. //BlinkRepeat
  11308. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11312. //ClockAlignedDataInterval
  11313. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11317. //ConnectionTimeOut
  11318. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11322. //GetConfigurationMaxKeys
  11323. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11325. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11326. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11327. // HeartbeatInterval
  11328. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11332. // LightIntensity
  11333. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11336. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11337. // LocalAuthorizeOffline
  11338. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11342. // LocalPreAuthorize
  11343. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  11344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11346. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11347. // MaxEnergyOnInvalidId
  11348. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11352. // MeterValuesAlignedData
  11353. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11355. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11357. else
  11358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11360. // MeterValuesAlignedDataMaxLength
  11361. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11363. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11365. else
  11366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11368. // MeterValuesSampledData
  11369. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11371. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11373. else
  11374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11375. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11376. // MeterValuesSampledDataMaxLength
  11377. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11379. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11381. else
  11382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11383. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11384. // MeterValueSampleInterval
  11385. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11389. // MinimumStatusDuration
  11390. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11393. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11395. // NumberOfConnectors
  11396. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11398. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11399. {
  11400. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11401. }
  11402. else
  11403. {
  11404. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11405. }
  11406. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11407. // ResetRetries
  11408. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11411. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11412. // ConnectorPhaseRotation
  11413. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11416. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11417. // ConnectorPhaseRotationMaxLength
  11418. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11422. // StopTransactionOnEVSideDisconnect
  11423. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11424. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11426. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11427. // StopTransactionOnInvalidId
  11428. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  11429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11432. // StopTxnAlignedData
  11433. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  11434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11437. // StopTxnAlignedDataMaxLength
  11438. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11441. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11442. // StopTxnSampledData
  11443. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11445. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11446. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11447. else
  11448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11449. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11450. // StopTxnSampledDataMaxLength
  11451. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11453. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11454. {
  11455. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  11456. }
  11457. else
  11458. {
  11459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  11460. }
  11461. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11462. // SupportedFeatureProfiles
  11463. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11466. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11467. // SupportedFeatureProfilesMaxLength
  11468. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11471. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11472. // TransactionMessageAttempts
  11473. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11476. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11477. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11478. // TransactionMessageRetryInterval
  11479. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11482. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11483. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11484. // UnlockConnectorOnEVSideDisconnect
  11485. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11488. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11489. // WebSocketPingInterval
  11490. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11493. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11494. // QueueOffLineStartTransactionMessage
  11495. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  11496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11498. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11499. // AuthorizationKey
  11500. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  11503. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11504. // SecurityProfile
  11505. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11507. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  11508. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11509. // DefaultPrice
  11510. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11514. // CustomDisplayCostAndPrice
  11515. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11518. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11519. // CustomIdleFeeAfterStop
  11520. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11523. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11524. // Configuration Version
  11525. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  11526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11527. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  11528. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11529. //* Local Auth List Management Profile*/
  11530. #if 0
  11531. //For OCTT Test Case
  11532. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  11534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11535. #endif
  11536. #if 1
  11537. //LocalAuthListEnabled
  11538. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11541. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11542. #endif
  11543. //LocalAuthListMaxLength
  11544. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11547. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11548. //SendLocalListMaxLength
  11549. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  11552. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11553. //ReserveConnectorZeroSupported
  11554. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11557. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11558. //* Smart Charging Profile */
  11559. //ChargeProfileMaxStackLevel
  11560. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11564. // ChargingScheduleAllowedChargingRateUnit
  11565. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11568. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11569. // ChargingScheduleMaxPeriods
  11570. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11574. // ConnectorSwitch3to1PhaseSupported
  11575. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11579. // MaxChargingProfilesInstalled
  11580. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11584. fclose(outfile);
  11585. }
  11586. else
  11587. {
  11588. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  11589. char keystr[60]={0};
  11590. char readonlystr[10]={0};
  11591. char valuestr[256]={0};
  11592. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  11593. if(fp == NULL) {
  11594. DEBUG_INFO("Error opening file");
  11595. return FALSE;
  11596. }
  11597. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  11598. {
  11599. //DEBUG_INFO("Get Configuration \n");
  11600. if(strlen(str) > 0)
  11601. {
  11602. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  11603. //*************************key*********************************/
  11604. if(strstr(str, "key") != NULL)
  11605. {
  11606. loc = strstr(str, "key");
  11607. c = 0;
  11608. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11609. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11610. {
  11611. sstr[c] = loc[strlen("key")+3+c];
  11612. c++;
  11613. }
  11614. sstr[c] = '\0';
  11615. strcpy(keystr,sstr);
  11616. }
  11617. //*************************readonly*********************************/
  11618. if(strstr(str, "readonly") != NULL)
  11619. {
  11620. loc = strstr(str, "readonly");
  11621. c = 0;
  11622. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11623. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  11624. {
  11625. sstr[c] = loc[strlen("readonly")+2+c];
  11626. c++;
  11627. }
  11628. sstr[c] = '\0';
  11629. strcpy(readonlystr,sstr);
  11630. }
  11631. //*************************value*********************************/
  11632. if(strstr(str, "value") != NULL)
  11633. {
  11634. loc = strstr(str, "value");
  11635. c = 0;
  11636. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11637. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11638. {
  11639. sstr[c] = loc[strlen("value")+3+c];
  11640. c++;
  11641. }
  11642. sstr[c] = '\0';
  11643. strcpy(valuestr,sstr);
  11644. }
  11645. // DEBUG_INFO("keystr=%s\n",keystr);
  11646. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  11647. // DEBUG_INFO("valuestr=%s\n",valuestr);
  11648. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  11649. {
  11650. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11651. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11652. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  11653. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11654. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11655. }
  11656. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  11657. {
  11658. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11659. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  11661. }
  11662. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  11663. {
  11664. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  11666. }
  11667. if(strcmp(keystr, "BlinkRepeat") == 0)
  11668. {
  11669. //Charger.BlinkRepeat = Integer.parseInt(value);
  11670. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11671. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  11672. }
  11673. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  11674. {
  11675. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11676. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  11677. }
  11678. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  11679. {
  11680. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11681. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  11682. }
  11683. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  11684. {
  11685. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  11687. }
  11688. if(strcmp(keystr, "HeartbeatInterval") == 0)
  11689. {
  11690. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11691. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  11692. HeartBeatWaitTime = atoi(valuestr);
  11693. }
  11694. if(strcmp(keystr, "LightIntensity") == 0)
  11695. {
  11696. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11697. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  11698. }
  11699. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  11700. {
  11701. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11702. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  11703. }
  11704. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  11705. {
  11706. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11707. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  11708. }
  11709. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  11710. {
  11711. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11712. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  11713. }
  11714. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  11715. {
  11716. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11717. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11718. }
  11719. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11720. {
  11721. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11722. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11723. }
  11724. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11725. {
  11726. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11727. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11728. }
  11729. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11730. {
  11731. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11732. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11733. }
  11734. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11735. {
  11736. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11737. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11738. }
  11739. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11740. {
  11741. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11742. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11743. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11744. }
  11745. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11746. {
  11747. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11748. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11749. }
  11750. if(strcmp(keystr, "ResetRetries") == 0)
  11751. {
  11752. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11753. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11754. }
  11755. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11756. {
  11757. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11758. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11759. }
  11760. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11761. {
  11762. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11763. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11764. }
  11765. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11766. {
  11767. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11768. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11769. }
  11770. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11771. {
  11772. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11773. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11774. }
  11775. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11776. {
  11777. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11778. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11779. }
  11780. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11781. {
  11782. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11783. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11784. }
  11785. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11786. {
  11787. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11788. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11789. }
  11790. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11791. {
  11792. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11793. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11794. }
  11795. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11796. {
  11797. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11798. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11799. }
  11800. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11801. {
  11802. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11803. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11804. }
  11805. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11806. {
  11807. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11808. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11809. TransactionMessageAttemptsValue = atoi(valuestr);
  11810. }
  11811. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11812. {
  11813. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11815. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11816. }
  11817. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11818. {
  11819. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11820. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11821. }
  11822. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11823. {
  11824. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11825. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11826. }
  11827. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  11828. {
  11829. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  11831. }
  11832. if(strcmp(keystr, "AuthorizationKey") == 0)
  11833. {
  11834. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11835. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  11836. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  11837. }
  11838. if(strcmp(keystr, "SecurityProfile") == 0)
  11839. {
  11840. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11841. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  11842. }
  11843. if(strcmp(keystr, "DefaultPrice") == 0)
  11844. {
  11845. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11846. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  11847. }
  11848. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  11849. {
  11850. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  11852. }
  11853. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  11854. {
  11855. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11856. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  11857. }
  11858. if(strcmp(keystr, "ConfigurationVersion") == 0)
  11859. {
  11860. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11861. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  11862. }
  11863. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11864. {
  11865. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11866. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11867. }
  11868. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11869. {
  11870. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11871. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11872. }
  11873. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11874. {
  11875. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11876. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11877. }
  11878. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11879. {
  11880. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11881. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11882. }
  11883. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11884. {
  11885. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11887. }
  11888. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11889. {
  11890. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11891. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11892. }
  11893. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11894. {
  11895. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11896. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11897. }
  11898. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11899. {
  11900. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11901. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11902. }
  11903. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11904. {
  11905. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11906. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11907. }
  11908. }
  11909. }
  11910. fclose(fp);
  11911. }
  11912. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  11913. {
  11914. return PASS;
  11915. }
  11916. else
  11917. {
  11918. return FAIL;
  11919. }
  11920. }
  11921. void StoreConfigurationTable(void)
  11922. {
  11923. FILE *outfile;
  11924. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11925. if(outfile == NULL)
  11926. {
  11927. DEBUG_INFO("Error opening file");
  11928. return ;
  11929. }
  11930. /*Core Profile*/
  11931. //AllowOfflineTxForUnknownId
  11932. /*
  11933. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11934. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11937. */
  11938. //DEBUG_INFO("data=%s\n",data);
  11939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11940. //AuthorizationCacheEnabled
  11941. /*
  11942. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11944. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11945. */
  11946. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11947. //AuthorizeRemoteTxRequests
  11948. /*
  11949. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11952. */
  11953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11954. //BlinkRepeat
  11955. /*
  11956. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11959. */
  11960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11961. //ClockAlignedDataInterval
  11962. /*
  11963. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11966. */
  11967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11968. //ConnectionTimeOut
  11969. /*
  11970. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11973. */
  11974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11975. //GetConfigurationMaxKeys
  11976. /*
  11977. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11980. */
  11981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11982. // HeartbeatInterval
  11983. /*
  11984. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11987. */
  11988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11989. // LightIntensity
  11990. /*
  11991. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11994. */
  11995. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11996. // LocalAuthorizeOffline
  11997. /*
  11998. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12001. */
  12002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12003. // LocalPreAuthorize
  12004. /*
  12005. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12008. */
  12009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12010. // MaxEnergyOnInvalidId
  12011. /*
  12012. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12015. */
  12016. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12017. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12018. // MeterValuesAlignedData
  12019. /*
  12020. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12023. */
  12024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12025. // MeterValuesAlignedDataMaxLength
  12026. /*
  12027. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12030. */
  12031. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12032. // MeterValuesSampledData
  12033. /*
  12034. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12037. */
  12038. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12039. // MeterValuesSampledDataMaxLength
  12040. /*
  12041. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12044. */
  12045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12046. // MeterValueSampleInterval
  12047. /*
  12048. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12051. */
  12052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12053. // MinimumStatusDuration
  12054. /*
  12055. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12058. */
  12059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12060. // NumberOfConnectors
  12061. /*
  12062. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12064. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12065. {
  12066. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12067. }
  12068. else
  12069. {
  12070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12071. }
  12072. */
  12073. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12074. // ResetRetries
  12075. /*
  12076. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12079. */
  12080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12081. // ConnectorPhaseRotation
  12082. /*
  12083. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12086. */
  12087. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12088. // ConnectorPhaseRotationMaxLength
  12089. /*
  12090. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12093. */
  12094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12095. // StopTransactionOnEVSideDisconnect
  12096. /*
  12097. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12100. */
  12101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12102. // StopTransactionOnInvalidId
  12103. /*
  12104. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12107. */
  12108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12109. // StopTxnAlignedData
  12110. /*
  12111. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12114. */
  12115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12116. // StopTxnAlignedDataMaxLength
  12117. /*
  12118. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12121. */
  12122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12123. // StopTxnSampledData
  12124. /*
  12125. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12128. */
  12129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12130. // StopTxnSampledDataMaxLength
  12131. /*
  12132. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12135. */
  12136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12137. // SupportedFeatureProfiles
  12138. /*
  12139. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12142. */
  12143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12144. // SupportedFeatureProfilesMaxLength
  12145. /*
  12146. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12149. */
  12150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12151. // TransactionMessageAttempts
  12152. /*
  12153. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12156. */
  12157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12158. // TransactionMessageRetryInterval
  12159. /*
  12160. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12163. */
  12164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12165. // UnlockConnectorOnEVSideDisconnect
  12166. /*
  12167. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12170. */
  12171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12172. // WebSocketPingInterval
  12173. /*
  12174. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12177. */
  12178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12179. // QueueOffLineStartTransactionMessage
  12180. /*
  12181. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  12182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12184. */
  12185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12186. // AuthorizationKey
  12187. /*
  12188. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12191. */
  12192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12193. // SecurityProfile
  12194. /*
  12195. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12198. */
  12199. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12200. // DefaultPrice
  12201. /*
  12202. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12205. */
  12206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12207. // CustomDisplayCostAndPrice
  12208. /*
  12209. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12211. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12212. */
  12213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12214. // CustomIdleFeeAfterStop
  12215. /*
  12216. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12219. */
  12220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12221. // ConfigurationVersion
  12222. /*
  12223. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12226. */
  12227. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12228. //* Local Auth List Management Profile*/
  12229. //LocalAuthListEnabled
  12230. /*
  12231. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12234. */
  12235. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12236. //LocalAuthListMaxLength
  12237. /*
  12238. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12241. */
  12242. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12243. //SendLocalListMaxLength
  12244. /*
  12245. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12248. */
  12249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12250. //ReserveConnectorZeroSupported
  12251. /*
  12252. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12255. */
  12256. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12257. //* Smart Charging Profile */
  12258. //ChargeProfileMaxStackLevel
  12259. /*
  12260. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12263. */
  12264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12265. // ChargingScheduleAllowedChargingRateUnit
  12266. /*
  12267. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12270. */
  12271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12272. // ChargingScheduleMaxPeriods
  12273. /*
  12274. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12277. */
  12278. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12279. // ConnectorSwitch3to1PhaseSupported
  12280. /*
  12281. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12284. */
  12285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12286. // MaxChargingProfilesInstalled
  12287. /*
  12288. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12290. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12291. */
  12292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12293. fclose(outfile);
  12294. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12295. }
  12296. void getKeyValue(char *keyReq)
  12297. {
  12298. int isEmpty = FALSE;
  12299. int isKnowKey = FALSE;
  12300. DEBUG_INFO("keyReq = %s\n", keyReq);
  12301. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12302. isEmpty = TRUE;
  12303. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12304. {
  12305. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12307. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12308. {
  12309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12310. }
  12311. else
  12312. {
  12313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12314. }
  12315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12316. isKnowKey = TRUE;
  12317. }
  12318. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12319. {
  12320. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12322. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12323. {
  12324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12325. }
  12326. else
  12327. {
  12328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12329. }
  12330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12331. isKnowKey = TRUE;
  12332. }
  12333. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12334. {
  12335. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12337. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12338. {
  12339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12340. }
  12341. else
  12342. {
  12343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12344. }
  12345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12346. isKnowKey = TRUE;
  12347. }
  12348. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12349. {
  12350. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12352. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12353. {
  12354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12355. }
  12356. else
  12357. {
  12358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12359. }
  12360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12361. isKnowKey = TRUE;
  12362. }
  12363. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12364. {
  12365. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12367. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12368. {
  12369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12370. }
  12371. else
  12372. {
  12373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12374. }
  12375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12376. isKnowKey = TRUE;
  12377. }
  12378. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12379. {
  12380. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12382. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12383. {
  12384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12385. }
  12386. else
  12387. {
  12388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12389. }
  12390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12391. isKnowKey = TRUE;
  12392. }
  12393. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12394. {
  12395. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12398. {
  12399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12400. }
  12401. else
  12402. {
  12403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12404. }
  12405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12406. isKnowKey = TRUE;
  12407. }
  12408. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  12409. {
  12410. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  12411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  12412. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12413. {
  12414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  12415. }
  12416. else
  12417. {
  12418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  12419. }
  12420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  12421. isKnowKey = TRUE;
  12422. }
  12423. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  12424. {
  12425. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  12426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  12427. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12428. {
  12429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  12430. }
  12431. else
  12432. {
  12433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  12434. }
  12435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  12436. isKnowKey = TRUE;
  12437. }
  12438. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  12439. {
  12440. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  12441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  12442. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12443. {
  12444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  12445. }
  12446. else
  12447. {
  12448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  12449. }
  12450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  12451. isKnowKey = TRUE;
  12452. }
  12453. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  12454. {
  12455. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  12456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  12457. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12458. {
  12459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  12460. }
  12461. else
  12462. {
  12463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  12464. }
  12465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  12466. isKnowKey = TRUE;
  12467. }
  12468. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  12469. {
  12470. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  12471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  12472. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12473. {
  12474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12475. }
  12476. else
  12477. {
  12478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12479. }
  12480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  12481. isKnowKey = TRUE;
  12482. }
  12483. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  12484. {
  12485. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  12486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  12487. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12488. {
  12489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12490. }
  12491. else
  12492. {
  12493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12494. }
  12495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  12496. isKnowKey = TRUE;
  12497. }
  12498. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  12499. {
  12500. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  12501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  12502. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12503. {
  12504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12505. }
  12506. else
  12507. {
  12508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12509. }
  12510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  12511. isKnowKey = TRUE;
  12512. }
  12513. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  12514. {
  12515. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  12516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  12517. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12518. {
  12519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  12520. }
  12521. else
  12522. {
  12523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  12524. }
  12525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  12526. isKnowKey = TRUE;
  12527. }
  12528. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  12529. {
  12530. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  12531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  12532. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12533. {
  12534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12535. }
  12536. else
  12537. {
  12538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12539. }
  12540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  12541. isKnowKey = TRUE;
  12542. }
  12543. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  12544. {
  12545. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  12546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  12547. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12548. {
  12549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  12550. }
  12551. else
  12552. {
  12553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  12554. }
  12555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  12556. isKnowKey = TRUE;
  12557. }
  12558. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  12559. {
  12560. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  12561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  12562. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12563. {
  12564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  12565. }
  12566. else
  12567. {
  12568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  12569. }
  12570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  12571. isKnowKey = TRUE;
  12572. }
  12573. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  12574. {
  12575. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  12576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  12577. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12578. {
  12579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  12580. }
  12581. else
  12582. {
  12583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  12584. }
  12585. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  12586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  12587. isKnowKey = TRUE;
  12588. }
  12589. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  12590. {
  12591. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  12592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  12593. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12594. {
  12595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  12596. }
  12597. else
  12598. {
  12599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  12600. }
  12601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  12602. isKnowKey = TRUE;
  12603. }
  12604. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  12605. {
  12606. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  12607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  12608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12609. {
  12610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  12611. }
  12612. else
  12613. {
  12614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  12615. }
  12616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  12617. isKnowKey = TRUE;
  12618. }
  12619. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  12620. {
  12621. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  12622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  12623. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12624. {
  12625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12626. }
  12627. else
  12628. {
  12629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12630. }
  12631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  12632. isKnowKey = TRUE;
  12633. }
  12634. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  12635. {
  12636. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  12637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  12638. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12639. {
  12640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12641. }
  12642. else
  12643. {
  12644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12645. }
  12646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  12647. isKnowKey = TRUE;
  12648. }
  12649. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  12650. {
  12651. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  12652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  12653. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12654. {
  12655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12656. }
  12657. else
  12658. {
  12659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12660. }
  12661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  12662. isKnowKey = TRUE;
  12663. }
  12664. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  12665. {
  12666. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  12667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  12668. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12669. {
  12670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12671. }
  12672. else
  12673. {
  12674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12675. }
  12676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  12677. isKnowKey = TRUE;
  12678. }
  12679. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  12680. {
  12681. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  12682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  12683. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12684. {
  12685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12686. }
  12687. else
  12688. {
  12689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12690. }
  12691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  12692. isKnowKey = TRUE;
  12693. }
  12694. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  12695. {
  12696. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  12697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  12698. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12699. {
  12700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  12701. }
  12702. else
  12703. {
  12704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  12705. }
  12706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  12707. isKnowKey = TRUE;
  12708. }
  12709. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  12710. {
  12711. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  12712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  12713. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12714. {
  12715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12716. }
  12717. else
  12718. {
  12719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12720. }
  12721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  12722. isKnowKey = TRUE;
  12723. }
  12724. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  12725. {
  12726. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  12727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  12728. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12729. {
  12730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  12731. }
  12732. else
  12733. {
  12734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  12735. }
  12736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  12737. isKnowKey = TRUE;
  12738. }
  12739. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  12740. {
  12741. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  12742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  12743. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12744. {
  12745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12746. }
  12747. else
  12748. {
  12749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12750. }
  12751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  12752. isKnowKey = TRUE;
  12753. }
  12754. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  12755. {
  12756. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  12757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  12758. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12759. {
  12760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  12761. }
  12762. else
  12763. {
  12764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  12765. }
  12766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  12767. isKnowKey = TRUE;
  12768. }
  12769. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  12770. {
  12771. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  12772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  12773. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12774. {
  12775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  12776. }
  12777. else
  12778. {
  12779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  12780. }
  12781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  12782. isKnowKey = TRUE;
  12783. }
  12784. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  12785. {
  12786. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  12787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  12788. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12789. {
  12790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12791. }
  12792. else
  12793. {
  12794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12795. }
  12796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  12797. isKnowKey = TRUE;
  12798. }
  12799. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  12800. {
  12801. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  12802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  12803. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12804. {
  12805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12806. }
  12807. else
  12808. {
  12809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12810. }
  12811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12812. isKnowKey = TRUE;
  12813. }
  12814. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  12815. {
  12816. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  12817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  12818. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12819. {
  12820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  12821. }
  12822. else
  12823. {
  12824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  12825. }
  12826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  12827. isKnowKey = TRUE;
  12828. }
  12829. /*
  12830. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  12831. {
  12832. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  12833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  12834. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  12835. {
  12836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  12837. }
  12838. else
  12839. {
  12840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  12841. }
  12842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  12843. isKnowKey = TRUE;
  12844. }*/
  12845. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  12846. {
  12847. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  12848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  12849. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12850. {
  12851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  12852. }
  12853. else
  12854. {
  12855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  12856. }
  12857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  12858. isKnowKey = TRUE;
  12859. }
  12860. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  12861. {
  12862. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  12863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  12864. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  12865. {
  12866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  12867. }
  12868. else
  12869. {
  12870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  12871. }
  12872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  12873. isKnowKey = TRUE;
  12874. }
  12875. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  12876. {
  12877. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  12878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  12879. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12880. {
  12881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  12882. }
  12883. else
  12884. {
  12885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  12886. }
  12887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  12888. isKnowKey = TRUE;
  12889. }
  12890. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  12891. {
  12892. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  12893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  12894. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12895. {
  12896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  12897. }
  12898. else
  12899. {
  12900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  12901. }
  12902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  12903. isKnowKey = TRUE;
  12904. }
  12905. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  12906. {
  12907. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  12908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  12909. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  12910. {
  12911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  12912. }
  12913. else
  12914. {
  12915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  12916. }
  12917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  12918. isKnowKey = TRUE;
  12919. }
  12920. #if 1
  12921. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  12922. {
  12923. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  12924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  12925. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12926. {
  12927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12928. }
  12929. else
  12930. {
  12931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12932. }
  12933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12934. isKnowKey = TRUE;
  12935. }
  12936. #endif
  12937. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  12938. {
  12939. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  12940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  12941. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12942. {
  12943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12944. }
  12945. else
  12946. {
  12947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12948. }
  12949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  12950. isKnowKey = TRUE;
  12951. }
  12952. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  12953. {
  12954. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  12955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  12956. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12957. {
  12958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12959. }
  12960. else
  12961. {
  12962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12963. }
  12964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  12965. isKnowKey = TRUE;
  12966. }
  12967. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  12968. {
  12969. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  12970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  12971. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12972. {
  12973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  12974. }
  12975. else
  12976. {
  12977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  12978. }
  12979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12980. isKnowKey = TRUE;
  12981. }
  12982. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  12983. {
  12984. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  12985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  12986. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12987. {
  12988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  12989. }
  12990. else
  12991. {
  12992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  12993. }
  12994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12995. isKnowKey = TRUE;
  12996. }
  12997. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  12998. {
  12999. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  13000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  13001. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13002. {
  13003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  13004. }
  13005. else
  13006. {
  13007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13008. }
  13009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13010. isKnowKey = TRUE;
  13011. }
  13012. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13013. {
  13014. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13016. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13017. {
  13018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13019. }
  13020. else
  13021. {
  13022. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13023. }
  13024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13025. isKnowKey = TRUE;
  13026. }
  13027. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13028. {
  13029. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13031. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13032. {
  13033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13034. }
  13035. else
  13036. {
  13037. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13038. }
  13039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13040. isKnowKey = TRUE;
  13041. }
  13042. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13043. {
  13044. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13046. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13047. {
  13048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13049. }
  13050. else
  13051. {
  13052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13053. }
  13054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13055. isKnowKey = TRUE;
  13056. }
  13057. //=========================================================
  13058. if(!isEmpty && !isKnowKey)
  13059. {
  13060. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13061. strcpy(unknownkey[UnknownKeynum], keyReq);
  13062. UnknownKeynum = UnknownKeynum + 1;
  13063. }
  13064. }
  13065. void processUnkownKey(void)
  13066. {
  13067. DEBUG_INFO("processUnkownKey...\n");
  13068. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13069. for(int index=0; index < UnknownKeynum; index++)
  13070. {
  13071. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13072. {
  13073. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13074. }
  13075. }
  13076. }
  13077. int setKeyValue(char *key, char *value)
  13078. {
  13079. int isSuccess = NotSupported;
  13080. int check_ascii=0;
  13081. char str[256]={0};
  13082. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13083. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13084. {
  13085. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13086. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13087. {
  13088. strcpy(str, (const char*)value);
  13089. for(int i = 0; str[i]; i++){
  13090. str[i] = tolower(str[i]);
  13091. }
  13092. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13093. isSuccess = ConfigurationStatus_Accepted;
  13094. }
  13095. else
  13096. {
  13097. isSuccess = ConfigurationStatus_Rejected;
  13098. }
  13099. }
  13100. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13101. {
  13102. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13103. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13104. {
  13105. strcpy(str, (const char*)value);
  13106. for(int i = 0; str[i]; i++){
  13107. str[i] = tolower(str[i]);
  13108. }
  13109. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13110. isSuccess = ConfigurationStatus_Accepted;
  13111. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  13112. }
  13113. else
  13114. {
  13115. isSuccess = ConfigurationStatus_Rejected;
  13116. }
  13117. }
  13118. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  13119. {
  13120. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13121. {
  13122. strcpy(str, (const char*)value);
  13123. for(int i = 0; str[i]; i++)
  13124. {
  13125. str[i] = tolower(str[i]);
  13126. }
  13127. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  13128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13129. isSuccess = ConfigurationStatus_Accepted;
  13130. }
  13131. else
  13132. {
  13133. isSuccess = ConfigurationStatus_Rejected;
  13134. }
  13135. }
  13136. if(strcmp(key, "BlinkRepeat") == 0)
  13137. {
  13138. //Charger.BlinkRepeat = Integer.parseInt(value);
  13139. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13140. {
  13141. check_ascii = value[0];
  13142. if( (check_ascii < 48) || (check_ascii > 57) )
  13143. {
  13144. isSuccess = ConfigurationStatus_Rejected;
  13145. }
  13146. else
  13147. {
  13148. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  13149. isSuccess = ConfigurationStatus_Accepted;
  13150. }
  13151. }
  13152. else
  13153. {
  13154. isSuccess = ConfigurationStatus_Rejected;
  13155. }
  13156. }
  13157. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  13158. {
  13159. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13160. {
  13161. check_ascii = value[0];
  13162. if( (check_ascii < 48) || (check_ascii > 57) )
  13163. {
  13164. isSuccess = ConfigurationStatus_Rejected;
  13165. }
  13166. else
  13167. {
  13168. if((atoi(value) == 0) || (atoi(value) >= 10))
  13169. {
  13170. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  13171. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  13172. isSuccess = ConfigurationStatus_Accepted;
  13173. }
  13174. else
  13175. isSuccess = ConfigurationStatus_Rejected;
  13176. }
  13177. }
  13178. else
  13179. {
  13180. isSuccess = ConfigurationStatus_Rejected;
  13181. }
  13182. }
  13183. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13184. {
  13185. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13186. {
  13187. check_ascii = value[0];
  13188. if( (check_ascii < 48) || (check_ascii > 57) )
  13189. {
  13190. isSuccess = ConfigurationStatus_Rejected;
  13191. }
  13192. else
  13193. {
  13194. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13195. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13196. isSuccess = ConfigurationStatus_Accepted;
  13197. }
  13198. }
  13199. else
  13200. {
  13201. isSuccess = ConfigurationStatus_Rejected;
  13202. }
  13203. }
  13204. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13205. {
  13206. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13207. {
  13208. check_ascii = value[0];
  13209. if( (check_ascii < 48) || (check_ascii > 57) )
  13210. {
  13211. isSuccess = ConfigurationStatus_Rejected;
  13212. }
  13213. else
  13214. {
  13215. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13216. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13217. isSuccess = ConfigurationStatus_Accepted;
  13218. }
  13219. }
  13220. else
  13221. {
  13222. isSuccess = ConfigurationStatus_Rejected;
  13223. }
  13224. }
  13225. if(strcmp(key, "HeartbeatInterval") == 0)
  13226. {
  13227. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13228. {
  13229. check_ascii = value[0];
  13230. if( (check_ascii < 48) || (check_ascii > 57) )
  13231. {
  13232. isSuccess = ConfigurationStatus_Rejected;
  13233. }
  13234. else
  13235. {
  13236. if((atoi(value) == 0) || (atoi(value) >= 10))
  13237. {
  13238. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13239. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13240. HeartBeatWaitTime = atoi(value);
  13241. isSuccess = ConfigurationStatus_Accepted;
  13242. }
  13243. else
  13244. {
  13245. isSuccess = ConfigurationStatus_Rejected;
  13246. }
  13247. }
  13248. }
  13249. else
  13250. {
  13251. isSuccess = ConfigurationStatus_Rejected;
  13252. }
  13253. }
  13254. if(strcmp(key, "LightIntensity") == 0)
  13255. {
  13256. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13257. {
  13258. check_ascii = value[0];
  13259. if( (check_ascii < 48) || (check_ascii > 57) )
  13260. {
  13261. isSuccess = ConfigurationStatus_Rejected;
  13262. }
  13263. else
  13264. {
  13265. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13266. isSuccess = ConfigurationStatus_Accepted;
  13267. }
  13268. }
  13269. else
  13270. {
  13271. isSuccess = ConfigurationStatus_Rejected;
  13272. }
  13273. }
  13274. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13275. {
  13276. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13277. {
  13278. strcpy(str, (const char*)value);
  13279. for(int i = 0; str[i]; i++)
  13280. {
  13281. str[i] = tolower(str[i]);
  13282. }
  13283. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13284. isSuccess = ConfigurationStatus_Accepted;
  13285. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13286. }
  13287. else
  13288. {
  13289. isSuccess = ConfigurationStatus_Rejected;
  13290. }
  13291. }
  13292. if(strcmp(key, "LocalPreAuthorize") == 0)
  13293. {
  13294. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13295. {
  13296. strcpy(str, (const char*)value);
  13297. for(int i = 0; str[i]; i++)
  13298. {
  13299. str[i] = tolower(str[i]);
  13300. }
  13301. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13302. isSuccess = ConfigurationStatus_Accepted;
  13303. }
  13304. else
  13305. {
  13306. isSuccess = ConfigurationStatus_Rejected;
  13307. }
  13308. }
  13309. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13310. {
  13311. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13312. {
  13313. check_ascii = value[0];
  13314. if( (check_ascii < 48) || (check_ascii > 57) )
  13315. {
  13316. isSuccess = ConfigurationStatus_Rejected;
  13317. }
  13318. else
  13319. {
  13320. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13321. isSuccess = ConfigurationStatus_Accepted;
  13322. }
  13323. }
  13324. else
  13325. {
  13326. isSuccess = ConfigurationStatus_Rejected;
  13327. }
  13328. }
  13329. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13330. {
  13331. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13332. {
  13333. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13334. isSuccess = ConfigurationStatus_Accepted;
  13335. }
  13336. else
  13337. {
  13338. isSuccess = ConfigurationStatus_Rejected;
  13339. }
  13340. }
  13341. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13342. {
  13343. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13344. {
  13345. check_ascii = value[0];
  13346. if( (check_ascii < 48) || (check_ascii > 57) )
  13347. {
  13348. isSuccess = ConfigurationStatus_Rejected;
  13349. }
  13350. else
  13351. {
  13352. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13353. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13354. isSuccess = ConfigurationStatus_Accepted;
  13355. }
  13356. }
  13357. else
  13358. {
  13359. isSuccess = ConfigurationStatus_Rejected;
  13360. }
  13361. }
  13362. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13363. {
  13364. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13365. {
  13366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13367. isSuccess = ConfigurationStatus_Accepted;
  13368. }
  13369. else
  13370. {
  13371. isSuccess = ConfigurationStatus_Rejected;
  13372. }
  13373. }
  13374. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13375. {
  13376. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13377. {
  13378. check_ascii = value[0];
  13379. if( (check_ascii < 48) || (check_ascii > 57) )
  13380. {
  13381. isSuccess = ConfigurationStatus_Rejected;
  13382. }
  13383. else
  13384. {
  13385. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13387. isSuccess = ConfigurationStatus_Accepted;
  13388. }
  13389. }
  13390. else
  13391. {
  13392. isSuccess = ConfigurationStatus_Rejected;
  13393. }
  13394. }
  13395. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13396. {
  13397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13398. {
  13399. check_ascii = value[0];
  13400. if( (check_ascii < 48) || (check_ascii > 57) )
  13401. {
  13402. isSuccess = ConfigurationStatus_Rejected;
  13403. }
  13404. else
  13405. {
  13406. if((atoi(value) == 0) || (atoi(value) >= 10))
  13407. {
  13408. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13409. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  13410. isSuccess = ConfigurationStatus_Accepted;
  13411. }
  13412. else
  13413. {
  13414. isSuccess = ConfigurationStatus_Rejected;
  13415. }
  13416. }
  13417. }
  13418. else
  13419. {
  13420. isSuccess = ConfigurationStatus_Rejected;
  13421. }
  13422. }
  13423. if(strcmp(key, "MinimumStatusDuration") == 0)
  13424. {
  13425. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13426. {
  13427. check_ascii = value[0];
  13428. if( (check_ascii < 48) || (check_ascii > 57) )
  13429. {
  13430. isSuccess = ConfigurationStatus_Rejected;
  13431. }
  13432. else
  13433. {
  13434. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  13435. {
  13436. isSuccess = ConfigurationStatus_Rejected;
  13437. }
  13438. else
  13439. {
  13440. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  13441. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  13442. server_cycle_Status = atoi(value); //StatusNotification Cycle
  13443. isSuccess = ConfigurationStatus_Accepted;
  13444. }
  13445. }
  13446. }
  13447. else
  13448. {
  13449. isSuccess = ConfigurationStatus_Rejected;
  13450. }
  13451. }
  13452. if(strcmp(key, "NumberOfConnectors") == 0)
  13453. {
  13454. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13455. {
  13456. check_ascii = value[0];
  13457. if( (check_ascii < 48) || (check_ascii > 57) )
  13458. {
  13459. isSuccess = ConfigurationStatus_Rejected;
  13460. }
  13461. else
  13462. {
  13463. //Charger.ResetRetries = Integer.parseInt(value);
  13464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  13465. isSuccess = ConfigurationStatus_Accepted;
  13466. }
  13467. }
  13468. else
  13469. {
  13470. isSuccess = ConfigurationStatus_Rejected;
  13471. }
  13472. }
  13473. if(strcmp(key, "ResetRetries") == 0)
  13474. {
  13475. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13476. {
  13477. check_ascii = value[0];
  13478. if( (check_ascii < 48) || (check_ascii > 57) )
  13479. {
  13480. isSuccess = ConfigurationStatus_Rejected;
  13481. }
  13482. else
  13483. {
  13484. //Charger.ResetRetries = Integer.parseInt(value);
  13485. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  13486. isSuccess = ConfigurationStatus_Accepted;
  13487. }
  13488. }
  13489. else
  13490. {
  13491. isSuccess = ConfigurationStatus_Rejected;
  13492. }
  13493. }
  13494. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  13495. {
  13496. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13497. {
  13498. strcpy(str, (const char*)value);
  13499. for(int i = 0; str[i]; i++)
  13500. {
  13501. str[i] = tolower(str[i]);
  13502. }
  13503. if(strcmp(str, "notapplicable")== 0)
  13504. {
  13505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  13506. isSuccess = ConfigurationStatus_Accepted;
  13507. }
  13508. else if(strcmp(str, "unknown")== 0)
  13509. {
  13510. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  13511. isSuccess = ConfigurationStatus_Accepted;
  13512. }
  13513. else if(strcmp(str, "rst")== 0)
  13514. {
  13515. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  13516. isSuccess = ConfigurationStatus_Accepted;
  13517. }
  13518. else if(strcmp(str, "rts")== 0)
  13519. {
  13520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  13521. isSuccess = ConfigurationStatus_Accepted;
  13522. }
  13523. else if(strcmp(str, "srt")== 0)
  13524. {
  13525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  13526. isSuccess = ConfigurationStatus_Accepted;
  13527. }
  13528. else if(strcmp(str, "str")== 0)
  13529. {
  13530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  13531. isSuccess = ConfigurationStatus_Accepted;
  13532. }
  13533. else if(strcmp(str, "trs")== 0)
  13534. {
  13535. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  13536. isSuccess = ConfigurationStatus_Accepted;
  13537. }
  13538. else if(strcmp(str, "tsr")== 0)
  13539. {
  13540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  13541. isSuccess = ConfigurationStatus_Accepted;
  13542. }
  13543. else
  13544. {
  13545. isSuccess = ConfigurationStatus_Rejected;
  13546. }
  13547. }
  13548. else
  13549. {
  13550. isSuccess = ConfigurationStatus_Rejected;
  13551. }
  13552. }
  13553. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  13554. {
  13555. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13556. {
  13557. check_ascii = value[0];
  13558. if( (check_ascii < 48) || (check_ascii > 57) )
  13559. {
  13560. isSuccess = ConfigurationStatus_Rejected;
  13561. }
  13562. else
  13563. {
  13564. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  13565. isSuccess = ConfigurationStatus_Accepted;
  13566. }
  13567. }
  13568. else
  13569. {
  13570. isSuccess = ConfigurationStatus_Rejected;
  13571. }
  13572. }
  13573. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  13574. {
  13575. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13576. {
  13577. strcpy(str, (const char*)value);
  13578. for(int i = 0; str[i]; i++)
  13579. {
  13580. str[i] = tolower(str[i]);
  13581. }
  13582. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13583. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13584. isSuccess = ConfigurationStatus_Accepted;
  13585. }
  13586. else
  13587. {
  13588. isSuccess = ConfigurationStatus_Rejected;
  13589. }
  13590. }
  13591. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  13592. {
  13593. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13594. {
  13595. strcpy(str, (const char*)value);
  13596. for(int i = 0; str[i]; i++)
  13597. {
  13598. str[i] = tolower(str[i]);
  13599. }
  13600. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  13601. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13602. isSuccess = ConfigurationStatus_Accepted;
  13603. }
  13604. else
  13605. {
  13606. isSuccess = ConfigurationStatus_Rejected;
  13607. }
  13608. }
  13609. if(strcmp(key, "StopTxnAlignedData") == 0)
  13610. {
  13611. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13612. {
  13613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  13614. isSuccess = ConfigurationStatus_Accepted;
  13615. }
  13616. else
  13617. {
  13618. isSuccess = ConfigurationStatus_Rejected;
  13619. }
  13620. }
  13621. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  13622. {
  13623. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13624. {
  13625. check_ascii = value[0];
  13626. if( (check_ascii < 48) || (check_ascii > 57) )
  13627. {
  13628. isSuccess = ConfigurationStatus_Rejected;
  13629. }
  13630. else
  13631. {
  13632. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  13633. isSuccess = ConfigurationStatus_Accepted;
  13634. }
  13635. }
  13636. else
  13637. {
  13638. isSuccess = ConfigurationStatus_Rejected;
  13639. }
  13640. }
  13641. if(strcmp(key, "StopTxnSampledData") == 0)
  13642. {
  13643. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13644. {
  13645. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  13646. isSuccess = ConfigurationStatus_Accepted;
  13647. }
  13648. else
  13649. {
  13650. isSuccess = ConfigurationStatus_Rejected;
  13651. }
  13652. }
  13653. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  13654. {
  13655. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13656. {
  13657. check_ascii = value[0];
  13658. if( (check_ascii < 48) || (check_ascii > 57) )
  13659. {
  13660. isSuccess = ConfigurationStatus_Rejected;
  13661. }
  13662. else
  13663. {
  13664. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  13665. isSuccess = ConfigurationStatus_Accepted;
  13666. }
  13667. }
  13668. else
  13669. {
  13670. isSuccess = ConfigurationStatus_Rejected;
  13671. }
  13672. }
  13673. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  13674. {
  13675. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13676. {
  13677. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  13678. isSuccess = ConfigurationStatus_Accepted;
  13679. }
  13680. else
  13681. {
  13682. isSuccess = ConfigurationStatus_Rejected;
  13683. }
  13684. }
  13685. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  13686. {
  13687. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13688. {
  13689. check_ascii = value[0];
  13690. if( (check_ascii < 48) || (check_ascii > 57) )
  13691. {
  13692. isSuccess = ConfigurationStatus_Rejected;
  13693. }
  13694. else
  13695. {
  13696. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  13697. isSuccess = ConfigurationStatus_Accepted;
  13698. }
  13699. }
  13700. else
  13701. {
  13702. isSuccess = ConfigurationStatus_Rejected;
  13703. }
  13704. }
  13705. if(strcmp(key, "TransactionMessageAttempts") == 0)
  13706. {
  13707. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13708. {
  13709. check_ascii = value[0];
  13710. if( (check_ascii < 48) || (check_ascii > 57) )
  13711. {
  13712. isSuccess = ConfigurationStatus_Rejected;
  13713. }
  13714. else
  13715. {
  13716. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  13717. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  13718. TransactionMessageAttemptsValue = atoi(value);
  13719. isSuccess = ConfigurationStatus_Accepted;
  13720. }
  13721. }
  13722. else
  13723. {
  13724. isSuccess = ConfigurationStatus_Rejected;
  13725. }
  13726. }
  13727. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  13728. {
  13729. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13730. {
  13731. check_ascii = value[0];
  13732. if( (check_ascii < 48) || (check_ascii > 57) )
  13733. {
  13734. isSuccess = ConfigurationStatus_Rejected;
  13735. }
  13736. else
  13737. {
  13738. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  13739. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  13740. TransactionMessageRetryIntervalValue = atoi(value);
  13741. isSuccess = ConfigurationStatus_Accepted;
  13742. }
  13743. }
  13744. else
  13745. {
  13746. isSuccess = ConfigurationStatus_Rejected;
  13747. }
  13748. }
  13749. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  13750. {
  13751. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13752. {
  13753. strcpy(str, (const char*)value);
  13754. for(int i = 0; str[i]; i++)
  13755. {
  13756. str[i] = tolower(str[i]);
  13757. }
  13758. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13759. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13760. isSuccess = ConfigurationStatus_Accepted;
  13761. }
  13762. else
  13763. {
  13764. isSuccess = ConfigurationStatus_Rejected;
  13765. }
  13766. }
  13767. if(strcmp(key, "WebSocketPingInterval") == 0)
  13768. {
  13769. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13770. {
  13771. check_ascii = value[0];
  13772. if( (check_ascii < 48) || (check_ascii > 57) )
  13773. {
  13774. isSuccess = ConfigurationStatus_Rejected;
  13775. }
  13776. else
  13777. {
  13778. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  13779. isSuccess = ConfigurationStatus_Accepted;
  13780. }
  13781. }
  13782. else
  13783. {
  13784. isSuccess = ConfigurationStatus_Rejected;
  13785. }
  13786. }
  13787. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  13788. {
  13789. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13790. {
  13791. strcpy(str, (const char*)value);
  13792. for(int i = 0; str[i]; i++)
  13793. {
  13794. str[i] = tolower(str[i]);
  13795. }
  13796. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13797. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13798. isSuccess = ConfigurationStatus_Accepted;
  13799. }
  13800. else
  13801. {
  13802. isSuccess = ConfigurationStatus_Rejected;
  13803. }
  13804. }
  13805. if(strcmp(key, "AuthorizationKey") == 0)
  13806. {
  13807. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  13808. {
  13809. strcpy(str, (const char*)value);
  13810. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  13811. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13812. isSuccess = ConfigurationStatus_Accepted;
  13813. }
  13814. else
  13815. {
  13816. isSuccess = ConfigurationStatus_Rejected;
  13817. }
  13818. }
  13819. if(strcmp(key, "SecurityProfile") == 0)
  13820. {
  13821. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13822. {
  13823. check_ascii = value[0];
  13824. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  13825. {
  13826. isSuccess = ConfigurationStatus_Rejected;
  13827. }
  13828. else if(check_ascii == 0x33)
  13829. {
  13830. isSuccess = NotSupported;
  13831. }
  13832. else
  13833. {
  13834. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  13835. {
  13836. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  13837. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  13838. isSuccess = ConfigurationStatus_Accepted;
  13839. }
  13840. else
  13841. isSuccess = ConfigurationStatus_Rejected;
  13842. }
  13843. }
  13844. else
  13845. {
  13846. isSuccess = ConfigurationStatus_Rejected;
  13847. }
  13848. }
  13849. if(strcmp(key, "DefaultPrice") == 0)
  13850. {
  13851. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  13852. {
  13853. strcpy(str, (const char*)value);
  13854. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  13855. isSuccess = ConfigurationStatus_Accepted;
  13856. }
  13857. else
  13858. {
  13859. isSuccess = ConfigurationStatus_Rejected;
  13860. }
  13861. }
  13862. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  13863. {
  13864. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13865. {
  13866. strcpy(str, (const char*)value);
  13867. for(int i = 0; str[i]; i++)
  13868. {
  13869. str[i] = tolower(str[i]);
  13870. }
  13871. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13873. isSuccess = ConfigurationStatus_Accepted;
  13874. }
  13875. else
  13876. {
  13877. isSuccess = ConfigurationStatus_Rejected;
  13878. }
  13879. }
  13880. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  13881. {
  13882. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13883. {
  13884. strcpy(str, (const char*)value);
  13885. for(int i = 0; str[i]; i++)
  13886. {
  13887. str[i] = tolower(str[i]);
  13888. }
  13889. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13890. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13891. isSuccess = ConfigurationStatus_Accepted;
  13892. }
  13893. else
  13894. {
  13895. isSuccess = ConfigurationStatus_Rejected;
  13896. }
  13897. }
  13898. #if 0
  13899. //For OCPP Test Case
  13900. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  13901. {
  13902. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13903. {
  13904. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  13905. isSuccess = ConfigurationStatus_Accepted;
  13906. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13907. }
  13908. else
  13909. {
  13910. isSuccess = ConfigurationStatus_Rejected;
  13911. }
  13912. }
  13913. #endif
  13914. #if 1
  13915. if(strcmp(key, "LocalAuthListEnabled") == 0)
  13916. {
  13917. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13918. {
  13919. strcpy(str, (const char*)value);
  13920. for(int i = 0; str[i]; i++)
  13921. {
  13922. str[i] = tolower(str[i]);
  13923. }
  13924. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13925. isSuccess = ConfigurationStatus_Accepted;
  13926. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13927. }
  13928. else
  13929. {
  13930. isSuccess = ConfigurationStatus_Rejected;
  13931. }
  13932. }
  13933. #endif
  13934. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  13935. {
  13936. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13937. {
  13938. check_ascii = value[0];
  13939. if( (check_ascii < 48) || (check_ascii > 57) )
  13940. {
  13941. isSuccess = ConfigurationStatus_Rejected;
  13942. }
  13943. else
  13944. {
  13945. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  13946. isSuccess = ConfigurationStatus_Accepted;
  13947. }
  13948. }
  13949. else
  13950. {
  13951. isSuccess = ConfigurationStatus_Rejected;
  13952. }
  13953. }
  13954. if(strcmp(key, "SendLocalListMaxLength") == 0)
  13955. {
  13956. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13957. {
  13958. check_ascii = value[0];
  13959. if( (check_ascii < 48) || (check_ascii > 57) )
  13960. {
  13961. isSuccess = ConfigurationStatus_Rejected;
  13962. }
  13963. else
  13964. {
  13965. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  13966. isSuccess = ConfigurationStatus_Accepted;
  13967. }
  13968. }
  13969. else
  13970. {
  13971. isSuccess = ConfigurationStatus_Rejected;
  13972. }
  13973. }
  13974. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  13975. {
  13976. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13977. {
  13978. strcpy(str, (const char*)value);
  13979. for(int i = 0; str[i]; i++)
  13980. {
  13981. str[i] = tolower(str[i]);
  13982. }
  13983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13984. isSuccess = ConfigurationStatus_Accepted;
  13985. }
  13986. else
  13987. {
  13988. isSuccess = ConfigurationStatus_Rejected;
  13989. }
  13990. }
  13991. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  13992. {
  13993. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13994. {
  13995. check_ascii = value[0];
  13996. if( (check_ascii < 48) || (check_ascii > 57) )
  13997. {
  13998. isSuccess = ConfigurationStatus_Rejected;
  13999. }
  14000. else
  14001. {
  14002. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  14003. isSuccess = ConfigurationStatus_Accepted;
  14004. }
  14005. }
  14006. else
  14007. {
  14008. isSuccess = ConfigurationStatus_Rejected;
  14009. }
  14010. }
  14011. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14012. {
  14013. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14014. {
  14015. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14016. isSuccess = ConfigurationStatus_Accepted;
  14017. }
  14018. else
  14019. {
  14020. isSuccess = ConfigurationStatus_Rejected;
  14021. }
  14022. }
  14023. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14024. {
  14025. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14026. {
  14027. check_ascii = value[0];
  14028. if( (check_ascii < 48) || (check_ascii > 57) )
  14029. {
  14030. isSuccess = ConfigurationStatus_Rejected;
  14031. }
  14032. else
  14033. {
  14034. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14035. isSuccess = ConfigurationStatus_Accepted;
  14036. }
  14037. }
  14038. else
  14039. {
  14040. isSuccess = ConfigurationStatus_Rejected;
  14041. }
  14042. }
  14043. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14044. {
  14045. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14046. {
  14047. strcpy(str, (const char*)value);
  14048. for(int i = 0; str[i]; i++)
  14049. {
  14050. str[i] = tolower(str[i]);
  14051. }
  14052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14053. isSuccess = ConfigurationStatus_Accepted;
  14054. }
  14055. else
  14056. {
  14057. isSuccess = ConfigurationStatus_Rejected;
  14058. }
  14059. }
  14060. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14061. {
  14062. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].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. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14072. isSuccess = ConfigurationStatus_Accepted;
  14073. }
  14074. }
  14075. else
  14076. {
  14077. isSuccess = ConfigurationStatus_Rejected;
  14078. }
  14079. }
  14080. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14081. return isSuccess;
  14082. }
  14083. int TransactionMessageAttemptsGet(void)
  14084. {
  14085. return TransactionMessageAttemptsValue;
  14086. }
  14087. int FirstHeartBeatResponse(void)
  14088. {
  14089. return FirstHeartBeat;
  14090. }
  14091. int TransactionMessageRetryIntervalGet(void)
  14092. {
  14093. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14094. }
  14095. int ReadHttpStatus(int sock)
  14096. {
  14097. //char c;
  14098. char buff[1024]="",*ptr=buff+1;
  14099. int bytes_received, status;
  14100. DEBUG_INFO("Begin Response ..\n");
  14101. while((bytes_received = recv(sock, ptr, 1, 0))){
  14102. if(bytes_received==-1){
  14103. perror("ReadHttpStatus");
  14104. exit(1);
  14105. }
  14106. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  14107. ptr++;
  14108. }
  14109. *ptr=0;
  14110. ptr=buff+1;
  14111. sscanf(ptr,"%*s %d ", &status);
  14112. DEBUG_INFO("%s\n",ptr);
  14113. DEBUG_INFO("status=%d\n",status);
  14114. DEBUG_INFO("End Response ..\n");
  14115. return (bytes_received>0)?status:0;
  14116. }
  14117. //the only filed that it parsed is 'Content-Length'
  14118. int ParseHeader(int sock)
  14119. {
  14120. //char c;
  14121. char buff[1024]="",*ptr=buff+4;
  14122. int bytes_received;
  14123. DEBUG_INFO("Begin HEADER ..\n");
  14124. while((bytes_received = recv(sock, ptr, 1, 0))){
  14125. if(bytes_received==-1){
  14126. perror("Parse Header");
  14127. exit(1);
  14128. }
  14129. if(
  14130. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  14131. (ptr[-1]=='\r') && (*ptr=='\n' )
  14132. ) break;
  14133. ptr++;
  14134. }
  14135. *ptr=0;
  14136. ptr=buff+4;
  14137. //printf("%s",ptr);
  14138. if(bytes_received){
  14139. ptr=strstr(ptr,"Content-Length:");
  14140. if(ptr){
  14141. sscanf(ptr,"%*s %d",&bytes_received);
  14142. }else
  14143. bytes_received=-1; //unknown size
  14144. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  14145. }
  14146. DEBUG_INFO("End HEADER ..\n");
  14147. return bytes_received ;
  14148. }
  14149. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14150. {
  14151. int result = TRUE;
  14152. char rmFileCmd[100]={0};
  14153. char FilePath[100]={0};
  14154. char ftpbuf[200];
  14155. int systemresult;
  14156. //DEBUG_INFO("filename=%s\n",filename);
  14157. //DEBUG_INFO("url=%s\n",url);
  14158. sprintf(FilePath,"/mnt/%s",filename);
  14159. system("ping 8.8.8.8 &");
  14160. if((access(FilePath,F_OK))!=-1)
  14161. {
  14162. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14163. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14164. system(rmFileCmd);
  14165. }
  14166. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14167. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14168. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14169. systemresult = system(ftpbuf);
  14170. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14171. if(systemresult != 0)
  14172. {
  14173. DEBUG_INFO("http DownLoad error!\n");
  14174. result = FALSE;
  14175. }
  14176. system("pkill ping");
  14177. return result;
  14178. }
  14179. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14180. {
  14181. int result = TRUE;
  14182. char rmFileCmd[100]={0};
  14183. char FilePath[100]={0};
  14184. char ftpbuf[200];
  14185. int systemresult;
  14186. //char temp[100];
  14187. sprintf(FilePath,"/mnt/%s",filename);
  14188. system("ping 8.8.8.8 &");
  14189. if((access(FilePath,F_OK))!=-1)
  14190. {
  14191. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14192. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14193. system(rmFileCmd);
  14194. }
  14195. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14196. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14197. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14198. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14199. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14200. systemresult = system(ftpbuf);
  14201. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14202. if(systemresult != 0)
  14203. {
  14204. printf("wget error!\n");
  14205. result = FALSE;
  14206. }
  14207. system("pkill ping");
  14208. return result;
  14209. }
  14210. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14211. {
  14212. char rmFileCmd[100]={0};
  14213. char FilePath[100]={0};
  14214. char buf[512];
  14215. int systemresult = 0;
  14216. //DEBUG_INFO("filename=%s\n",filename);
  14217. //DEBUG_INFO("url=%s\n",url);
  14218. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14219. if((access(FilePath,F_OK))!=-1)
  14220. {
  14221. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14222. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14223. system(rmFileCmd);
  14224. }
  14225. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14226. if(fp == NULL)
  14227. {
  14228. DEBUG_INFO("log is NULL\n");
  14229. return FALSE;
  14230. }
  14231. else
  14232. {
  14233. fprintf(fp, "%s\n", url);
  14234. fprintf(fp, "%s\n", filename);
  14235. fclose(fp);
  14236. }
  14237. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14238. if(phpFP == NULL)
  14239. {
  14240. DEBUG_INFO("PHP upload fail.\n");
  14241. return FALSE;
  14242. }
  14243. else
  14244. {
  14245. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14246. {
  14247. if(strstr(buf, "result") != NULL)
  14248. {
  14249. sscanf(buf, "result: %d", &systemresult);
  14250. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14251. }
  14252. }
  14253. pclose(phpFP);
  14254. }
  14255. if(systemresult != 1)
  14256. {
  14257. DEBUG_INFO("HTTP upload error!\n");
  14258. return FALSE;
  14259. }
  14260. return TRUE;
  14261. }
  14262. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14263. {
  14264. struct hostent* server;
  14265. char *IPbuffer;
  14266. char ftpbuf[200];
  14267. int systemresult;
  14268. // To retrieve host information
  14269. server = gethostbyname(location);
  14270. // To convert an Internet network
  14271. // address into ASCII string
  14272. IPbuffer = inet_ntoa(*((struct in_addr*)
  14273. server->h_addr_list[0]));
  14274. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14275. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14276. /* format : ftpput -u username -p passwd IP target source*/
  14277. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14278. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14279. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14280. systemresult = system(ftpbuf);
  14281. DEBUG_INFO("systemresult=%d\n",systemresult);
  14282. if(systemresult != 0)
  14283. {
  14284. DEBUG_INFO("ftpput error!\n");
  14285. return FALSE;
  14286. }
  14287. return TRUE;
  14288. }
  14289. int GetOcppServerURL()
  14290. {
  14291. int result = FALSE;
  14292. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14293. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14294. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14295. struct yuarel url;
  14296. char urlStr[512];
  14297. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  14298. {
  14299. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  14300. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14301. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14302. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  14303. if(yuarel_parse(&url, urlStr) != -1)
  14304. {
  14305. sprintf(OcppProtocol, "%s", url.scheme);
  14306. sprintf(OcppHost, "%s", url.host);
  14307. if(url.path == NULL)
  14308. OcppTempPath[0] = '\0';
  14309. else
  14310. {
  14311. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  14312. {
  14313. sprintf(OcppTempPath, "%s/", url.path);
  14314. }
  14315. else
  14316. {
  14317. sprintf(OcppTempPath, "%s", url.path);
  14318. }
  14319. }
  14320. if(url.port == 0)
  14321. {
  14322. if(strcmp(OcppProtocol, "wss") == 0)
  14323. OcppPort = 443;
  14324. else
  14325. OcppPort = 80;
  14326. }
  14327. else
  14328. OcppPort = url.port;
  14329. result = TRUE;
  14330. }
  14331. }
  14332. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  14333. {
  14334. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  14335. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14336. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14337. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  14338. if(yuarel_parse(&url, urlStr) != -1)
  14339. {
  14340. sprintf(OcppProtocol, "%s", url.scheme);
  14341. sprintf(OcppHost, "%s", url.host);
  14342. if(url.path == NULL)
  14343. OcppTempPath[0] = '\0';
  14344. else
  14345. sprintf(OcppTempPath, "%s", url.path);
  14346. if(url.port == 0)
  14347. {
  14348. if(strcmp(OcppProtocol, "wss") == 0)
  14349. OcppPort = 443;
  14350. else
  14351. OcppPort = 80;
  14352. }
  14353. else
  14354. OcppPort = url.port;
  14355. result = TRUE;
  14356. }
  14357. }
  14358. else
  14359. {
  14360. strcpy(OcppHost,"");
  14361. }
  14362. return result;
  14363. }
  14364. int GetOcppPath()
  14365. {
  14366. int result = FALSE;
  14367. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  14368. {
  14369. if(OcppTempPath == NULL)
  14370. {
  14371. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14372. }
  14373. else
  14374. {
  14375. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14376. }
  14377. result = TRUE;
  14378. goto End;
  14379. }
  14380. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  14381. {
  14382. if(OcppTempPath == NULL)
  14383. {
  14384. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  14385. }
  14386. else
  14387. {
  14388. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  14389. }
  14390. result = TRUE;
  14391. goto End;
  14392. }
  14393. else
  14394. {
  14395. strcpy(OcppPath,"");
  14396. }
  14397. End:
  14398. return result;
  14399. }
  14400. int GetOcppPort()
  14401. {
  14402. return OcppPort;
  14403. }
  14404. int GetOcppConnStatus(void)
  14405. {
  14406. return ShmOCPP16Data->OcppConnStatus;
  14407. }
  14408. void SetOcppConnStatus(uint8_t status)
  14409. {
  14410. ShmOCPP16Data->OcppConnStatus = status;
  14411. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  14412. }
  14413. int GetHeartBeatWithNOResponse(void)
  14414. {
  14415. return HeartBeatWithNOResponse;
  14416. }
  14417. void SetHeartBeatWithNOResponse(void)
  14418. {
  14419. HeartBeatWithNOResponse = 0;
  14420. }
  14421. void GetStartTransactionIdTag(int gun_index)
  14422. {
  14423. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14424. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14425. }
  14426. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14427. {
  14428. char ch;
  14429. FILE *fptr1;
  14430. int temptransactionId;
  14431. char str[100]={0};
  14432. temptransactionId = 0;
  14433. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14434. {
  14435. DEBUG_INFO("IdTag is empty.\n");
  14436. return temptransactionId;
  14437. }
  14438. /*------ Read the file ----------------*/
  14439. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  14440. if (!fptr1)
  14441. {
  14442. DEBUG_INFO("QueueTransactionId file open error.\n");
  14443. //printf(" File not found or unable to open the input file!!\n");
  14444. return temptransactionId;
  14445. }
  14446. ch=fgetc(fptr1);
  14447. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  14448. rewind(fptr1);
  14449. if(ch!=EOF)
  14450. {
  14451. // printf("%c",ch);
  14452. while (fgets(str, 100, fptr1) != NULL)
  14453. {
  14454. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14455. if(str[0]=='\0')
  14456. {
  14457. break;
  14458. }
  14459. char *revbuf[8] = {0}; // Variable store string split
  14460. int num = 0;// Quantity after string split
  14461. DEBUG_INFO("Transaction queue data= %s\n", str);
  14462. splitstring(str,",",revbuf,&num); // String split
  14463. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  14464. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  14465. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  14466. DEBUG_INFO("------------------------------\n");
  14467. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  14468. {
  14469. if(isStopTransaction)
  14470. {
  14471. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  14472. {
  14473. temptransactionId = atoi(revbuf[2]);
  14474. //break;
  14475. }
  14476. }
  14477. else
  14478. {
  14479. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  14480. {
  14481. temptransactionId = atoi(revbuf[2]);
  14482. //break;
  14483. }
  14484. }
  14485. }
  14486. }
  14487. }
  14488. else
  14489. DEBUG_INFO("EOF\n");
  14490. fclose(fptr1);
  14491. /*------- End of reading ---------------*/
  14492. return temptransactionId;
  14493. }
  14494. void SetTransactionIdZero(int transactionId)
  14495. {
  14496. char ch;
  14497. FILE *fptr1, *fptr2;
  14498. int temptransactionId = 0;
  14499. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  14500. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  14501. if (!fptr1)
  14502. {
  14503. //printf(" File not found or unable to open the input file!!\n");
  14504. return ;
  14505. }
  14506. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  14507. if (!fptr2)
  14508. {
  14509. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  14510. fclose(fptr1);
  14511. return ;
  14512. }
  14513. ch=fgetc(fptr1);
  14514. rewind(fptr1);
  14515. if(ch!=EOF)
  14516. {
  14517. // copy all contents to the temporary file except the specific line
  14518. while (fgets(str, 100, fptr1) != NULL)
  14519. {
  14520. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14521. if(str[0]=='\0')
  14522. {
  14523. break;
  14524. }
  14525. char *revbuf[8] = {0};
  14526. int num = 0;
  14527. strcpy(strtemp, str);
  14528. splitstring(str,",",revbuf,&num);
  14529. if(revbuf[2][0] != '\0')
  14530. {
  14531. temptransactionId = atoi(revbuf[2]);
  14532. if(transactionId != temptransactionId)
  14533. {
  14534. fprintf(fptr2, "%s\n", strtemp);
  14535. }
  14536. }
  14537. }
  14538. }
  14539. fclose(fptr1);
  14540. fclose(fptr2);
  14541. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  14542. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  14543. /*------ Read the file ----------------*/
  14544. }
  14545. int InternetDisconnect(void)
  14546. {
  14547. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  14548. }
  14549. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14550. void storeTempStopTransaction(int gun_index)
  14551. {
  14552. char guid[37]={0};
  14553. int tempIndex = 0;
  14554. char TempStopTransaction[256];
  14555. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14556. DEBUG_INFO("storeTempStopTransaction...\n");
  14557. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  14558. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  14559. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  14560. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14561. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14562. {
  14563. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14564. {
  14565. tempIndex = ((gun_index==2) ? 1: 0);
  14566. }
  14567. else
  14568. {
  14569. tempIndex = gun_index;
  14570. }
  14571. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14572. {
  14573. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14574. {
  14575. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  14576. }
  14577. }// END OF CHAdeMO_QUANTITY
  14578. }
  14579. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14580. {
  14581. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14582. {
  14583. tempIndex = ((gun_index==2) ? 1: 0);
  14584. }
  14585. else
  14586. {
  14587. tempIndex = gun_index;
  14588. }
  14589. for (int index = 0; index < CCS_QUANTITY; index++)
  14590. {
  14591. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14592. {
  14593. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  14594. }
  14595. }// END OF CCS_QUANTITY
  14596. }
  14597. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14598. {
  14599. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14600. {
  14601. tempIndex = ((gun_index==2) ? 1: 0);
  14602. }
  14603. else
  14604. {
  14605. tempIndex = gun_index;
  14606. }
  14607. for (int index = 0; index < GB_QUANTITY; index++)
  14608. {
  14609. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14610. {
  14611. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  14612. }
  14613. }// END OF GB_QUANTITY
  14614. }
  14615. else if(gunType[gun_index] == GUN_TYPE_DO)
  14616. {
  14617. tempIndex = gun_index;
  14618. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14619. {
  14620. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14621. {
  14622. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  14623. }
  14624. }
  14625. }
  14626. else
  14627. {
  14628. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14629. {
  14630. tempIndex = 2;
  14631. }
  14632. else
  14633. {
  14634. tempIndex = gun_index;
  14635. }
  14636. for (int index = 0; index < AC_QUANTITY; index++)
  14637. {
  14638. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14639. {
  14640. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  14641. }
  14642. }// END OF AC_QUANTITY
  14643. }
  14644. //Stop Transaction Time
  14645. struct timeval tmnow;
  14646. struct tm *tm;
  14647. char buf[28];//, usec_buf[6];
  14648. gettimeofday(&tmnow, NULL);
  14649. time_t t;
  14650. t = time(NULL);
  14651. /*UTC time and date*/
  14652. tm = gmtime(&t);
  14653. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  14654. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  14655. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  14656. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  14657. random_uuid(guid);
  14658. /***********************************transactionData******************************************************/
  14659. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  14660. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  14661. //=================================
  14662. //1. Transaction_Begin
  14663. //=================================
  14664. //============================== Energy.Active.Import.Interval ===========================================
  14665. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14666. {
  14667. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  14668. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  14670. 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*/]);
  14671. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14672. 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))
  14673. {
  14674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  14675. }
  14676. else
  14677. {
  14678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  14679. }
  14680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  14681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14682. }
  14683. //=================================
  14684. //2. Transaction_End
  14685. //=================================
  14686. //2.1====================================== Current.Import L1 ==============================================
  14687. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14688. {
  14689. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  14690. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14691. {
  14692. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14693. {
  14694. tempIndex = ((gun_index==2) ? 1: 0);
  14695. }
  14696. else
  14697. {
  14698. tempIndex = gun_index;
  14699. }
  14700. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14701. {
  14702. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14703. {
  14704. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14705. }
  14706. }// End of for CHAdeMO_QUANTITY
  14707. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14708. }
  14709. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14710. {
  14711. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14712. {
  14713. tempIndex = ((gun_index==2) ? 1: 0);
  14714. }
  14715. else
  14716. {
  14717. tempIndex = gun_index;
  14718. }
  14719. for (int index = 0; index < CCS_QUANTITY; index++)
  14720. {
  14721. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14722. {
  14723. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14724. }
  14725. }// End of for CCS_QUANTITY
  14726. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14727. }
  14728. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14729. {
  14730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14731. {
  14732. tempIndex = ((gun_index==2) ? 1: 0);
  14733. }
  14734. else
  14735. {
  14736. tempIndex = gun_index;
  14737. }
  14738. for (int index = 0; index < GB_QUANTITY; index++)
  14739. {
  14740. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14741. {
  14742. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14743. }
  14744. }// End of for GB_QUANTITY
  14745. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14746. }
  14747. else if(gunType[gun_index] == GUN_TYPE_DO)
  14748. {
  14749. tempIndex = gun_index;
  14750. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14751. {
  14752. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14753. {
  14754. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14755. }
  14756. }
  14757. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14758. }
  14759. else
  14760. {
  14761. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14762. {
  14763. tempIndex = 2;
  14764. }
  14765. else
  14766. {
  14767. tempIndex = gun_index;
  14768. }
  14769. for (int index = 0; index < AC_QUANTITY; index++)
  14770. {
  14771. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14772. {
  14773. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  14774. }
  14775. }// End of for AC_QUANTITY
  14776. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14777. }
  14778. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14779. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  14780. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  14781. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14782. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  14783. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14784. }
  14785. //2.2===================================== Energy.Active.Import.Interval ==========================================
  14786. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14787. {
  14788. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14789. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14790. {
  14791. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14792. {
  14793. tempIndex = ((gun_index==2) ? 1: 0);
  14794. }
  14795. else
  14796. {
  14797. tempIndex = gun_index;
  14798. }
  14799. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14800. {
  14801. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14802. {
  14803. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14804. }
  14805. }// END OF CHAdeMO_QUANTITY
  14806. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14807. }
  14808. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14809. {
  14810. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14811. {
  14812. tempIndex = ((gun_index==2) ? 1: 0);
  14813. }
  14814. else
  14815. {
  14816. tempIndex = gun_index;
  14817. }
  14818. for (int index = 0; index < CCS_QUANTITY; index++)
  14819. {
  14820. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14821. {
  14822. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14823. }
  14824. }// END OF CCS_QUANTITY
  14825. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14826. }
  14827. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14828. {
  14829. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14830. {
  14831. tempIndex = ((gun_index==2) ? 1: 0);
  14832. }
  14833. else
  14834. {
  14835. tempIndex = gun_index;
  14836. }
  14837. for (int index = 0; index < GB_QUANTITY; index++)
  14838. {
  14839. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14840. {
  14841. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14842. }
  14843. }// END OF GB_QUANTITY
  14844. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14845. }
  14846. else if(gunType[gun_index] == GUN_TYPE_DO)
  14847. {
  14848. tempIndex = gun_index;
  14849. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14850. {
  14851. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14852. {
  14853. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14854. }
  14855. }
  14856. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14857. }
  14858. else
  14859. {
  14860. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14861. {
  14862. tempIndex = 2;
  14863. }
  14864. else
  14865. {
  14866. tempIndex = gun_index;
  14867. }
  14868. for (int index = 0; index < AC_QUANTITY; index++)
  14869. {
  14870. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14871. {
  14872. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14873. }
  14874. }// END OF AC_QUANTITY
  14875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14876. }
  14877. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14878. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14879. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  14880. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14881. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14882. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14883. }
  14884. //2.3====================================== Power.Active.Import =========================================
  14885. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  14886. {
  14887. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14888. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14889. {
  14890. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14891. {
  14892. tempIndex = ((gun_index==2) ? 1: 0);
  14893. }
  14894. else
  14895. {
  14896. tempIndex = gun_index;
  14897. }
  14898. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14899. {
  14900. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14901. {
  14902. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14903. }
  14904. } // End for CHAdeMO_QUANTITY
  14905. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14906. }
  14907. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14908. {
  14909. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14910. {
  14911. tempIndex = ((gun_index==2) ? 1: 0);
  14912. }
  14913. else
  14914. {
  14915. tempIndex = gun_index;
  14916. }
  14917. for (int index = 0; index < CCS_QUANTITY; index++)
  14918. {
  14919. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14920. {
  14921. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14922. }
  14923. } // END for CCS_QUANTITY
  14924. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14925. }
  14926. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14927. {
  14928. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14929. {
  14930. tempIndex = ((gun_index==2) ? 1: 0);
  14931. }
  14932. else
  14933. {
  14934. tempIndex = gun_index;
  14935. }
  14936. for (int index = 0; index < GB_QUANTITY; index++)
  14937. {
  14938. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14939. {
  14940. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14941. }
  14942. }// END for GB_QUANTITY
  14943. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14944. }
  14945. else if(gunType[gun_index] == GUN_TYPE_DO)
  14946. {
  14947. tempIndex = gun_index;
  14948. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14949. {
  14950. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14951. {
  14952. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14953. }
  14954. }
  14955. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14956. }
  14957. else
  14958. {
  14959. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14960. {
  14961. tempIndex = 2;
  14962. }
  14963. else
  14964. {
  14965. tempIndex = gun_index;
  14966. }
  14967. for (int index = 0; index < AC_QUANTITY; index++)
  14968. {
  14969. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14970. {
  14971. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14972. }
  14973. } // END for AC_QUANTITY
  14974. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14975. }
  14976. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14977. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  14978. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  14979. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  14981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  14982. }
  14983. //2.4====================================== Voltage L1 ====================================================
  14984. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14985. {
  14986. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14987. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14988. {
  14989. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14990. {
  14991. tempIndex = ((gun_index==2) ? 1: 0);
  14992. }
  14993. else
  14994. {
  14995. tempIndex = gun_index;
  14996. }
  14997. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14998. {
  14999. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15000. {
  15001. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15002. }
  15003. } // END OF FOR CHAdeMO_QUANTITY
  15004. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15005. }
  15006. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15007. {
  15008. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15009. {
  15010. tempIndex = ((gun_index==2) ? 1: 0);
  15011. }
  15012. else
  15013. {
  15014. tempIndex = gun_index;
  15015. }
  15016. for (int index = 0; index < CCS_QUANTITY; index++)
  15017. {
  15018. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15019. {
  15020. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15021. }
  15022. } // END OF FOR CCS_QUANTITY
  15023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15024. }
  15025. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15026. {
  15027. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15028. {
  15029. tempIndex = ((gun_index==2) ? 1: 0);
  15030. }
  15031. else
  15032. {
  15033. tempIndex = gun_index;
  15034. }
  15035. for (int index = 0; index < GB_QUANTITY; index++)
  15036. {
  15037. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15038. {
  15039. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15040. }
  15041. } // END OF FOR GB_QUANTITY
  15042. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15043. }
  15044. else if(gunType[gun_index] == GUN_TYPE_DO)
  15045. {
  15046. tempIndex = gun_index;
  15047. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15048. {
  15049. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15050. {
  15051. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15052. }
  15053. }
  15054. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15055. }
  15056. else
  15057. {
  15058. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15059. {
  15060. tempIndex = 2;
  15061. }
  15062. else
  15063. {
  15064. tempIndex = gun_index;
  15065. }
  15066. for (int index = 0; index < AC_QUANTITY; index++)
  15067. {
  15068. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15069. {
  15070. 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
  15071. }
  15072. } // END OF FOR AC_QUANTITY
  15073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15074. }
  15075. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15078. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15081. }
  15082. //2.5============================================== End SoC =========================================================
  15083. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15084. {
  15085. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15086. 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))
  15087. {
  15088. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15089. {
  15090. tempIndex = ((gun_index==2) ? 1: 0);
  15091. }
  15092. else
  15093. {
  15094. tempIndex = gun_index;
  15095. }
  15096. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15097. {
  15098. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15099. {
  15100. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15101. {
  15102. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15103. }
  15104. }
  15105. }
  15106. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15107. {
  15108. for (int index = 0; index < CCS_QUANTITY; index++)
  15109. {
  15110. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15111. {
  15112. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15113. }
  15114. }
  15115. }
  15116. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15117. {
  15118. for (int index = 0; index < GB_QUANTITY; index++)
  15119. {
  15120. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15121. {
  15122. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15123. }
  15124. }
  15125. }
  15126. else if(gunType[gun_index] == GUN_TYPE_DO)
  15127. {
  15128. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15129. {
  15130. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15131. {
  15132. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  15133. }
  15134. }
  15135. }
  15136. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15137. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15138. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  15141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15142. } // END FOR DC CASE
  15143. }
  15144. //2.6====================================== Current.Import L2 ==============================================
  15145. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15146. {
  15147. // AC 3 phase L2 current
  15148. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15149. {
  15150. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15151. {
  15152. tempIndex = 2;
  15153. }
  15154. else
  15155. {
  15156. tempIndex = gun_index;
  15157. }
  15158. for (int index = 0; index < AC_QUANTITY; index++)
  15159. {
  15160. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15161. {
  15162. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15163. }
  15164. }// End of for AC_QUANTITY
  15165. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15166. }
  15167. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15168. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15169. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15170. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15171. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15172. }
  15173. //2.7====================================== Current.Import L3 ==============================================
  15174. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15175. {
  15176. // AC 3 phase L3 current
  15177. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15178. {
  15179. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15180. {
  15181. tempIndex = 2;
  15182. }
  15183. else
  15184. {
  15185. tempIndex = gun_index;
  15186. }
  15187. for (int index = 0; index < AC_QUANTITY; index++)
  15188. {
  15189. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15190. {
  15191. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15192. }
  15193. }// End of for AC_QUANTITY
  15194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15195. }
  15196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15201. }
  15202. //2.9====================================== Voltage L2 ====================================================
  15203. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15204. {
  15205. // AC 3 phase L2 volatge
  15206. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15207. {
  15208. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15209. {
  15210. tempIndex = 2;
  15211. }
  15212. else
  15213. {
  15214. tempIndex = gun_index;
  15215. }
  15216. for (int index = 0; index < AC_QUANTITY; index++)
  15217. {
  15218. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15219. {
  15220. 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
  15221. }
  15222. } // END OF FOR AC_QUANTITY
  15223. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15224. }
  15225. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15229. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15230. }
  15231. //2.10====================================== Voltage L3 ====================================================
  15232. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15233. {
  15234. // AC 3 phase L3 volatge
  15235. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15236. {
  15237. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15238. {
  15239. tempIndex = 2;
  15240. }
  15241. else
  15242. {
  15243. tempIndex = gun_index;
  15244. }
  15245. for (int index = 0; index < AC_QUANTITY; index++)
  15246. {
  15247. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15248. {
  15249. 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
  15250. }
  15251. } // END OF FOR AC_QUANTITY
  15252. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15253. }
  15254. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15255. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15259. }
  15260. //====================== Start SoC ================================
  15261. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15262. {
  15263. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15264. 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))
  15265. {
  15266. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15267. {
  15268. tempIndex = ((gun_index==2) ? 1: 0);
  15269. }
  15270. else
  15271. {
  15272. tempIndex = gun_index;
  15273. }
  15274. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15275. {
  15276. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15277. {
  15278. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15279. {
  15280. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15281. }
  15282. }
  15283. }
  15284. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15285. {
  15286. for (int index = 0; index < CCS_QUANTITY; index++)
  15287. {
  15288. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15289. {
  15290. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15291. }
  15292. }
  15293. }
  15294. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15295. {
  15296. for (int index = 0; index < GB_QUANTITY; index++)
  15297. {
  15298. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15299. {
  15300. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15301. }
  15302. }
  15303. }
  15304. else if(gunType[gun_index] == GUN_TYPE_DO)
  15305. {
  15306. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15307. {
  15308. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15309. {
  15310. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15311. }
  15312. }
  15313. }
  15314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15315. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15316. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15317. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15318. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15319. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15320. } // END FOR DC CASE
  15321. }
  15322. //======================================== Message create ==============================================
  15323. json_object *StopTransaction = json_object_new_object();
  15324. json_object *transactionDatas = json_object_new_array();
  15325. json_object *sampledValues = json_object_new_array();
  15326. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  15327. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  15328. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  15329. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  15330. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  15331. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15332. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  15333. {
  15334. json_object *transactionData = json_object_new_object();
  15335. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15336. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15337. {
  15338. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15339. {
  15340. json_object *sampledValue = json_object_new_object();
  15341. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15342. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15343. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15344. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15345. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15346. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15347. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15348. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15349. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15350. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15351. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15352. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15353. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15354. json_object_array_add(sampledValues, sampledValue);
  15355. }
  15356. }
  15357. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15358. json_object_array_add(transactionDatas, transactionData);
  15359. }
  15360. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15361. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15362. ,MESSAGE_TYPE_CALL
  15363. ,guid
  15364. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15365. json_object_put(StopTransaction);
  15366. // Check File "TempStopTransaction" Exist
  15367. if((access(TempStopTransaction,F_OK))!=-1)
  15368. {
  15369. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15370. fclose(fopen(TempStopTransaction, "w"));
  15371. }
  15372. else
  15373. {
  15374. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15375. FILE *log = fopen(TempStopTransaction, "w+");
  15376. if(log == NULL)
  15377. {
  15378. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15379. return ;
  15380. }
  15381. else
  15382. {
  15383. fclose(log);
  15384. }
  15385. }
  15386. //Add TempStopTransaction | Update TempStopTransaction
  15387. // open file for writing
  15388. FILE *outfile;
  15389. outfile = fopen (TempStopTransaction, "a");
  15390. //DEBUG_INFO("data = %s\n", queuedata);
  15391. fputs(queuedata, outfile);
  15392. fputs("\n", outfile);
  15393. fclose (outfile);
  15394. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15395. }
  15396. void checkTempStopTransaction(int gun_index)
  15397. {
  15398. FILE *fptr1;
  15399. char ch;
  15400. char str[QUEUE_MESSAGE_LENGTH]={0};
  15401. char guid[37]={0};
  15402. char tempdata[65]={0};
  15403. char connectorStr[2]={0};
  15404. char TempStopTransaction[256];
  15405. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15406. fptr1 = fopen(TempStopTransaction, "r");
  15407. //TempStopTransaction格式: 槍號,StopTransaction封包
  15408. if (!fptr1)
  15409. {
  15410. //printf(" File not found or unable to open the input file!!\n");
  15411. return ;
  15412. }
  15413. ch=fgetc(fptr1);
  15414. //printf(" Now the content of the file %s is : \n",fname);
  15415. rewind(fptr1);
  15416. if(ch!=EOF)
  15417. {
  15418. // copy all contents to the temporary file except the specific line
  15419. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15420. {
  15421. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15422. if(str[0]=='\0')
  15423. {
  15424. break;
  15425. }
  15426. //TempStopTransaction格式: 槍號,StopTransaction封包
  15427. strncpy(connectorStr, str, 1);
  15428. if(atoi(connectorStr) != (gun_index+1))
  15429. {
  15430. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15431. fclose(fptr1);
  15432. return ;
  15433. }
  15434. //random_uuid(guid);
  15435. strncpy(guid, str+6, 36); //copy guid
  15436. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15437. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15438. {
  15439. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15440. }
  15441. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15442. OCPP_insert_transaction_msg(NO, str);
  15443. memset(str,0,ARRAY_SIZE(str));
  15444. }
  15445. }
  15446. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15447. fclose(fptr1);
  15448. remove(TempStopTransaction); // remove the original file
  15449. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15450. }
  15451. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15452. {
  15453. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15454. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15455. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15456. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15457. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15458. }
  15459. int GetWebSocketPingInterval(void)
  15460. {
  15461. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15462. }
  15463. int GetServerSign(void)
  15464. {
  15465. return server_sign;
  15466. }
  15467. uint8_t GetOcppSecurityProfile()
  15468. {
  15469. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15470. }
  15471. void GetOcppChargerBoxId(uint8_t *data)
  15472. {
  15473. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15474. }
  15475. void GetOcppSecurityPassword(uint8_t *data)
  15476. {
  15477. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15478. }
  15479. void SetOcppVersion(uint8_t *version)
  15480. {
  15481. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  15482. DEBUG_INFO("ocpp version: %s\n", version);
  15483. if(strstr((char*)version, "ocpp1.6") != NULL)
  15484. {
  15485. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  15486. }
  15487. else if(strstr((char*)version, "ocpp2.0") != NULL)
  15488. {
  15489. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  15490. system("pkill OcppBackend");
  15491. }
  15492. }
  15493. void SetServerSign(int value)
  15494. {
  15495. server_sign = value;
  15496. }
  15497. int GetBootNotificationInterval(void)
  15498. {
  15499. return BootNotificationInterval;
  15500. }
  15501. int GetInternetConn(void)
  15502. {
  15503. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15504. }
  15505. int GetBackendConnectionTimeout(void)
  15506. {
  15507. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  15508. }
  15509. int isConnectorInitMode(int gun_index)
  15510. {
  15511. int tempIndex = 0;
  15512. int result = TRUE;
  15513. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15514. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15515. {
  15516. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15517. {
  15518. tempIndex = ((gun_index==2) ? 1: 0);
  15519. }
  15520. else
  15521. {
  15522. tempIndex = gun_index;
  15523. }
  15524. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15525. {
  15526. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15527. {
  15528. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15529. } //end of the same index
  15530. }//end of for CHAdeMO_QUANTITY
  15531. }
  15532. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15533. {
  15534. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15535. {
  15536. tempIndex = ((gun_index==2) ? 1: 0);
  15537. }
  15538. else
  15539. {
  15540. tempIndex = gun_index;
  15541. }
  15542. for (int index = 0; index < CCS_QUANTITY; index++)
  15543. {
  15544. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15545. {
  15546. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15547. } //end of the same index
  15548. } // end of for CCS_QUANTITY
  15549. }
  15550. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15551. {
  15552. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15553. {
  15554. tempIndex = ((gun_index==2) ? 1: 0);
  15555. }
  15556. else
  15557. {
  15558. tempIndex = gun_index;
  15559. }
  15560. for (int index = 0; index < GB_QUANTITY; index++)
  15561. {
  15562. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15563. {
  15564. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15565. } //end of the same index
  15566. } // end of for GB_QUANTITY
  15567. }
  15568. else if(gunType[gun_index] == GUN_TYPE_DO)
  15569. {
  15570. tempIndex = gun_index;
  15571. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15572. {
  15573. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15574. {
  15575. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15576. } //end of the same index
  15577. }
  15578. }
  15579. else
  15580. {
  15581. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15582. {
  15583. tempIndex = 2;
  15584. }
  15585. else
  15586. {
  15587. tempIndex = gun_index;
  15588. }
  15589. for (int index = 0; index < AC_QUANTITY; index++)
  15590. {
  15591. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15592. {
  15593. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15594. }//end of the same index
  15595. }//end of for AC_QUANTITY
  15596. }
  15597. return result;
  15598. }
  15599. void refreshProcDogTimer()
  15600. {
  15601. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  15602. }
  15603. void InitialSystemValue(void)
  15604. {
  15605. int connectorIndex = 0;
  15606. //int valueASCII = 0;
  15607. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15608. gunTotalNumber=0;
  15609. SystemInitial = 0;
  15610. localversion=0;
  15611. BootNotificationInterval = 0;
  15612. authorizeRetryTimes = 0;
  15613. GunStatusInterval = 10;
  15614. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15615. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15616. //Hear Beat
  15617. HeartBeatWithNOResponse = 0;
  15618. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  15619. FirstHeartBeat = 0;
  15620. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  15621. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  15622. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15623. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  15624. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15625. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15626. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15627. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15628. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15629. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15630. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15631. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15632. memset(gunType, 0, ARRAY_SIZE(gunType));
  15633. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15634. {
  15635. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  15636. {
  15637. // DO series
  15638. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15639. {
  15640. SystemInitial = SystemInitial + 1;
  15641. gunTotalNumber = gunTotalNumber + 1;
  15642. gunType[connectorIndex] = GUN_TYPE_DO;
  15643. connectorIndex = connectorIndex + 1;
  15644. }
  15645. }
  15646. else
  15647. {
  15648. // DM, DW, DS series
  15649. //check connector / socket type (index: 8, 9, 10)
  15650. for(int index=7; index <10 ; index++)
  15651. {
  15652. if(index != 8)
  15653. {
  15654. // DC Connector
  15655. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15656. {
  15657. SystemInitial = SystemInitial + 1;
  15658. gunTotalNumber = gunTotalNumber + 1;
  15659. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15660. connectorIndex = connectorIndex + 1;
  15661. }
  15662. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15663. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15664. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15665. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15666. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15667. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15668. {
  15669. SystemInitial = SystemInitial + 1;
  15670. gunTotalNumber = gunTotalNumber + 1;
  15671. gunType[connectorIndex] = GUN_TYPE_CCS;
  15672. connectorIndex = connectorIndex + 1;
  15673. }
  15674. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15675. {
  15676. SystemInitial = SystemInitial + 1;
  15677. gunTotalNumber = gunTotalNumber + 1;
  15678. gunType[connectorIndex] = GUN_TYPE_GBT;
  15679. connectorIndex = connectorIndex + 1;
  15680. }
  15681. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15682. {
  15683. SystemInitial = SystemInitial + 1;
  15684. gunTotalNumber = gunTotalNumber + 1;
  15685. gunType[connectorIndex] = GUN_TYPE_DO;
  15686. connectorIndex = connectorIndex + 1;
  15687. }
  15688. }
  15689. else
  15690. {
  15691. // AC Connector
  15692. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15693. {
  15694. SystemInitial = SystemInitial + 1;
  15695. gunTotalNumber = gunTotalNumber + 1;
  15696. gunType[connectorIndex] = GUN_TYPE_AC;
  15697. connectorIndex = connectorIndex + 1;
  15698. }
  15699. }
  15700. }
  15701. }
  15702. //DEBUG_INFO("DC ...\n");
  15703. }
  15704. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15705. {
  15706. //check connector / socket type (index: 8, 9, 10)
  15707. for(int index=7; index <10 ; index++)
  15708. {
  15709. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15710. {
  15711. SystemInitial = SystemInitial + 1;
  15712. gunTotalNumber = gunTotalNumber + 1;
  15713. gunType[connectorIndex] = GUN_TYPE_AC;
  15714. connectorIndex = connectorIndex + 1;
  15715. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15716. }
  15717. }
  15718. }
  15719. //Status && ConnectorPlugIn Setting
  15720. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15721. {
  15722. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15723. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15724. }
  15725. for (int index = 0; index < CCS_QUANTITY; index++)
  15726. {
  15727. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15728. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15729. }
  15730. for (int index = 0; index < GB_QUANTITY; index++)
  15731. {
  15732. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15733. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15734. }
  15735. for (int index = 0; index < AC_QUANTITY; index++)
  15736. {
  15737. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15738. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15739. }
  15740. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15741. {
  15742. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15743. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15744. }
  15745. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15746. {
  15747. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15748. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  15749. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15750. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  15751. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  15752. }
  15753. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  15754. clientTime.Heartbeat=time((time_t*)NULL);
  15755. sleep(1);
  15756. }
  15757. void LWS_Send(char *str)
  15758. {
  15759. //=====================================================
  15760. // Check InternetConn 0: disconnected, 1: connected
  15761. //====================================================
  15762. if(GetOcppConnStatus() == 0)
  15763. {
  15764. DEBUG_INFO("offline now !!!\n");
  15765. return;
  15766. }
  15767. // Only disable isWebsocketSendable operation initiated by charger
  15768. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15769. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15770. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15771. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15772. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15773. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15774. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15775. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15776. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15777. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15778. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15779. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15780. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15781. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15782. {
  15783. isWebsocketSendable = 0;
  15784. }
  15785. pthread_mutex_lock(&lock_send);
  15786. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15787. sprintf((char *)SendBuffer, "%s", str);
  15788. SendBufLen = strlen(str);
  15789. pthread_mutex_unlock(&lock_send);
  15790. lws_callback_on_writable(wsi_client);
  15791. //lws_service(context, 0);
  15792. //sleep(1);
  15793. }
  15794. void LWS_SendNow(char *str)
  15795. {
  15796. //=====================================================
  15797. // Check InternetConn 0: disconnected, 1: connected
  15798. //====================================================
  15799. if(GetOcppConnStatus() == 0)
  15800. {
  15801. DEBUG_INFO("offline now !!!\n");
  15802. return;
  15803. }
  15804. // Only disable isWebsocketSendable operation initiated by charger
  15805. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15806. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15807. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15808. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15809. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15810. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15811. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15812. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15813. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15814. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15815. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15816. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15817. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15818. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15819. {
  15820. isWebsocketSendable = 0;
  15821. }
  15822. pthread_mutex_lock(&lock_send);
  15823. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15824. sprintf((char *)SendBuffer, "%s", str);
  15825. SendBufLen = strlen(str);
  15826. pthread_mutex_unlock(&lock_send);
  15827. lws_callback_on_writable(wsi_client);
  15828. lws_service(context, 0);
  15829. //sleep(1);
  15830. }